-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_editable.py
More file actions
79 lines (73 loc) · 2.88 KB
/
Copy pathtest_editable.py
File metadata and controls
79 lines (73 loc) · 2.88 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# SPDX-FileCopyrightText: 2022-present Stéphane Bidoul <stephane.bidoul@acsone.eu>
# SPDX-FileCopyrightText: 2022-present ACSONE <https://acsone.eu>
# SPDX-FileCopyrightText: 2025-present XCG SAS <https://orbeet.io>
#
# SPDX-License-Identifier: MIT
import subprocess
import sys
from pathlib import Path
from typing import List
from packaging.version import Version
if sys.version_info < (3, 8):
import importlib_metadata
else:
import importlib.metadata as importlib_metadata
import pytest
@pytest.mark.parametrize(
"project_name,expected_editable_pth_lines,expected_editable_addon_names",
[
("project1", ["src"], ["addona", "addonb"]),
("project2", ["src", "build/__editable_odoo_addons__"], ["addona", "addonb"]),
("project3", [""], ["addona", "addonb"]),
("project4", ["src", "addons_group1", "addons_group2"], ["addona", "addonb"]),
("project5", ["", "build/__editable_odoo_addons__"], ["addona", "addonb"]),
("project6", ["build/__editable_odoo_addons__"], ["addona", "addonb"]),
("project7", ["build/__editable_odoo_addons__"], ["project7"]),
],
)
def test_odoo_addons_dependencies(
project_name: str,
expected_editable_pth_lines: List[str],
expected_editable_addon_names: List[str],
data_path: Path,
tmp_path: Path,
) -> None:
subprocess.run(
[
sys.executable,
"-m",
"pip",
"install",
"-e",
str(data_path / project_name), # str for compat with Python 3.7 on Windows
"--no-deps",
"--no-build-isolation",
"--target",
str(tmp_path), # str for compat with Python 3.7 on Windows
],
check=True,
)
# Check we have the .pth lines we expect.
pth_lines = set()
# Cope with older hatchling versions which adds the project directory to the
# editable paths.
if project_name == "project6" and Version(
importlib_metadata.version("hatchling")
) < Version("1.20"):
expected_editable_pth_lines = expected_editable_pth_lines[:] + [""]
for pth_file in tmp_path.glob("*.pth"):
pth_lines.update((tmp_path / pth_file).read_text().splitlines())
assert pth_lines == {
str(data_path / project_name / line) for line in expected_editable_pth_lines
}
# Check all addons are in the editable paths.
editable_addon_names = []
for pth_line in pth_lines:
addons_dir = Path(pth_line) / "odoo" / "addons"
for addon_name in expected_editable_addon_names:
if (addons_dir / addon_name).is_dir():
editable_addon_names.append(addon_name)
assert sorted(editable_addon_names) == expected_editable_addon_names
# Check that the project odoo packages have not been copied to the target.
assert not tmp_path.joinpath("odoo").exists()
assert not tmp_path.joinpath(project_name).exists()