Commit dfcaadb7 authored by Stefan Behnel's avatar Stefan Behnel

apply some safety fixes in test code

parent d3e6486c
...@@ -43,7 +43,7 @@ def test_gdb(): ...@@ -43,7 +43,7 @@ def test_gdb():
# gdb was not installed # gdb was not installed
have_gdb = False have_gdb = False
else: else:
gdb_version = p.stdout.read().decode('ascii') gdb_version = p.stdout.read().decode('ascii', 'ignore')
p.wait() p.wait()
p.stdout.close() p.stdout.close()
...@@ -54,17 +54,23 @@ def test_gdb(): ...@@ -54,17 +54,23 @@ def test_gdb():
if gdb_version_number >= [7, 2]: if gdb_version_number >= [7, 2]:
python_version_script = tempfile.NamedTemporaryFile(mode='w+') python_version_script = tempfile.NamedTemporaryFile(mode='w+')
python_version_script.write(
'python import sys; print("%s %s" % sys.version_info[:2])')
python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE)
python_version = p.stdout.read().decode('ascii')
p.wait()
try: try:
python_version_number = list(map(int, python_version.split())) python_version_script.write(
except ValueError: 'python import sys; print("%s %s" % sys.version_info[:2])')
have_gdb = False python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE)
try:
python_version = p.stdout.read().decode('ascii')
p.wait()
finally:
p.stdout.close()
try:
python_version_number = list(map(int, python_version.split()))
except ValueError:
have_gdb = False
finally:
python_version_script.close()
# Be Python 3 compatible # Be Python 3 compatible
if (not have_gdb if (not have_gdb
...@@ -146,6 +152,7 @@ class DebuggerTestCase(unittest.TestCase): ...@@ -146,6 +152,7 @@ class DebuggerTestCase(unittest.TestCase):
finally: finally:
optimization_disabler.restore_state() optimization_disabler.restore_state()
sys.stderr = stderr sys.stderr = stderr
new_stderr.close()
# ext = Cython.Distutils.extension.Extension( # ext = Cython.Distutils.extension.Extension(
# 'codefile', # 'codefile',
...@@ -250,8 +257,11 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -250,8 +257,11 @@ class GdbDebuggerTestCase(DebuggerTestCase):
python_version_script.flush() python_version_script.flush()
p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name], p = subprocess.Popen(['gdb', '-batch', '-x', python_version_script.name],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
python_version = p.stdout.read().decode('ascii') try:
p.wait() python_version = p.stdout.read().decode('ascii')
p.wait()
finally:
p.stdout.close()
try: try:
python_version_number = list(map(int, python_version.split())) python_version_number = list(map(int, python_version.split()))
except ValueError: except ValueError:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment