# can't access the module anymore. Get it from sys.modules instead.
build_ext = sys.modules['Cython.Distutils.build_ext']
+
+have_gdb = None
+def test_gdb():
+ global have_gdb
+ if have_gdb is None:
+ try:
+ p = subprocess.Popen(['gdb', '-v'], stdout=subprocess.PIPE)
+ have_gdb = True
+ except OSError:
+ # gdb was not installed
+ have_gdb = False
+ else:
+ gdb_version = p.stdout.read().decode('ascii')
+ p.wait()
+ p.stdout.close()
+
+ if have_gdb:
+ # Based on Lib/test/test_gdb.py
+ regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
+ gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))
+
+ if gdb_version_number >= [7, 2]:
+ 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()
+ python_version_number = list(map(int, python_version.split()))
+
+ # Be Python 3 compatible
+ if (not have_gdb
+ or gdb_version_number < [7, 2]
+ or python_version_number < [2, 6]):
+ warnings.warn(
+ 'Skipping gdb tests, need gdb >= 7.2 with Python >= 2.6')
+ have_gdb = False
+
+ return have_gdb
+
+
class DebuggerTestCase(unittest.TestCase):
def setUp(self):
Run gdb and have cygdb import the debug information from the code
defined in TestParseTreeTransforms's setUp method
"""
+ if not test_gdb():
+ return
+
self.tempdir = tempfile.mkdtemp()
self.destfile = os.path.join(self.tempdir, 'codefile.pyx')
self.debug_dest = os.path.join(self.tempdir,
# )
def tearDown(self):
+ if not test_gdb():
+ return
os.chdir(self.cwd)
shutil.rmtree(self.tempdir)
class GdbDebuggerTestCase(DebuggerTestCase):
def setUp(self):
+ if not test_gdb():
+ return
+
super(GdbDebuggerTestCase, self).setUp()
prefix_code = textwrap.dedent('''\
p.wait()
p.stdout.close()
- if have_gdb:
- 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()
- python_version_number = [int(a) for a in python_version.split()]
-
if have_gdb:
# Based on Lib/test/test_gdb.py
regex = "^GNU gdb [^\d]*(\d+)\.(\d+)"
- gdb_version_number = re.search(regex, gdb_version).groups()
-
+ gdb_version_number = list(map(int, re.search(regex, gdb_version).groups()))
+
+ if gdb_version_number >= [7, 2]:
+ 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()
+ python_version_number = list(map(int, python_version.split()))
+
+
# Be Python 3 compatible
if (not have_gdb
- or list(map(int, gdb_version_number)) < [7, 2]
+ or gdb_version_number < [7, 2]
or python_version_number < [2, 6]):
self.p = None
warnings.warn(
env=env)
def tearDown(self):
+ if not test_gdb():
+ return
+
super(GdbDebuggerTestCase, self).tearDown()
if self.p:
self.p.stderr.close()
class TestAll(GdbDebuggerTestCase):
def test_all(self):
- if self.p is None:
+ if not test_gdb():
return
out, err = self.p.communicate()