diff --git a/checkbox-ng/plainbox/impl/unit/test_testplan.py b/checkbox-ng/plainbox/impl/unit/test_testplan.py index 73d76b4d3..b817bc736 100644 --- a/checkbox-ng/plainbox/impl/unit/test_testplan.py +++ b/checkbox-ng/plainbox/impl/unit/test_testplan.py @@ -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")]), + ], + ) diff --git a/checkbox-ng/plainbox/impl/unit/testplan.py b/checkbox-ng/plainbox/impl/unit/testplan.py index 96b5c9ae3..efbb97315 100644 --- a/checkbox-ng/plainbox/impl/unit/testplan.py +++ b/checkbox-ng/plainbox/impl/unit/testplan.py @@ -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