Skip to content

Commit 2336898

Browse files
committed
Add test dependency kind
Add a new kind called test to support dependency on test. ref: eng/devenv/issues#9 it/org/software-supply-chain/production-pipeline/issues#131
1 parent 32769c1 commit 2336898

File tree

5 files changed

+46
-26
lines changed

5 files changed

+46
-26
lines changed

src/e3/anod/deps.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
if TYPE_CHECKING:
1313
from typing import Any, Hashable, Literal
1414
from e3.anod.spec import Anod, DEPENDENCY_PRIMITIVE
15-
from e3.mypy import assert_never
1615

1716
logger = e3.log.getLogger("e3.anod.deps")
1817

@@ -38,6 +37,14 @@ def __str__(self) -> str:
3837
class Dependency:
3938
kind: DEPENDENCY_PRIMITIVE
4039

40+
ALLOWED_REQUIRE: dict[str, str] = {
41+
"build_tree": "build",
42+
"download": "download",
43+
"installation": "install",
44+
"source_pkg": "source",
45+
"test": "test",
46+
}
47+
4148
def __init__(
4249
self,
4350
name: str,
@@ -52,6 +59,7 @@ def __init__(
5259
| Literal["installation"]
5360
| Literal["download"]
5461
| Literal["source_pkg"]
62+
| Literal["test"]
5563
) = "build_tree",
5664
track: bool = False,
5765
**kwargs: Any,
@@ -103,26 +111,14 @@ def __init__(
103111
else:
104112
raise e3.anod.error.SpecError(f"invalid qualifier type: {qualifier}")
105113

106-
if require not in (
107-
"build_tree",
108-
"download",
109-
"installation",
110-
"source_pkg",
111-
):
114+
if require in self.ALLOWED_REQUIRE:
115+
self.kind = self.ALLOWED_REQUIRE[require] # type: ignore[assignment]
116+
else:
112117
raise e3.anod.error.SpecError(
113-
f"require should be build_tree, download, installation,"
114-
f" or source_pkg not {require}."
118+
f"Invalid require parameter {require!r}. "
119+
f"Allowed values are {', '.join(self.ALLOWED_REQUIRE)}"
115120
)
116-
if require == "build_tree":
117-
self.kind = "build"
118-
elif require == "download":
119-
self.kind = "download"
120-
elif require == "installation":
121-
self.kind = "install"
122-
elif require == "source_pkg":
123-
self.kind = "source"
124-
else:
125-
assert_never()
121+
126122
self.track = track
127123

128124
def env(self, parent: Anod, default_env: BaseEnv) -> BaseEnv:

src/e3/anod/spec.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@
6666

6767
# Anod Dependency can target a build, install, or source
6868
DEPENDENCY_PRIMITIVE = Union[
69-
BUILD_PRIMITIVE, DOWNLOAD_PRIMITIVE, INSTALL_PRIMITIVE, SOURCE_PRIMITIVE
69+
BUILD_PRIMITIVE,
70+
DOWNLOAD_PRIMITIVE,
71+
INSTALL_PRIMITIVE,
72+
SOURCE_PRIMITIVE,
73+
TEST_PRIMITIVE,
7074
]
7175

7276
# Supported primitives are build, install, source, and test
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from e3.anod.spec import Anod
2+
3+
4+
class Spec14(Anod):
5+
6+
@property
7+
def build_deps(self):
8+
return [Anod.Dependency(name="spec4", require="test")]
9+
10+
@Anod.primitive()
11+
def build(self):
12+
pass

tests/tests_e3/anod/context_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ def test_add_anod_action13(self):
367367
assert "x86-linux.spec13.download_bin" in keys
368368
assert "x86-linux.spec13.install" in keys
369369

370+
def test_add_anod_action14(self):
371+
"""Check test dependency."""
372+
ac = self.create_context()
373+
ac.add_anod_action("spec14", env=ac.default_env, primitive="build")
374+
result = ac.schedule(ac.always_download_source_resolver)
375+
assert "x86-linux.spec4.test" in list(result.vertex_data.keys())
376+
370377
def test_source_fails_when_missing_source_primitive(self):
371378
"""Source action should fail when the source primitive is undefined.
372379

tests/tests_e3/anod/spec_test.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,15 @@ def test_spec_check_dll_closure_single_file(ldd) -> None: # type: ignore[no-unt
289289

290290
def test_spec_wrong_dep():
291291
"""Check exception message when wrong dependency is set."""
292-
with pytest.raises(SpecError) as err:
292+
with pytest.raises(
293+
SpecError,
294+
match=(
295+
"Invalid require parameter 'invalid'. "
296+
f"Allowed values are {', '.join(Anod.Dependency.ALLOWED_REQUIRE)}"
297+
),
298+
):
293299
Anod.Dependency("foo", require="invalid")
294300

295-
assert (
296-
"require should be build_tree, download, installation,"
297-
" or source_pkg not invalid" in str(err)
298-
)
299-
300301

301302
def test_primitive():
302303
class NoPrimitive(Anod):

0 commit comments

Comments
 (0)