@@ -419,8 +419,7 @@ def test_datetime_reset_strptime(self):
419
419
@unittest .skip ('inheritance across re-init is currently broken; see gh-117482' )
420
420
def test_static_types_inherited_slots (self ):
421
421
script = textwrap .dedent ("""
422
- import json
423
- import sys
422
+ import test.support
424
423
425
424
results = {}
426
425
def add(cls, slot, own):
@@ -429,41 +428,37 @@ def add(cls, slot, own):
429
428
subresults = results[cls.__name__]
430
429
except KeyError:
431
430
subresults = results[cls.__name__] = {}
432
- subresults[slot] = repr(value)
431
+ subresults[slot] = [repr(value), own]
432
+
433
+ for cls in test.support.iter_builtin_types():
434
+ for slot, own in test.support.iter_slot_wrappers(cls):
435
+ add(cls, slot, own)
436
+ """ )
433
437
434
- {body}
438
+ ns = {}
439
+ exec (script , ns , ns )
440
+ all_expected = ns ['results' ]
441
+ del ns
435
442
443
+ script += textwrap .dedent ("""
444
+ import json
445
+ import sys
436
446
text = json.dumps(results)
437
447
print(text, file=sys.stderr)
438
448
""" )
439
- body = []
440
- for cls in support .iter_builtin_types ():
441
- body .append ('' )
442
- body .append (f'cls = { cls .__name__ } ' )
443
- for slot , own in support .iter_slot_wrappers (cls ):
444
- body .append (f'add(cls, { slot !r} , { own } )' )
445
- body .pop (0 )
446
- script = script .replace ('{body}' , os .linesep .join (body ))
447
-
448
- with contextlib .redirect_stderr (io .StringIO ()) as stderr :
449
- ns = {}
450
- exec (script , ns , ns )
451
- expected = json .loads (stderr .getvalue ())
452
-
453
449
out , err = self .run_embedded_interpreter (
454
450
"test_repeated_init_exec" , script , script )
455
451
results = err .split ('--- Loop #' )[1 :]
456
452
results = [res .rpartition (' ---\n ' )[- 1 ] for res in results ]
457
453
458
454
self .maxDiff = None
459
455
for i , text in enumerate (results , start = 1 ):
460
- failed = True
461
- with self .subTest (loop = i ):
462
- result = json .loads (text )
463
- self .assertEqual (result , expected )
464
- failed = False
465
- if failed :
466
- break
456
+ result = json .loads (text )
457
+ for classname , expected in all_expected .items ():
458
+ with self .subTest (loop = i , cls = classname ):
459
+ slots = result .pop (classname )
460
+ self .assertEqual (slots , expected )
461
+ self .assertEqual (result , {})
467
462
self .assertEqual (out , '' )
468
463
469
464
0 commit comments