Skip to content

Commit f7dac87

Browse files
author
neil.schemenauer
committed
Fix test_build_ext.py to work when building in a separate directory.
Since "srcdir" should now be defined on all platforms, use it to find the module source. git-svn-id: http://svn.python.org/projects/python/trunk@69304 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 629224b commit f7dac87

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

Lib/distutils/tests/test_build_ext.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@
1111
import unittest
1212
from test import test_support
1313

14+
def _get_source_filename():
15+
srcdir = sysconfig.get_config_var('srcdir')
16+
return os.path.join(srcdir, 'Modules', 'xxmodule.c')
17+
1418
class BuildExtTestCase(unittest.TestCase):
1519
def setUp(self):
1620
# Create a simple test environment
1721
# Note that we're making changes to sys.path
1822
self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_")
1923
self.sys_path = sys.path[:]
2024
sys.path.append(self.tmp_dir)
21-
22-
xx_c = os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
23-
shutil.copy(xx_c, self.tmp_dir)
25+
shutil.copy(_get_source_filename(), self.tmp_dir)
2426

2527
def test_build_ext(self):
2628
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -66,9 +68,11 @@ def tearDown(self):
6668
shutil.rmtree(self.tmp_dir, os.name == 'nt' or sys.platform == 'cygwin')
6769

6870
def test_suite():
69-
if not sysconfig.python_build:
71+
src = _get_source_filename()
72+
if not os.path.exists(src):
7073
if test_support.verbose:
71-
print 'test_build_ext: The test must be run in a python build dir'
74+
print ('test_build_ext: Cannot find source code (test'
75+
' must run in python build dir)')
7276
return unittest.TestSuite()
7377
else: return unittest.makeSuite(BuildExtTestCase)
7478

0 commit comments

Comments
 (0)