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