@@ -391,29 +391,47 @@ def test_ucnhash_capi_reset(self):
391391 self .assertEqual (out , '9\n ' * INIT_LOOPS )
392392
393393 def test_static_types_inherited_slots (self ):
394- slots = []
395- script = ['import sys' ]
396- from test .test_types import iter_builtin_types , iter_own_slot_wrappers
397- for cls in iter_builtin_types ():
398- for slot in iter_own_slot_wrappers (cls ):
399- slots .append ((cls , slot ))
400- attr = f'{ cls .__name__ } .{ slot } '
401- script .append (f'print("{ attr } :", { attr } , file=sys.stderr)' )
402- script .append ('' )
403- script = os .linesep .join (script )
404-
405- with contextlib .redirect_stderr (io .StringIO ()) as stderr :
406- exec (script )
407- expected = stderr .getvalue ().splitlines ()
408-
409- out , err = self .run_embedded_interpreter ("test_repeated_init_exec" , script )
394+ script = textwrap .dedent ("""
395+ import test.support
396+
397+ results = {}
398+ def add(cls, slot, own):
399+ value = getattr(cls, slot)
400+ try:
401+ subresults = results[cls.__name__]
402+ except KeyError:
403+ subresults = results[cls.__name__] = {}
404+ subresults[slot] = [repr(value), own]
405+
406+ for cls in test.support.iter_builtin_types():
407+ for slot, own in test.support.iter_slot_wrappers(cls):
408+ add(cls, slot, own)
409+ """ )
410+
411+ ns = {}
412+ exec (script , ns , ns )
413+ all_expected = ns ['results' ]
414+ del ns
415+
416+ script += textwrap .dedent ("""
417+ import json
418+ import sys
419+ text = json.dumps(results)
420+ print(text, file=sys.stderr)
421+ """ )
422+ out , err = self .run_embedded_interpreter (
423+ "test_repeated_init_exec" , script , script )
410424 results = err .split ('--- Loop #' )[1 :]
411425 results = [res .rpartition (' ---\n ' )[- 1 ] for res in results ]
412426
413427 self .maxDiff = None
414- for i , result in enumerate (results , start = 1 ):
415- with self .subTest (loop = i ):
416- self .assertEqual (result .splitlines (), expected )
428+ for i , text in enumerate (results , start = 1 ):
429+ result = json .loads (text )
430+ for classname , expected in all_expected .items ():
431+ with self .subTest (loop = i , cls = classname ):
432+ slots = result .pop (classname )
433+ self .assertEqual (slots , expected )
434+ self .assertEqual (result , {})
417435 self .assertEqual (out , '' )
418436
419437
0 commit comments