mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update test_module.py from Cpython v3.11.2
This commit is contained in:
committed by
Jeong YunWon
parent
143036aa0a
commit
18150fa70f
49
Lib/test/test_module.py
vendored
49
Lib/test/test_module.py
vendored
@@ -18,14 +18,13 @@ class BareLoader:
|
||||
|
||||
|
||||
class ModuleTests(unittest.TestCase):
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
|
||||
def test_uninitialized(self):
|
||||
# An uninitialized module has no __dict__ or __name__,
|
||||
# and __doc__ is None
|
||||
foo = ModuleType.__new__(ModuleType)
|
||||
self.assertTrue(foo.__dict__ is None)
|
||||
self.assertRaises(TypeError, dir, foo)
|
||||
self.assertTrue(isinstance(foo.__dict__, dict))
|
||||
self.assertEqual(dir(foo), [])
|
||||
try:
|
||||
s = foo.__name__
|
||||
self.fail("__name__ = %s" % repr(s))
|
||||
@@ -335,18 +334,7 @@ a = A(destroyed)"""
|
||||
else:
|
||||
del foo.__dict__['__annotations__']
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_annotations_getset_raises(self):
|
||||
# module has no dict, all operations fail
|
||||
foo = ModuleType.__new__(ModuleType)
|
||||
with self.assertRaises(TypeError):
|
||||
print(foo.__annotations__)
|
||||
with self.assertRaises(TypeError):
|
||||
foo.__annotations__ = {}
|
||||
with self.assertRaises(TypeError):
|
||||
del foo.__annotations__
|
||||
|
||||
# double delete
|
||||
foo = ModuleType("foo")
|
||||
foo.__annotations__ = {}
|
||||
@@ -361,8 +349,39 @@ a = A(destroyed)"""
|
||||
self.assertFalse("__annotations__" in ann_module4.__dict__)
|
||||
|
||||
|
||||
def test_repeated_attribute_pops(self):
|
||||
# Repeated accesses to module attribute will be specialized
|
||||
# Check that popping the attribute doesn't break it
|
||||
m = ModuleType("test")
|
||||
d = m.__dict__
|
||||
count = 0
|
||||
for _ in range(100):
|
||||
m.attr = 1
|
||||
count += m.attr # Might be specialized
|
||||
d.pop("attr")
|
||||
self.assertEqual(count, 100)
|
||||
|
||||
# frozen and namespace module reprs are tested in importlib.
|
||||
|
||||
def test_subclass_with_slots(self):
|
||||
# In 3.11alpha this crashed, as the slots weren't NULLed.
|
||||
|
||||
class ModuleWithSlots(ModuleType):
|
||||
__slots__ = ("a", "b")
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
|
||||
m = ModuleWithSlots("name")
|
||||
with self.assertRaises(AttributeError):
|
||||
m.a
|
||||
with self.assertRaises(AttributeError):
|
||||
m.b
|
||||
m.a, m.b = 1, 2
|
||||
self.assertEqual(m.a, 1)
|
||||
self.assertEqual(m.b, 2)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user