2 Unit test for Pybind wrap program 3 Author: Matthew Sklar, Varun Agrawal 15 sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
17 osp.normpath(osp.abspath(osp.join(__file__,
'../../../build/wrap'))))
21 sys.path.append(osp.dirname(osp.dirname(osp.abspath(__file__))))
25 """Tests for Python wrapper based on Pybind11.""" 26 TEST_DIR = osp.dirname(osp.realpath(__file__))
27 INTERFACE_DIR = osp.join(TEST_DIR,
'fixtures')
28 PYTHON_TEST_DIR = osp.join(TEST_DIR,
'expected',
'python')
29 PYTHON_ACTUAL_DIR = osp.join(TEST_DIR,
"actual",
"python")
32 os.makedirs(PYTHON_ACTUAL_DIR, exist_ok=
True)
38 use_boost_serialization=False):
40 Common function to wrap content in `sources`. 42 with open(osp.join(self.
TEST_DIR,
"pybind_wrapper.tpl"),
43 encoding=
"UTF-8")
as template_file:
44 module_template = template_file.read()
48 module_name=module_name,
49 top_module_namespaces=[
''],
51 module_template=module_template,
52 use_boost_serialization=use_boost_serialization)
54 output = osp.join(self.
TEST_DIR, output_dir, module_name +
".cpp")
56 if not osp.exists(osp.join(self.
TEST_DIR, output_dir)):
57 os.mkdir(osp.join(self.
TEST_DIR, output_dir))
59 wrapper.wrap(sources, output)
65 Compute the comparison between the expected and actual file, 66 and assert if diff is zero. 69 success = filecmp.cmp(actual, expected)
72 os.system(f
"diff {actual} {expected}")
73 self.assertTrue(success, f
"Mismatch for file {file}")
77 Check generation of python geometry wrapper. 78 python3 ../pybind_wrapper.py --src geometry.h --module_name 79 geometry_py --out output/geometry_py.cc 85 use_boost_serialization=
True)
90 """Test interface file with function info.""" 98 """Test interface file with only class info.""" 106 """Test interface file with templated class.""" 114 """Test interface file with class inheritance definitions.""" 123 Check generation of python wrapper for full namespace definition. 124 python3 ../pybind_wrapper.py --src namespaces.i --module_name 125 namespaces_py --out output/namespaces_py.cpp 135 Tests for operator overloading. 145 Tests for some unique, non-trivial features. 148 output = self.
wrap_content([source],
'special_cases_py',
155 Test if enum generation is correct. 163 if __name__ ==
'__main__':
def wrap_content(self, sources, module_name, output_dir, use_boost_serialization=False)
def test_special_cases(self)
def test_operator_overload(self)
def test_inheritance(self)
def test_namespaces(self)
def compare_and_diff(self, file, actual)