diff --git a/tests/test_conditional_steps.py b/tests/test_conditional_steps.py index 2d402a91..95d03361 100644 --- a/tests/test_conditional_steps.py +++ b/tests/test_conditional_steps.py @@ -223,17 +223,66 @@ def test_prebuild_clean(test_env: ConditionalStepsTestEnv, test_env.check_fail(steps_info) +def test_conditional_step_critical(test_env: ConditionalStepsTestEnv) -> None: + steps_info: StepsInfo = test_env.build_conditional_steps_info(is_conditional_step_passed=False) + steps_info.conditional_step.critical = True + test_env.check_success(steps_info) + assert test_env.captured_out.out + assert "WARNING" in test_env.captured_out.out + + # TODO: implement support of conditional step with children # https://github.com/Samsung/Universum/issues/709 -def test_conditional_step_with_children(test_env: ConditionalStepsTestEnv) -> None: +def test_conditional_step_with_children(test_env: ConditionalStepsTestEnv, capsys: pytest.CaptureFixture) -> None: steps_info: StepsInfo = test_env.build_conditional_steps_info(is_conditional_step_passed=True) steps_info.conditional_step.children = Configuration([Step(name=" dummy child 1"), Step(name=" dummy child 2")]) test_env.check_fail(steps_info) + captured_out = capsys.readouterr() + assert "not supported" in captured_out.out -def test_conditional_step_critical(test_env: ConditionalStepsTestEnv) -> None: - steps_info: StepsInfo = test_env.build_conditional_steps_info(is_conditional_step_passed=False) - steps_info.conditional_step.critical = True - test_env.check_success(steps_info) - assert test_env.captured_out.out - assert "WARNING" in test_env.captured_out.out + +# TODO: implement support of conditional steps addition and multiplication +# https://github.com/Samsung/Universum/issues/709 +def test_add_step_to_conditional(test_env: ConditionalStepsTestEnv, capsys: pytest.CaptureFixture) -> None: + config_lines: List[str] = [ + "from universum.configuration_support import Configuration, Step", + "true_branch_config = Configuration([Step(name='true branch')])", + "conditional_step = Step(name='conditional', if_succeeded=true_branch_config)", + "another_step = Step(name='another step')", + "configs = Configuration([conditional_step + another_step])" + ] + config: str = "\n".join(config_lines) + test_env.configs_file.write_text(config, "utf-8") + test_env.run(expect_failure=True) + + captured_out = capsys.readouterr() + assert "not supported" in captured_out.out + + +# TODO: during implementation of the full conditional steps addition support, refactor this test to avoid direct usage +# of the ConditionalStepsTestEnv "internal" API (underscored methods) and config building duplication +# https://github.com/Samsung/Universum/issues/709 +def test_add_conditional_to_step(test_env: ConditionalStepsTestEnv, capsys: pytest.CaptureFixture) -> None: + # pylint: disable = protected-access + steps_info = test_env.build_conditional_steps_info(is_conditional_step_passed=True) + true_branch_config = test_env._build_configuration_string(steps_info.true_branch_steps) + config_lines: List[str] = [ + "from universum.configuration_support import Configuration, Step", + f"true_branch_config = {true_branch_config}", + f"conditional_step = Step(**{str(steps_info.conditional_step)})", + "another_step = Step(name='another step')", + + # `true/false_branch_steps` should be Python objects from this script + "conditional_step.is_conditional = True", + "conditional_step.if_succeeded = true_branch_config", + + "configs = Configuration([another_step + conditional_step])" + ] + config: str = "\n".join(config_lines) + test_env.configs_file.write_text(config, "utf-8") + test_env.run() + + test_env._check_conditional_step_artifacts_present(steps_info) + test_env._check_executed_step_artifacts_present(steps_info) + # pylint: enable = protected-access diff --git a/universum/configuration_support.py b/universum/configuration_support.py index 43831a8c..3b731a7e 100644 --- a/universum/configuration_support.py +++ b/universum/configuration_support.py @@ -3,6 +3,7 @@ from warnings import warn import copy import os +from .lib.ci_exception import CriticalCiException __all__ = [ @@ -397,6 +398,9 @@ def __add__(self, other: 'Step') -> 'Step': >>> step2 + step1 {'name': 'barfoo', 'command': ['bar', 'foo'], 'critical': True, 'background': True, 'my_var1': 'barfoo', 'my_var2': 'baz'} """ + if self.is_conditional: + # TODO: https://github.com/Samsung/Universum/issues/709 + raise CriticalCiException("Conditional steps addition is not supported yet") return Step( name=self.name + other.name, command=self.command + other.command, diff --git a/universum/modules/launcher.py b/universum/modules/launcher.py index c195c14f..e72a35b4 100644 --- a/universum/modules/launcher.py +++ b/universum/modules/launcher.py @@ -415,7 +415,7 @@ def process_project_configs(self) -> configuration_support.Configuration: raise CriticalCiException(text) if self._is_conditional_step_with_children_present(self.project_config): - raise CriticalCiException("Conditional step doesn't support children configuration") + raise CriticalCiException("Conditional steps with child configurations are not supported") self._warn_if_critical_conditional_steps_present(self.project_config) return self.project_config