@@ -18,14 +18,13 @@ class BareLoader:
18
18
19
19
20
20
class ModuleTests (unittest .TestCase ):
21
- # TODO: RUSTPYTHON
22
- @unittest .expectedFailure
21
+
23
22
def test_uninitialized (self ):
24
23
# An uninitialized module has no __dict__ or __name__,
25
24
# and __doc__ is None
26
25
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 ), [] )
29
28
try :
30
29
s = foo .__name__
31
30
self .fail ("__name__ = %s" % repr (s ))
@@ -335,18 +334,7 @@ def test_setting_annotations(self):
335
334
else :
336
335
del foo .__dict__ ['__annotations__' ]
337
336
338
- # TODO: RUSTPYTHON
339
- @unittest .expectedFailure
340
337
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
-
350
338
# double delete
351
339
foo = ModuleType ("foo" )
352
340
foo .__annotations__ = {}
@@ -361,8 +349,39 @@ def test_annotations_are_created_correctly(self):
361
349
self .assertFalse ("__annotations__" in ann_module4 .__dict__ )
362
350
363
351
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
+
364
364
# frozen and namespace module reprs are tested in importlib.
365
365
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
+
366
385
367
386
if __name__ == '__main__' :
368
387
unittest .main ()
0 commit comments