Skip to content

Commit 3b7a6d3

Browse files
authored
fix: make task_context transforms really work without a task-context (#761)
It's not enough to make it optional in the schema, the actual code also has to deal with its absence. Thanks @ErichDonGubler!
1 parent d57132e commit 3b7a6d3

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/taskgraph/transforms/task_context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
@transforms.add
8686
def render_task(config, tasks):
8787
for task in tasks:
88-
sub_config = task.pop("task-context")
88+
sub_config = task.pop("task-context", None)
89+
if sub_config is None:
90+
yield task
91+
continue
8992
params_context = {}
9093
for var, path in sub_config.pop("from-parameters", {}).items():
9194
if isinstance(path, str):

test/test_transform_task_context.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from copy import deepcopy
77
from pprint import pprint
88

9+
import pytest
910
from pytest_taskgraph import FakeParameters
1011

1112
from taskgraph.transforms import task_context
@@ -14,7 +15,7 @@
1415
here = os.path.abspath(os.path.dirname(__file__))
1516

1617
TASK_DEFAULTS = {
17-
"description": "fake description {object} {file} {param} {object_and_file}"
18+
"description": "fake description {object} {file} {param} {object_and_file} "
1819
"{object_and_param} {file_and_param} {object_file_and_param} {param_fallback} {name}",
1920
"name": "fake-task-name",
2021
"task-context": {
@@ -37,11 +38,24 @@
3738
],
3839
},
3940
}
41+
EXPECTED_DESCRIPTION = (
42+
"fake description object file param object-overrides-file "
43+
"param-overrides-object param-overrides-file param-overrides-all default fake-task-name"
44+
)
45+
NO_CONTEXT = deepcopy(TASK_DEFAULTS)
46+
del NO_CONTEXT["task-context"]
4047

4148

42-
def test_transforms(request, run_transform, graph_config):
43-
task = deepcopy(TASK_DEFAULTS)
44-
49+
@pytest.mark.parametrize(
50+
"task,description",
51+
(
52+
pytest.param(deepcopy(TASK_DEFAULTS), EXPECTED_DESCRIPTION, id="with-context"),
53+
pytest.param(
54+
deepcopy(NO_CONTEXT), TASK_DEFAULTS["description"], id="no-context"
55+
),
56+
),
57+
)
58+
def test_transforms(request, run_transform, graph_config, task, description):
4559
params = FakeParameters(
4660
{
4761
"param": "param",
@@ -77,8 +91,4 @@ def test_transforms(request, run_transform, graph_config):
7791
print("Dumping task:")
7892
pprint(task, indent=2)
7993

80-
assert (
81-
task["description"]
82-
== "fake description object file param object-overrides-file"
83-
"param-overrides-object param-overrides-file param-overrides-all default fake-task-name"
84-
)
94+
assert task["description"] == description

0 commit comments

Comments
 (0)