check for encoding attr before set in test_helper

This makes it work equivalently in py2 and py3
This commit is contained in:
Johnny Robeson 2016-06-21 23:44:24 -04:00
parent 133c82b1ab
commit 4c98edc588

View file

@ -89,7 +89,8 @@ def control_stdin(input=None):
"""
org = sys.stdin
sys.stdin = StringIO(input)
sys.stdin.encoding = 'utf8'
if hasattr(sys.stdin, 'encoding'):
sys.stdin.encoding = 'utf8'
try:
yield sys.stdin
finally:
@ -108,7 +109,8 @@ def capture_stdout():
"""
org = sys.stdout
sys.stdout = capture = StringIO()
sys.stdout.encoding = 'utf8'
if not hasattr(sys.stdout, 'encoding'):
sys.stdout.encoding = 'utf8'
try:
yield sys.stdout
finally: