]> granicus.if.org Git - python/commitdiff
Merge test cleanup from 3.5 into 3.6
authorMartin Panter <vadmium+py@gmail.com>
Thu, 29 Sep 2016 04:40:56 +0000 (04:40 +0000)
committerMartin Panter <vadmium+py@gmail.com>
Thu, 29 Sep 2016 04:40:56 +0000 (04:40 +0000)
1  2 
Lib/ctypes/test/test_find.py

index c7205f5ddf4efc2c7d857861ef3e6faf7578d213,94b0b890b737df375ecbcb4bf8d7cc726c8d185c..b99fdcba7b28fc2b248c17d4aef8e449a3e21f3d
@@@ -69,71 -69,5 +69,48 @@@ class Test_OpenGL_libs(unittest.TestCas
          self.assertFalse(os.path.lexists(test.support.TESTFN))
          self.assertIsNone(result)
  
- # On platforms where the default shared library suffix is '.so',
- # at least some libraries can be loaded as attributes of the cdll
- # object, since ctypes now tries loading the lib again
- # with '.so' appended of the first try fails.
- #
- # Won't work for libc, unfortunately.  OTOH, it isn't
- # needed for libc since this is already mapped into the current
- # process (?)
- #
- # On MAC OSX, it won't work either, because dlopen() needs a full path,
- # and the default suffix is either none or '.dylib'.
- @unittest.skip('test disabled')
- @unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
-                      'test not suitable for this platform')
- class LoadLibs(unittest.TestCase):
-     def test_libm(self):
-         import math
-         libm = cdll.libm
-         sqrt = libm.sqrt
-         sqrt.argtypes = (c_double,)
-         sqrt.restype = c_double
-         self.assertEqual(sqrt(2), math.sqrt(2))
 +
 +@unittest.skipUnless(sys.platform.startswith('linux'),
 +                     'Test only valid for Linux')
 +class LibPathFindTest(unittest.TestCase):
 +    def test_find_on_libpath(self):
 +        import subprocess
 +        import tempfile
 +
 +        try:
 +            p = subprocess.Popen(['gcc', '--version'], stdout=subprocess.PIPE,
 +                                 stderr=subprocess.DEVNULL)
 +            out, _ = p.communicate()
 +        except OSError:
 +            raise unittest.SkipTest('gcc, needed for test, not available')
 +        with tempfile.TemporaryDirectory() as d:
 +            # create an empty temporary file
 +            srcname = os.path.join(d, 'dummy.c')
 +            libname = 'py_ctypes_test_dummy'
 +            dstname = os.path.join(d, 'lib%s.so' % libname)
 +            with open(srcname, 'w') as f:
 +                pass
 +            self.assertTrue(os.path.exists(srcname))
 +            # compile the file to a shared library
 +            cmd = ['gcc', '-o', dstname, '--shared',
 +                   '-Wl,-soname,lib%s.so' % libname, srcname]
 +            out = subprocess.check_output(cmd)
 +            self.assertTrue(os.path.exists(dstname))
 +            # now check that the .so can't be found (since not in
 +            # LD_LIBRARY_PATH)
 +            self.assertIsNone(find_library(libname))
 +            # now add the location to LD_LIBRARY_PATH
 +            with test.support.EnvironmentVarGuard() as env:
 +                KEY = 'LD_LIBRARY_PATH'
 +                if KEY not in env:
 +                    v = d
 +                else:
 +                    v = '%s:%s' % (env[KEY], d)
 +                env.set(KEY, v)
 +                # now check that the .so can be found (since in
 +                # LD_LIBRARY_PATH)
 +                self.assertEqual(find_library(libname), 'lib%s.so' % libname)
 +
 +
  if __name__ == "__main__":
      unittest.main()