-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_hatch_build.py
More file actions
46 lines (38 loc) · 1.52 KB
/
test_hatch_build.py
File metadata and controls
46 lines (38 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from os import listdir
from pathlib import Path
from shutil import rmtree
from subprocess import check_call
from sys import modules, path, platform
class TestHatchBuild:
def test_hatch_build(self):
project = "test_project_hatch_build"
rmtree(f"hatch_cpp/tests/{project}/project/extension.so", ignore_errors=True)
rmtree(f"hatch_cpp/tests/{project}/project/extension.pyd", ignore_errors=True)
modules.pop("project", None)
modules.pop("project.extension", None)
# compile
check_call(
[
"hatch-build",
"--hooks-only",
"--",
"--libraries.0.name=project/extension",
"--libraries.0.sources=cpp/project/basic.cpp",
"--libraries.0.include-dirs=cpp",
"--libraries.0.binding=nanobind",
],
cwd=f"hatch_cpp/tests/{project}",
)
# assert built
if project == "test_project_limited_api" and platform != "win32":
assert "extension.abi3.so" in listdir(f"hatch_cpp/tests/{project}/project")
else:
if platform == "win32":
assert "extension.pyd" in listdir(f"hatch_cpp/tests/{project}/project")
else:
assert "extension.so" in listdir(f"hatch_cpp/tests/{project}/project")
# import
here = Path(__file__).parent / project
path.insert(0, str(here))
import project.extension
assert project.extension.hello() == "A string"