From: Martin Panter Date: Thu, 29 Sep 2016 04:40:56 +0000 (+0000) Subject: Merge test cleanup from 3.5 into 3.6 X-Git-Tag: v3.6.0b2~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a8e1ea80c2f2e8334b659f208fa3798219aebea;p=python Merge test cleanup from 3.5 into 3.6 --- 6a8e1ea80c2f2e8334b659f208fa3798219aebea diff --cc Lib/ctypes/test/test_find.py index c7205f5ddf,94b0b890b7..b99fdcba7b --- a/Lib/ctypes/test/test_find.py +++ b/Lib/ctypes/test/test_find.py @@@ -69,71 -69,5 +69,48 @@@ class Test_OpenGL_libs(unittest.TestCas self.assertFalse(os.path.lexists(test.support.TESTFN)) self.assertIsNone(result) + +@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) + + - # 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)) - if __name__ == "__main__": unittest.main()