"""Reject incompatible native libraries before exposing callable functions.""" from pathlib import Path import runpy from types import SimpleNamespace import unittest from unittest.mock import patch import pheon._native class LoaderTests(unittest.TestCase): def load(self, library): with patch("cffi.FFI.dlopen", return_value=library): return runpy.run_path(str(Path(pheon._native.__file__))) def test_matching_versions_are_accepted(self): self.load( SimpleNamespace( pheon_abi_version=lambda: 1, pheon_arrow_schema_version=lambda: 1 ) ) def test_incompatible_abi_or_schema_is_rejected(self): for abi, schema in [(2, 1), (1, 2)]: with self.assertRaisesRegex(ImportError, "Incompatible Pheon library"): self.load( SimpleNamespace( pheon_abi_version=lambda: abi, pheon_arrow_schema_version=lambda: schema, ) ) def test_unversioned_library_is_rejected(self): with self.assertRaisesRegex(ImportError, "version API"): self.load(SimpleNamespace())