Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Lib/test/test_module.py

Issue 22986: Improved handling of __class__ assignment
Patch Set: Created 5 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Objects/typeobject.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Test the module type 1 # Test the module type
2 import unittest 2 import unittest
3 import weakref 3 import weakref
4 from test.support import run_unittest, gc_collect 4 from test.support import run_unittest, gc_collect
5 from test.script_helper import assert_python_ok 5 from test.script_helper import assert_python_ok
6 6
7 import sys 7 import sys
8 ModuleType = type(sys) 8 ModuleType = type(sys)
9 9
10 class FullLoader: 10 class FullLoader:
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 b"len = len", 227 b"len = len",
228 b"shutil.rmtree = rmtree"}) 228 b"shutil.rmtree = rmtree"})
229 229
230 def test_descriptor_errors_propogate(self): 230 def test_descriptor_errors_propogate(self):
231 class Descr: 231 class Descr:
232 def __get__(self, o, t): 232 def __get__(self, o, t):
233 raise RuntimeError 233 raise RuntimeError
234 class M(ModuleType): 234 class M(ModuleType):
235 melon = Descr() 235 melon = Descr()
236 self.assertRaises(RuntimeError, getattr, M("mymod"), "melon") 236 self.assertRaises(RuntimeError, getattr, M("mymod"), "melon")
237
238 def test___class___assignment(self):
239 class SubType(ModuleType):
240 a = 1
241
242 m = ModuleType("m")
243 self.assertTrue(m.__class__ is ModuleType)
244 self.assertFalse(hasattr(m, "a"))
245
246 m.__class__ = SubType
247 self.assertTrue(m.__class__ is SubType)
248 self.assertTrue(hasattr(m, "a"))
249
250 m.__class__ = ModuleType
251 self.assertTrue(m.__class__ is ModuleType)
252 self.assertFalse(hasattr(m, "a"))
237 253
238 # frozen and namespace module reprs are tested in importlib. 254 # frozen and namespace module reprs are tested in importlib.
239 255
240 256
241 def test_main(): 257 def test_main():
242 run_unittest(ModuleTests) 258 run_unittest(ModuleTests)
243 259
244 260
245 if __name__ == '__main__': 261 if __name__ == '__main__':
246 test_main() 262 test_main()
OLDNEW
« no previous file with comments | « no previous file | Objects/typeobject.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+