Skip to content

Commit

Permalink
Take inline overrides into account in mandatory_include and bootstrap…
Browse files Browse the repository at this point in the history
…_include sections of a test plan (BugFix) (#1079)

* Take inline overrides into account in mandatory_include section of a test plan

Although inline overrides were taking into account in the `include`
section of a test plan, it was not the case for the `mandatory_include`
section.

So a test plan like this:

unit: test plan
id: test-plan
name: My test plan
mandatory_include:
    mandatory-cert-blocker-job  certification_status=blocker
include:
    regular-cert-blocker-job    certification_status=blocker

would only make "regular-cert-blocker-job" a cert-blocker, not
"mandatory-cert-blocker-job".

* Add support for bootstrap_include section

- Move the V class one level above, so it can be used for the different
include sections of the test plan.
- Fix issue found by Max (`mandatory_include` was parsed only if there
was an `include` section)
- Add support for `bootstrap_include` for good measure

* Add unit test to check bootstrap_include inline overrides
  • Loading branch information
pieqq authored Mar 19, 2024
1 parent a5f63a9 commit b5317f4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
37 changes: 37 additions & 0 deletions checkbox-ng/plainbox/impl/unit/test_testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,40 @@ def test_nested_tesplan__multiple_namespaces(self):
self.assertIsInstance(qual_list[1].matcher, OperatorMatcher)
self.assertEqual(qual_list[1].matcher.value, 'ns2::Bar')
self.assertEqual(qual_list[1].inclusive, True)


class TestTestPlanUnitSupport(TestCase):

def setUp(self):
self.tp1 = TestPlanUnit({
"id": "tp1",
"unit": "test plan",
"name": "An example test plan 1",
"bootstrap_include": "bootstrap_job certification_status=blocker",
"mandatory_include": "mandatory_job certification_status=blocker",
"include": "job1 certification_status=non-blocker",
})
self.tp2 = TestPlanUnit({
"id": "tp1",
"unit": "test plan",
"name": "An example test plan 2",
"include": "job1 certification_status=blocker",
})

def test_inline_override(self):
support_tp1 = TestPlanUnitSupport(self.tp1)
support_tp2 = TestPlanUnitSupport(self.tp2)
self.assertEqual(
support_tp1.override_list,
[
("^bootstrap_job$", [("certification_status", "blocker")]),
("^job1$", [("certification_status", "non-blocker")]),
("^mandatory_job$", [("certification_status", "blocker")]),
],
)
self.assertEqual(
support_tp2.override_list,
[
("^job1$", [("certification_status", "blocker")]),
],
)
36 changes: 20 additions & 16 deletions checkbox-ng/plainbox/impl/unit/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,23 +826,27 @@ def _get_inline_overrides(
collected into a list of tuples ``(field, value)`` and this list is
subsequently packed into a tuple ``(pattern, field_value_list)``.
"""
override_list = []
if testplan.include is not None:

class V(Visitor):

def visit_IncludeStmt_node(self, node: IncludeStmt):
if not node.overrides:
return
pattern = r"^{}$".format(
testplan.qualify_id(node.pattern.text))
field_value_list = [
(override_exp.field.text.replace('-', '_'),
override_exp.value.text)
for override_exp in node.overrides]
override_list.append((pattern, field_value_list))
class V(Visitor):

V().visit(IncludeStmtList.parse(testplan.include))
def visit_IncludeStmt_node(self, node: IncludeStmt):
if not node.overrides:
return
pattern = r"^{}$".format(
testplan.qualify_id(node.pattern.text))
field_value_list = [
(override_exp.field.text.replace('-', '_'),
override_exp.value.text)
for override_exp in node.overrides]
override_list.append((pattern, field_value_list))
override_list = []
include_sections = (
testplan.bootstrap_include,
testplan.mandatory_include,
testplan.include,
)
for section in include_sections:
if section:
V().visit(IncludeStmtList.parse(section))
for tp_unit in testplan.get_nested_part():
override_list.extend(self._get_inline_overrides(tp_unit))
return override_list

0 comments on commit b5317f4

Please sign in to comment.