Skip to content

Commit 07818b6

Browse files
committed
Add find_library tests for emscripten platform
1 parent a82b5f5 commit 07818b6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Lib/test/test_ctypes/test_find.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,37 @@ def test_find_library_with_ld(self):
123123
self.assertNotEqual(find_library('c'), None)
124124

125125

126+
@unittest.skipUnless(sys.platform.startswith('emscripten'),
127+
'Test only valid for Emscripten')
128+
class FindLibraryEmscripten(unittest.TestCase):
129+
def test_find_on_libpath(self):
130+
import tempfile
131+
132+
# A very simple wasm module
133+
# In WAT format: (module)
134+
wasm_module = b'\x00asm\x01\x00\x00\x00\x00\x08\x04name\x02\x01\x00'
135+
136+
with tempfile.TemporaryDirectory() as d:
137+
libname = 'dummy'
138+
dstname = os.path.join(d, 'lib%s.so' % libname)
139+
with open(dstname, 'wb') as f:
140+
f.write(wasm_module)
141+
142+
# now check that the .so can't be found (since not in
143+
# LD_LIBRARY_PATH)
144+
self.assertIsNone(find_library(libname))
145+
# now add the location to LD_LIBRARY_PATH
146+
with os_helper.EnvironmentVarGuard() as env:
147+
KEY = 'LD_LIBRARY_PATH'
148+
if KEY not in env:
149+
v = d
150+
else:
151+
v = '%s:%s' % (env[KEY], d)
152+
env.set(KEY, v)
153+
# now check that the .so can be found (since in
154+
# LD_LIBRARY_PATH)
155+
self.assertEqual(find_library(libname), dstname)
156+
157+
126158
if __name__ == "__main__":
127159
unittest.main()

0 commit comments

Comments
 (0)