Skip to content

Commit 5d1cfc0

Browse files
Avoid excessively long commandline arguments.
1 parent 31fc158 commit 5d1cfc0

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

Lib/test/test_embed.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ def test_datetime_reset_strptime(self):
418418

419419
def test_static_types_inherited_slots(self):
420420
script = textwrap.dedent("""
421-
import json
422-
import sys
421+
import test.support
423422
424423
results = {}
425424
def add(cls, slot, own):
@@ -428,41 +427,37 @@ def add(cls, slot, own):
428427
subresults = results[cls.__name__]
429428
except KeyError:
430429
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+
""")
432436

433-
{body}
437+
ns = {}
438+
exec(script, ns, ns)
439+
all_expected = ns['results']
440+
del ns
434441

442+
script += textwrap.dedent("""
443+
import json
444+
import sys
435445
text = json.dumps(results)
436446
print(text, file=sys.stderr)
437447
""")
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-
452448
out, err = self.run_embedded_interpreter(
453449
"test_repeated_init_exec", script, script)
454450
results = err.split('--- Loop #')[1:]
455451
results = [res.rpartition(' ---\n')[-1] for res in results]
456452

457453
self.maxDiff = None
458454
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, {})
466461
self.assertEqual(out, '')
467462

468463

0 commit comments

Comments
 (0)