Skip to content

Commit f641d25

Browse files
authored
Merge pull request #72 from sbidoul/ref-oca_list_addons_to_test_as_reqs
Avoid conflict between addons in test-requirements.txt and local repo
2 parents e78d8e1 + f250258 commit f641d25

4 files changed

+92
-8
lines changed

bin/oca_install_addons__deps_and_addons_path

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010

1111
set -ex
12-
shopt -s nullglob # in case there is setup.py nor pyproject.toml
12+
shopt -s nullglob # in case there is no setup.py nor pyproject.toml
1313

1414
# Compute and install direct dependencies of installable addons in $ADDONS_DIR
1515
# (this includes addons, python external dependencies and odoo itself).
@@ -31,7 +31,7 @@ cat test-requirements.txt
3131
# we create a constraints file with local directory references to the addons to test.
3232
if python -c 'import sys; sys.exit(sys.version_info < (3,6))' ; then
3333
# python >= 3.6
34-
oca_list_addons_to_test_as_reqs >> test-constraints.txt
34+
oca_list_addons_to_test_as_url_reqs >> test-constraints.txt
3535
else
3636
# old python where pip does not support URL constraints
3737
touch test-constraints.txt

bin/oca_list_addons_to_test_as_reqs bin/oca_list_addons_to_test_as_url_reqs

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/usr/bin/env python
2-
3-
#
4-
# Print addons to test as pip requirements pointing to local directories.
5-
# There is an option to make them editable or file URLs.
6-
#
2+
"""Print addons to test as pip requirements pointing to local directories.
3+
Addons that are referenced as direct URLs in test-requirements.txt are ignored
4+
because they are going to be installed from there, as test-requirements.txt
5+
must have priority over the local repo, when there are PR references in it.
6+
"""
77

88
import argparse
99
import os
10+
import re
1011
import subprocess
1112
from pathlib import Path
1213

@@ -39,7 +40,21 @@ def _list_addons_to_test():
3940
)
4041

4142

42-
parser = argparse.ArgumentParser()
43+
def _addons_in_test_requirements(addons_dir):
44+
"""Return a set of addon names that have direct URL requirements in test-requirements.txt."""
45+
test_requirements_path = addons_dir / "test-requirements.txt"
46+
if not test_requirements_path.exists():
47+
return set()
48+
url_addon_regex = re.compile(r"^odoo\d*-addon-(?P<addon_name>[a-zA-Z0-9_-]+) *@")
49+
res = set()
50+
for line in test_requirements_path.read_text().splitlines():
51+
match = url_addon_regex.match(line)
52+
if match:
53+
res.add(match.group("addon_name").replace("-", "_"))
54+
return res
55+
56+
57+
parser = argparse.ArgumentParser(description=__doc__)
4358
parser.add_argument(
4459
"--editable",
4560
action="store_true",
@@ -48,7 +63,10 @@ parser.add_argument(
4863
args = parser.parse_args()
4964

5065
addons_dir = Path(os.getenv("ADDONS_DIR", "."))
66+
addons_to_skip = _addons_in_test_requirements(addons_dir)
5167
for addon_name in _list_addons_to_test():
68+
if addon_name in addons_to_skip:
69+
continue
5270
pyproject_path = addons_dir / addon_name / "pyproject.toml"
5371
if pyproject_path.exists():
5472
print(_make_addon_req(pyproject_path.parent, args.editable))

tests/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ def did_run_test_module(output, test_module):
8787
test_module is the full name of the test (addon_name.tests.test_module).
8888
"""
8989
return "odoo.addons." + test_module in output
90+
91+
92+
def make_addon_dist_name(addon_name):
93+
odoo_series = int(os.getenv("ODOO_VERSION").partition(".")[0])
94+
return "odoo{odoo_series}-addon-{name}".format(
95+
name=addon_name,
96+
odoo_series=odoo_series if odoo_series < 15 else "",
97+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import subprocess
2+
import textwrap
3+
4+
from .common import make_addons_dir, make_addon_dist_name
5+
6+
7+
def test_oca_list_addons_to_test_as_url_reqs__basic():
8+
"""Basic successful test."""
9+
with make_addons_dir(
10+
["addon_success", "addon_with_deb_dep", "uninstallable_addon"]
11+
) as addons_dir:
12+
result = subprocess.check_output(
13+
["oca_list_addons_to_test_as_url_reqs"], cwd=addons_dir, text=True
14+
)
15+
assert result == textwrap.dedent(
16+
f"""\
17+
{make_addon_dist_name('addon_success')} @ {addons_dir.as_uri()}/addon_success
18+
{make_addon_dist_name('addon_with_deb_dep')} @ {addons_dir.as_uri()}/addon_with_deb_dep
19+
"""
20+
)
21+
22+
23+
def test_oca_list_addons_to_test_as_url_reqs__editable():
24+
"""Basic successful test with editables."""
25+
with make_addons_dir(
26+
["addon_success", "addon_with_deb_dep", "uninstallable_addon"]
27+
) as addons_dir:
28+
result = subprocess.check_output(
29+
["oca_list_addons_to_test_as_url_reqs", "--editable"],
30+
cwd=addons_dir,
31+
text=True,
32+
)
33+
assert result == textwrap.dedent(
34+
f"""\
35+
-e {addons_dir.as_uri()}/addon_success#egg={make_addon_dist_name('addon_success')}
36+
-e {addons_dir.as_uri()}/addon_with_deb_dep#egg={make_addon_dist_name('addon_with_deb_dep')}
37+
"""
38+
)
39+
40+
41+
def test_oca_list_addons_to_test_as_url_reqs__skip_test_requirement():
42+
"""Basic successful test."""
43+
with make_addons_dir(
44+
["addon_success", "addon_with_deb_dep", "uninstallable_addon"]
45+
) as addons_dir:
46+
# add URL reference to addon_success
47+
addons_dir.joinpath("test-requirements.txt").write_text(
48+
f"{make_addon_dist_name('addon_success')} @ git+https://github.com/oca/dummy@refs/pull/123/head"
49+
)
50+
result = subprocess.check_output(
51+
["oca_list_addons_to_test_as_url_reqs"], cwd=addons_dir, text=True
52+
)
53+
# addon_success should not be in result because it is already in test-requirements.txt
54+
assert result == textwrap.dedent(
55+
f"""\
56+
{make_addon_dist_name('addon_with_deb_dep')} @ {addons_dir.as_uri()}/addon_with_deb_dep
57+
"""
58+
)

0 commit comments

Comments
 (0)