Skip to content

Commit 18150fa

Browse files
Masorubka1youknowone
authored andcommitted
Update test_module.py from Cpython v3.11.2
1 parent 143036a commit 18150fa

File tree

1 file changed

+34
-15
lines changed

1 file changed

+34
-15
lines changed

Lib/test/test_module.py

+34-15
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ class BareLoader:
1818

1919

2020
class ModuleTests(unittest.TestCase):
21-
# TODO: RUSTPYTHON
22-
@unittest.expectedFailure
21+
2322
def test_uninitialized(self):
2423
# An uninitialized module has no __dict__ or __name__,
2524
# and __doc__ is None
2625
foo = ModuleType.__new__(ModuleType)
27-
self.assertTrue(foo.__dict__ is None)
28-
self.assertRaises(TypeError, dir, foo)
26+
self.assertTrue(isinstance(foo.__dict__, dict))
27+
self.assertEqual(dir(foo), [])
2928
try:
3029
s = foo.__name__
3130
self.fail("__name__ = %s" % repr(s))
@@ -335,18 +334,7 @@ def test_setting_annotations(self):
335334
else:
336335
del foo.__dict__['__annotations__']
337336

338-
# TODO: RUSTPYTHON
339-
@unittest.expectedFailure
340337
def test_annotations_getset_raises(self):
341-
# module has no dict, all operations fail
342-
foo = ModuleType.__new__(ModuleType)
343-
with self.assertRaises(TypeError):
344-
print(foo.__annotations__)
345-
with self.assertRaises(TypeError):
346-
foo.__annotations__ = {}
347-
with self.assertRaises(TypeError):
348-
del foo.__annotations__
349-
350338
# double delete
351339
foo = ModuleType("foo")
352340
foo.__annotations__ = {}
@@ -361,8 +349,39 @@ def test_annotations_are_created_correctly(self):
361349
self.assertFalse("__annotations__" in ann_module4.__dict__)
362350

363351

352+
def test_repeated_attribute_pops(self):
353+
# Repeated accesses to module attribute will be specialized
354+
# Check that popping the attribute doesn't break it
355+
m = ModuleType("test")
356+
d = m.__dict__
357+
count = 0
358+
for _ in range(100):
359+
m.attr = 1
360+
count += m.attr # Might be specialized
361+
d.pop("attr")
362+
self.assertEqual(count, 100)
363+
364364
# frozen and namespace module reprs are tested in importlib.
365365

366+
def test_subclass_with_slots(self):
367+
# In 3.11alpha this crashed, as the slots weren't NULLed.
368+
369+
class ModuleWithSlots(ModuleType):
370+
__slots__ = ("a", "b")
371+
372+
def __init__(self, name):
373+
super().__init__(name)
374+
375+
m = ModuleWithSlots("name")
376+
with self.assertRaises(AttributeError):
377+
m.a
378+
with self.assertRaises(AttributeError):
379+
m.b
380+
m.a, m.b = 1, 2
381+
self.assertEqual(m.a, 1)
382+
self.assertEqual(m.b, 2)
383+
384+
366385

367386
if __name__ == '__main__':
368387
unittest.main()

0 commit comments

Comments
 (0)