Skip to content

Return override list in the right order (bugfix) #1856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions checkbox-ng/plainbox/impl/unit/test_testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,21 @@ def setUp(self):
)
self.tp2 = TestPlanUnit(
{
"id": "tp1",
"id": "tp2",
"unit": "test plan",
"name": "An example test plan 2",
"include": "job1 certification_status=blocker",
}
)
self.tp3 = TestPlanUnit(
{
"id": "tp3",
"unit": "test plan",
"name": "An example test plan 3",
"include": "job1 certification_status=non-blocker",
"certification_status_overrides": "apply blocker to .*",
}
)

def test_inline_override(self):
support_tp1 = TestPlanUnitSupport(self.tp1)
Expand All @@ -592,8 +601,8 @@ def test_inline_override(self):
support_tp1.override_list,
[
("^bootstrap_job$", [("certification_status", "blocker")]),
("^job1$", [("certification_status", "non-blocker")]),
("^mandatory_job$", [("certification_status", "blocker")]),
("^job1$", [("certification_status", "non-blocker")]),
],
)
self.assertEqual(
Expand All @@ -602,3 +611,18 @@ def test_inline_override(self):
("^job1$", [("certification_status", "blocker")]),
],
)

def test_certification_status_overrides(self):
"""
Make sure certification_status_overrides is last in the override list
(so that it's applied last and overwrites other certification status
definitions)
"""
support_tp3 = TestPlanUnitSupport(self.tp3)
self.assertEqual(
support_tp3.override_list,
[
("^job1$", [("certification_status", "non-blocker")]),
("^.*$", [("certification_status", "blocker")]),
],
)
12 changes: 6 additions & 6 deletions checkbox-ng/plainbox/impl/unit/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,20 +790,20 @@
The code below in *not* resilient to errors so make sure to
validate the unit before starting with the helper.
"""
override_map = collections.defaultdict(list)
override_map = collections.OrderedDict()
# ^^ Dict[str, Tuple[str, str]]
for pattern, field_value_list in self._get_inline_overrides(testplan):
override_map[pattern].extend(field_value_list)
override_map.setdefault(pattern, []).extend(field_value_list)
for pattern, field, value in self._get_category_overrides(testplan):
override_map[pattern].append((field, value))
override_map.setdefault(pattern, []).append((field, value))

Check warning on line 798 in checkbox-ng/plainbox/impl/unit/testplan.py

View check run for this annotation

Codecov / codecov/patch

checkbox-ng/plainbox/impl/unit/testplan.py#L798

Added line #L798 was not covered by tests
for pattern, field, value in self._get_blocker_status_overrides(
testplan
):
override_map[pattern].append((field, value))
return sorted(
override_map.setdefault(pattern, []).append((field, value))
return [
(key, field_value_list)
for key, field_value_list in override_map.items()
)
]

def _get_category_overrides(
self, testplan: TestPlanUnit
Expand Down
Loading