Commit 9e1f938e authored by Stefan Behnel's avatar Stefan Behnel

fix cygdb and its tests when run in Py3

parent 0241a594
...@@ -50,9 +50,10 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False): ...@@ -50,9 +50,10 @@ def make_command_file(path_to_debug_info, prefix_code='', no_import=False):
virtualenv = os.getenv('VIRTUAL_ENV') virtualenv = os.getenv('VIRTUAL_ENV')
if virtualenv: if virtualenv:
path_to_activate_this_py = os.path.join(virtualenv, 'bin', 'activate_this.py') path_to_activate_this_py = os.path.join(virtualenv, 'bin', 'activate_this.py')
print("gdb command file: Activating virtualenv: %s; path_to_activate_this_py: %s" print("gdb command file: Activating virtualenv: %s; path_to_activate_this_py: %s" % (
% (virtualenv, path_to_activate_this_py,)) virtualenv, path_to_activate_this_py))
execfile(path_to_activate_this_py, dict(__file__=path_to_activate_this_py)) with open(path_to_activate_this_py) as f:
exec(f.read(), dict(__file__=path_to_activate_this_py))
from Cython.Debugger import libcython, libpython from Cython.Debugger import libcython, libpython
end end
......
...@@ -21,11 +21,8 @@ root = os.path.dirname(os.path.abspath(__file__)) ...@@ -21,11 +21,8 @@ root = os.path.dirname(os.path.abspath(__file__))
codefile = os.path.join(root, 'codefile') codefile = os.path.join(root, 'codefile')
cfuncs_file = os.path.join(root, 'cfuncs.c') cfuncs_file = os.path.join(root, 'cfuncs.c')
f = open(codefile) with open(codefile) as f:
try: source_to_lineno = dict((line.strip(), i + 1) for i, line in enumerate(f))
source_to_lineno = dict([ (line.strip(), i + 1) for i, line in enumerate(f) ])
finally:
f.close()
# Cython.Distutils.__init__ imports build_ext from build_ext which means we # Cython.Distutils.__init__ imports build_ext from build_ext which means we
# can't access the module anymore. Get it from sys.modules instead. # can't access the module anymore. Get it from sys.modules instead.
...@@ -76,8 +73,8 @@ def test_gdb(): ...@@ -76,8 +73,8 @@ def test_gdb():
# Be Python 3 compatible # Be Python 3 compatible
if (not have_gdb if (not have_gdb
or gdb_version_number < [7, 2] or gdb_version_number < [7, 2]
or python_version_number < [2, 6]): or python_version_number < [2, 6]):
warnings.warn( warnings.warn(
'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6') 'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
have_gdb = False have_gdb = False
...@@ -197,6 +194,8 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -197,6 +194,8 @@ class GdbDebuggerTestCase(DebuggerTestCase):
def excepthook(type, value, tb): def excepthook(type, value, tb):
traceback.print_exception(type, value, tb) traceback.print_exception(type, value, tb)
sys.stderr.flush()
sys.stdout.flush()
os._exit(1) os._exit(1)
sys.excepthook = excepthook sys.excepthook = excepthook
...@@ -220,11 +219,8 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -220,11 +219,8 @@ class GdbDebuggerTestCase(DebuggerTestCase):
self.gdb_command_file = cygdb.make_command_file(self.tempdir, self.gdb_command_file = cygdb.make_command_file(self.tempdir,
prefix_code) prefix_code)
f = open(self.gdb_command_file, 'a') with open(self.gdb_command_file, 'a') as f:
try:
f.write(code) f.write(code)
finally:
f.close()
args = ['gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args', args = ['gdb', '-batch', '-x', self.gdb_command_file, '-n', '--args',
sys.executable, '-c', 'import codefile'] sys.executable, '-c', 'import codefile']
...@@ -239,7 +235,7 @@ class GdbDebuggerTestCase(DebuggerTestCase): ...@@ -239,7 +235,7 @@ class GdbDebuggerTestCase(DebuggerTestCase):
self.p = subprocess.Popen( self.p = subprocess.Popen(
args, args,
stdout=open(os.devnull, 'w'), stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
env=env) env=env)
...@@ -266,19 +262,23 @@ class TestAll(GdbDebuggerTestCase): ...@@ -266,19 +262,23 @@ class TestAll(GdbDebuggerTestCase):
return return
out, err = self.p.communicate() out, err = self.p.communicate()
out = out.decode('UTF-8')
err = err.decode('UTF-8') err = err.decode('UTF-8')
exit_status = self.p.returncode exit_status = self.p.returncode
if exit_status == 1: if exit_status == 1:
sys.stderr.write(out)
sys.stderr.write(err) sys.stderr.write(err)
elif exit_status >= 2: elif exit_status >= 2:
border = u'*' * 30 border = u'*' * 30
start = u'%s v INSIDE GDB v %s' % (border, border) start = u'%s v INSIDE GDB v %s' % (border, border)
stderr = u'%s v STDERR v %s' % (border, border)
end = u'%s ^ INSIDE GDB ^ %s' % (border, border) end = u'%s ^ INSIDE GDB ^ %s' % (border, border)
errmsg = u'\n%s\n%s%s' % (start, err, end) errmsg = u'\n%s\n%s%s' % (start, out, stderr, err, end)
sys.stderr.write(errmsg) sys.stderr.write(errmsg)
self.assertEqual(exit_status, 0)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -503,10 +503,11 @@ class CythonParameter(gdb.Parameter): ...@@ -503,10 +503,11 @@ class CythonParameter(gdb.Parameter):
if default is not None: if default is not None:
self.value = default self.value = default
def __nonzero__(self): def __bool__(self):
return bool(self.value) return bool(self.value)
__bool__ = __nonzero__ # python 3 __nonzero__ = __bool__ # Python 2
class CompleteUnqualifiedFunctionNames(CythonParameter): class CompleteUnqualifiedFunctionNames(CythonParameter):
""" """
......
...@@ -284,14 +284,6 @@ VER_DEP_MODULES = { ...@@ -284,14 +284,6 @@ VER_DEP_MODULES = {
]), ]),
} }
# files that should not be converted to Python 3 code with 2to3
KEEP_2X_FILES = [
os.path.join('Cython', 'Debugger', 'Tests', 'test_libcython_in_gdb.py'),
os.path.join('Cython', 'Debugger', 'Tests', 'test_libpython_in_gdb.py'),
os.path.join('Cython', 'Debugger', 'libcython.py'),
os.path.join('Cython', 'Debugger', 'libpython.py'),
]
COMPILER = None COMPILER = None
INCLUDE_DIRS = [ d for d in os.getenv('INCLUDE', '').split(os.pathsep) if d ] INCLUDE_DIRS = [ d for d in os.getenv('INCLUDE', '').split(os.pathsep) if d ]
CFLAGS = os.getenv('CFLAGS', '').split() CFLAGS = os.getenv('CFLAGS', '').split()
...@@ -1509,9 +1501,6 @@ def refactor_for_py3(distdir, cy3_dir): ...@@ -1509,9 +1501,6 @@ def refactor_for_py3(distdir, cy3_dir):
''') ''')
sys.path.insert(0, cy3_dir) sys.path.insert(0, cy3_dir)
for keep_2x_file in KEEP_2X_FILES:
destfile = os.path.join(cy3_dir, keep_2x_file)
shutil.copy(keep_2x_file, destfile)
class PendingThreadsError(RuntimeError): class PendingThreadsError(RuntimeError):
pass pass
......
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