diff options
author | Nick Papior Andersen <nickpapior@gmail.com> | 2015-02-25 09:51:41 +0000 |
---|---|---|
committer | Nick Papior Andersen <nickpapior@gmail.com> | 2015-02-25 09:51:41 +0000 |
commit | a6c2443a646eb46b0bca9d8560d52d5b9fa87c9d (patch) | |
tree | 46059b796c74ab9a00696ffdffb951550797e9d9 /numpy/distutils/tests | |
parent | f91796046592ff876b74db14544adaab21e31f93 (diff) | |
download | numpy-a6c2443a646eb46b0bca9d8560d52d5b9fa87c9d.tar.gz |
BUG: PEP corrections
More corrections pointed out by Ralf
Changed the get_standard_file to a fully temporary
file. This means that the __init__ diverges a bit
from the system_info object. However, it only has
to do with the setup for the test. All internal things
regarding the object have not been altered.
I have checked on my box that all files/directories are removed.
Diffstat (limited to 'numpy/distutils/tests')
-rw-r--r-- | numpy/distutils/tests/test_system_info.py | 150 |
1 files changed, 79 insertions, 71 deletions
diff --git a/numpy/distutils/tests/test_system_info.py b/numpy/distutils/tests/test_system_info.py index eda8c9548..1c37f1907 100644 --- a/numpy/distutils/tests/test_system_info.py +++ b/numpy/distutils/tests/test_system_info.py @@ -1,7 +1,8 @@ from __future__ import division, print_function import os -from tempfile import mkdtemp +import shutil +from tempfile import mkstemp, mkdtemp from numpy.distutils import ccompiler from numpy.testing import TestCase, run_module_suite, assert_, assert_equal @@ -15,22 +16,11 @@ def get_class(name, notfound_action=1): 1 - display warning message 2 - raise error """ - cl = {'temp1': test_temp1, - 'temp2': test_temp2 + cl = {'temp1': TestTemp1, + 'temp2': TestTemp2 }.get(name.lower(), test_system_info) return cl() -def get_standard_file(fname): - """ - Overrides the get_standard_file from system_info - """ - tmpdir = mkdtemp() - filename = os.path.join(tmpdir,fname) - with open(filename,'w') as fd: - fd.write(site_cfg) - filenames = [filename] - return filenames - simple_site = """ [ALL] library_dirs = {dir1:s}:{dir2:s} @@ -61,6 +51,7 @@ void bar(void) { } """ + class test_system_info(system_info): def __init__(self, default_lib_dirs=default_lib_dirs, @@ -78,113 +69,130 @@ class test_system_info(system_info): defaults['extra_compile_args'] = [] defaults['extra_link_args'] = [] self.cp = ConfigParser(defaults) - self.files = [] - self.files.extend(get_standard_file('site.cfg')) - self.parse_config_files() - if self.section is not None: - # Have to by-pass a boolean conversion for non-existing variable - try: - self.search_static_first = self.cp.getboolean(self.section, 'search_static_first') - except: pass - assert_(isinstance(self.search_static_first, int)) - + # We have to parse the config files afterwards + # to have a consistent temporary filepath + def _check_libs(self, lib_dirs, libs, opt_libs, exts): """Override _check_libs to return with all dirs """ - info = {'libraries' : libs , 'library_dirs' : lib_dirs } + info = {'libraries' : libs , 'library_dirs' : lib_dirs} return info -class test_temp1(test_system_info): + +class TestTemp1(test_system_info): section = 'temp1' -class test_temp2(test_system_info): + + +class TestTemp2(test_system_info): section = 'temp2' + class TestSystemInfoReading(TestCase): def setUp(self): """ Create the libraries """ # Create 2 sources and 2 libraries self._dir1 = mkdtemp() - self._src1 = os.path.join(self._dir1,'foo.c') - self._lib1 = os.path.join(self._dir1,'libfoo.so') + self._src1 = os.path.join(self._dir1, 'foo.c') + self._lib1 = os.path.join(self._dir1, 'libfoo.so') self._dir2 = mkdtemp() - self._src2 = os.path.join(self._dir2,'bar.c') - self._lib2 = os.path.join(self._dir2,'libbar.so') + self._src2 = os.path.join(self._dir2, 'bar.c') + self._lib2 = os.path.join(self._dir2, 'libbar.so') # Update local site.cfg global simple_site, site_cfg site_cfg = simple_site.format(**{ - 'dir1' : self._dir1 , - 'lib1' : self._lib1 , - 'dir2' : self._dir2 , + 'dir1' : self._dir1, + 'lib1' : self._lib1, + 'dir2' : self._dir2, 'lib2' : self._lib2 }) + # Write site.cfg + fd, self._sitecfg = mkstemp() + os.write(fd,site_cfg) + os.close(fd) # Write the sources with open(self._src1,'w') as fd: fd.write(fakelib_c_text) with open(self._src2,'w') as fd: fd.write(fakelib_c_text) + # We create all class-instances + def site_and_parse(c,site_cfg): + c.files = [site_cfg] + c.parse_config_files() + return c + self.c_default = site_and_parse(get_class('default'), self._sitecfg) + self.c_temp1 = site_and_parse(get_class('temp1'), self._sitecfg) + self.c_temp2 = site_and_parse(get_class('temp2'), self._sitecfg) def tearDown(self): + # Do each removal separately try: shutil.rmtree(self._dir1) + except: + pass + try: shutil.rmtree(self._dir2) - except: + except: + pass + try: + os.remove(self._sitecfg) + except: pass def test_all(self): - """ Read in all information in the ALL block """ - tsi = get_class('default') - assert_equal(tsi.get_lib_dirs(),[self._dir1,self._dir2]) - assert_equal(tsi.get_libraries(),[self._lib1,self._lib2]) - assert_equal(tsi.get_runtime_lib_dirs(),[self._dir1]) + # Read in all information in the ALL block + tsi = self.c_default + assert_equal(tsi.get_lib_dirs(), [self._dir1, self._dir2]) + assert_equal(tsi.get_libraries(), [self._lib1, self._lib2]) + assert_equal(tsi.get_runtime_lib_dirs(), [self._dir1]) extra = tsi.calc_extra_info() - assert_equal(extra['extra_compile_args'],['-I/fake/directory']) + assert_equal(extra['extra_compile_args'], ['-I/fake/directory']) def test_temp1(self): - """ Read in all information in the temp1 block """ - tsi = get_class('temp1') - assert_equal(tsi.get_lib_dirs(),[self._dir1]) - assert_equal(tsi.get_libraries(),[self._lib1]) - assert_equal(tsi.get_runtime_lib_dirs(),[self._dir1]) + # Read in all information in the temp1 block + tsi = self.c_temp1 + assert_equal(tsi.get_lib_dirs(), [self._dir1]) + assert_equal(tsi.get_libraries(), [self._lib1]) + assert_equal(tsi.get_runtime_lib_dirs(), [self._dir1]) def test_temp2(self): - """ Read in all information in the temp2 block """ - tsi = get_class('temp2') - assert_equal(tsi.get_lib_dirs(),[self._dir2]) - assert_equal(tsi.get_libraries(),[self._lib2]) + # Read in all information in the temp2 block + tsi = self.c_temp2 + assert_equal(tsi.get_lib_dirs(), [self._dir2]) + assert_equal(tsi.get_libraries(), [self._lib2]) extra = tsi.calc_extra_info() - assert_equal(extra['extra_link_args'],['-Wl,-rpath='+self._lib2]) + assert_equal(extra['extra_link_args'], ['-Wl,-rpath='+self._lib2]) def test_compile1(self): - """ Compile source and link the first source """ - tsi = get_class('temp1') + # Compile source and link the first source + tsi = self.c_temp1 c = ccompiler.new_compiler() - # Change directory to not screw up directories try: + # Change directory to not screw up directories previousDir = os.getcwd() + os.chdir(self._dir1) + c.compile([os.path.basename(self._src1)], output_dir=self._dir1) + # Ensure that the object exists + assert_(os.path.isfile(self._src1.replace('.c', '.o'))) + os.chdir(previousDir) except OSError: - return - os.chdir(self._dir1) - c.compile([os.path.basename(self._src1)], output_dir=self._dir1) - # Ensure that the object exists - assert_(os.path.isfile(self._src1.replace('.c','.o'))) - os.chdir(previousDir) + pass def test_compile2(self): - """ Compile source and link the second source """ - tsi = get_class('temp2') + # Compile source and link the second source + tsi = self.c_temp2 c = ccompiler.new_compiler() extra_link_args = tsi.calc_extra_info()['extra_link_args'] - # Change directory to not screw up directories try: + # Change directory to not screw up directories previousDir = os.getcwd() + os.chdir(self._dir2) + c.compile([os.path.basename(self._src2)], output_dir=self._dir2, + extra_postargs=extra_link_args) + # Ensure that the object exists + assert_(os.path.isfile(self._src2.replace('.c', '.o'))) + os.chdir(previousDir) except OSError: - return - os.chdir(self._dir2) - c.compile([os.path.basename(self._src2)], output_dir=self._dir2, - extra_postargs=extra_link_args) - # Ensure that the object exists - assert_(os.path.isfile(self._src2.replace('.c','.o'))) - os.chdir(previousDir) - + pass + if __name__ == '__main__': run_module_suite() |