comparison tests/heredoctest.py @ 40318:55fd0fefbec4

py3: flush std streams before/after running user code in heredoctest.py Otherwise, things written to stdout.buffer would be interleaved.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 16 Oct 2018 07:18:30 +0200
parents 6a98f9408a50
children 2372284d9457
comparison
equal deleted inserted replaced
40317:6958eb9bdcd6 40318:55fd0fefbec4
1 from __future__ import absolute_import, print_function 1 from __future__ import absolute_import, print_function
2 2
3 import sys 3 import sys
4
5 def flush():
6 sys.stdout.flush()
7 sys.stderr.flush()
4 8
5 globalvars = {} 9 globalvars = {}
6 lines = sys.stdin.readlines() 10 lines = sys.stdin.readlines()
7 while lines: 11 while lines:
8 l = lines.pop(0) 12 l = lines.pop(0)
13 while lines and lines[0].startswith('... '): 17 while lines and lines[0].startswith('... '):
14 l = lines.pop(0) 18 l = lines.pop(0)
15 snippet += l[4:] 19 snippet += l[4:]
16 c = compile(snippet, '<heredoc>', 'single') 20 c = compile(snippet, '<heredoc>', 'single')
17 try: 21 try:
22 flush()
18 exec(c, globalvars) 23 exec(c, globalvars)
24 flush()
19 except Exception as inst: 25 except Exception as inst:
26 flush()
20 print(repr(inst)) 27 print(repr(inst))