diff --git a/test_python_bindings.py b/test_python_bindings.py index 48f01e0..44cc30c 100644 --- a/test_python_bindings.py +++ b/test_python_bindings.py @@ -95,8 +95,20 @@ def test_create_rejects_too_small_stack(): raise AssertionError(f"expected ValueError for stackSize={stack_size}") +def test_missing_library_raises_oserror(): + try: + weaseljson.WeaselJsonParser( + weaseljson.WeaselJsonCallbacksBase(), + build_dir="/nonexistent", + ) + except OSError: + return + raise AssertionError("expected OSError when the shared library is missing") + + if __name__ == "__main__": test_object_keys_routed_correctly() test_mixed_values() test_create_rejects_too_small_stack() + test_missing_library_raises_oserror() print("python bindings ok") diff --git a/weaseljson.py b/weaseljson.py index b6c20d6..7063c98 100644 --- a/weaseljson.py +++ b/weaseljson.py @@ -84,13 +84,7 @@ class WeaselJsonParser: pass if self._lib is None: - import sys - - print( - "Could not find libweaseljson implementation", - file=sys.stderr, - ) - sys.exit(1) + raise OSError(f"Could not load libweaseljson from {build_dir}") self._lib.WeaselJsonParser_create.argtypes = ( ctypes.c_int,