fixed various failures and environment alterations in distutils.test_build_ext
This commit is contained in:
parent
895ee2419d
commit
5501e6a7da
|
@ -19,10 +19,15 @@ ALREADY_TESTED = False
|
||||||
|
|
||||||
def _get_source_filename():
|
def _get_source_filename():
|
||||||
srcdir = sysconfig.get_config_var('srcdir')
|
srcdir = sysconfig.get_config_var('srcdir')
|
||||||
|
fallback_path = os.path.join(os.path.dirname(__file__), 'xxmodule.c')
|
||||||
if srcdir is None:
|
if srcdir is None:
|
||||||
# local fallback
|
return fallback_path
|
||||||
return os.path.join(os.path.dirname(__file__), 'xxmodule.c')
|
locations = (srcdir, os.path.dirname(sys.executable))
|
||||||
return os.path.join(srcdir, 'Modules', 'xxmodule.c')
|
for location in locations:
|
||||||
|
path = os.path.join(location, 'Modules', 'xxmodule.c')
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
return fallback_path
|
||||||
|
|
||||||
class BuildExtTestCase(support.TempdirManager,
|
class BuildExtTestCase(support.TempdirManager,
|
||||||
support.LoggingSilencer,
|
support.LoggingSilencer,
|
||||||
|
@ -81,7 +86,7 @@ class BuildExtTestCase(support.TempdirManager,
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
# Get everything back to normal
|
# Get everything back to normal
|
||||||
test_support.unload('xx')
|
test_support.unload('xx')
|
||||||
sys.path = self.sys_path
|
sys.path[:] = self.sys_path
|
||||||
# XXX on Windows the test leaves a directory with xx module in TEMP
|
# XXX on Windows the test leaves a directory with xx module in TEMP
|
||||||
shutil.rmtree(self.tmp_dir, os.name == 'nt' or sys.platform == 'cygwin')
|
shutil.rmtree(self.tmp_dir, os.name == 'nt' or sys.platform == 'cygwin')
|
||||||
super(BuildExtTestCase, self).tearDown()
|
super(BuildExtTestCase, self).tearDown()
|
||||||
|
@ -350,6 +355,10 @@ class BuildExtTestCase(support.TempdirManager,
|
||||||
self.assertEquals(wanted, path)
|
self.assertEquals(wanted, path)
|
||||||
|
|
||||||
def test_setuptools_compat(self):
|
def test_setuptools_compat(self):
|
||||||
|
import distutils.core, distutils.extension, distutils.command.build_ext
|
||||||
|
saved_ext = distutils.extension.Extension
|
||||||
|
try:
|
||||||
|
# theses import patch Distutils' Extension class
|
||||||
from setuptools_build_ext import build_ext as setuptools_build_ext
|
from setuptools_build_ext import build_ext as setuptools_build_ext
|
||||||
from setuptools_extension import Extension
|
from setuptools_extension import Extension
|
||||||
|
|
||||||
|
@ -366,6 +375,11 @@ class BuildExtTestCase(support.TempdirManager,
|
||||||
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
|
wanted = os.path.join(curdir, 'src', 'lxml', 'etree' + ext)
|
||||||
path = cmd.get_ext_fullpath('lxml.etree')
|
path = cmd.get_ext_fullpath('lxml.etree')
|
||||||
self.assertEquals(wanted, path)
|
self.assertEquals(wanted, path)
|
||||||
|
finally:
|
||||||
|
# restoring Distutils' Extension class otherwise its broken
|
||||||
|
distutils.extension.Extension = saved_ext
|
||||||
|
distutils.core.Extension = saved_ext
|
||||||
|
distutils.command.build_ext.Extension = saved_ext
|
||||||
|
|
||||||
def test_build_ext_path_with_os_sep(self):
|
def test_build_ext_path_with_os_sep(self):
|
||||||
dist = Distribution({'name': 'UpdateManager'})
|
dist = Distribution({'name': 'UpdateManager'})
|
||||||
|
@ -391,13 +405,7 @@ class BuildExtTestCase(support.TempdirManager,
|
||||||
self.assertEquals(ext_path, wanted)
|
self.assertEquals(ext_path, wanted)
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
src = _get_source_filename()
|
return unittest.makeSuite(BuildExtTestCase)
|
||||||
if not os.path.exists(src):
|
|
||||||
if test_support.verbose:
|
|
||||||
print ('test_build_ext: Cannot find source code (test'
|
|
||||||
' must run in python build dir)')
|
|
||||||
return unittest.TestSuite()
|
|
||||||
else: return unittest.makeSuite(BuildExtTestCase)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
test_support.run_unittest(test_suite())
|
test_support.run_unittest(test_suite())
|
||||||
|
|
Loading…
Reference in New Issue