From b5317f4c60b8f9d47254711ebdc1c89539146eeb Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Tue, 19 Mar 2024 19:45:42 +0800 Subject: [PATCH] Take inline overrides into account in mandatory_include and bootstrap_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 --- .../plainbox/impl/unit/test_testplan.py | 37 +++++++++++++++++++ checkbox-ng/plainbox/impl/unit/testplan.py | 36 ++++++++++-------- 2 files changed, 57 insertions(+), 16 deletions(-) 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