Coverage for /home/runner/work/zserio/zserio/compiler/extensions/python/runtime/tests/test_cppbind.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-10-29 13:10 +0000

1import unittest 

2import os 

3 

4from zserio.cppbind import import_cpp_class 

5from zserio.exception import PythonRuntimeException 

6 

7 

8class MissingCppClass: 

9 pass 

10 

11 

12class CppBindTest(unittest.TestCase): 

13 

14 def test_invalid_env(self): 

15 os.environ["ZSERIO_PYTHON_IMPLEMENTATION"] = "invalid" 

16 with self.assertRaises(PythonRuntimeException): 

17 import_cpp_class("MissingCppClass") 

18 

19 def test_missing_cpp_default(self): 

20 os.environ.pop("ZSERIO_PYTHON_IMPLEMENTATION") 

21 self.assertIsNone(import_cpp_class("MissingCppClass")) 

22 

23 def test_missing_cpp_python(self): 

24 os.environ["ZSERIO_PYTHON_IMPLEMENTATION"] = "python" 

25 self.assertIsNone(import_cpp_class("MissingCppClass")) 

26 

27 def test_missing_cpp_cpp(self): 

28 os.environ["ZSERIO_PYTHON_IMPLEMENTATION"] = "cpp" 

29 with self.assertRaises(PythonRuntimeException): 

30 import_cpp_class("MissingCppClass")