Skip to content

Commit

Permalink
Fix test_build_ext.py to work when building in a separate directory.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
neil.schemenauer committed Feb 5, 2009
1 parent 629224b commit f7dac87
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Lib/distutils/tests/test_build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
import unittest
from test import test_support

def _get_source_filename():
srcdir = sysconfig.get_config_var('srcdir')
return os.path.join(srcdir, 'Modules', 'xxmodule.c')

class BuildExtTestCase(unittest.TestCase):
def setUp(self):
# Create a simple test environment
# Note that we're making changes to sys.path
self.tmp_dir = tempfile.mkdtemp(prefix="pythontest_")
self.sys_path = sys.path[:]
sys.path.append(self.tmp_dir)

xx_c = os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
shutil.copy(xx_c, self.tmp_dir)
shutil.copy(_get_source_filename(), self.tmp_dir)

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

def test_suite():
if not sysconfig.python_build:
src = _get_source_filename()
if not os.path.exists(src):
if test_support.verbose:
print 'test_build_ext: The test must be run in a python build dir'
print ('test_build_ext: Cannot find source code (test'
' must run in python build dir)')
return unittest.TestSuite()
else: return unittest.makeSuite(BuildExtTestCase)

Expand Down

0 comments on commit f7dac87

Please sign in to comment.