From 547eacebd0077dda70b91389ca15caf89c18debd Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 7 Oct 2024 22:44:27 +0000 Subject: [PATCH 1/2] p Signed-off-by: kevin --- .../pipeline_generator/pipeline_generator_helper.py | 13 +++++++++++++ .../test_pipeline_generator_helper.py | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 scripts/pipeline_generator/pipeline_generator_helper.py create mode 100644 scripts/tests/pipeline_generator/test_pipeline_generator_helper.py diff --git a/scripts/pipeline_generator/pipeline_generator_helper.py b/scripts/pipeline_generator/pipeline_generator_helper.py new file mode 100644 index 0000000..d034c08 --- /dev/null +++ b/scripts/pipeline_generator/pipeline_generator_helper.py @@ -0,0 +1,13 @@ +from typing import List + +from .step import TestStep + +def step_should_run(step: TestStep, run_all: bool, list_file_diff: List[str]) -> bool: + """Determine whether the step should automatically run or not.""" + if step.optional: + return False + if not step.source_file_dependencies or run_all: + return True + return any(source_file in diff_file + for source_file in step.source_file_dependencies + for diff_file in list_file_diff) \ No newline at end of file diff --git a/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py b/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py new file mode 100644 index 0000000..b7e1bf3 --- /dev/null +++ b/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py @@ -0,0 +1,9 @@ +import pytest +import sys + +from scripts.pipeline_generator.pipeline_generator_helper import step_should_run + + + +if __name__ == "__main__": + sys.exit(pytest.main(["-v", __file__])) From 5975f628a4a239a5b226e62067903e9bf7587ec6 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 7 Oct 2024 23:59:07 +0000 Subject: [PATCH 2/2] p Signed-off-by: kevin --- .../pipeline_generator_helper.py | 5 ++- .../test_pipeline_generator_helper.py | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/scripts/pipeline_generator/pipeline_generator_helper.py b/scripts/pipeline_generator/pipeline_generator_helper.py index d034c08..ab02d95 100644 --- a/scripts/pipeline_generator/pipeline_generator_helper.py +++ b/scripts/pipeline_generator/pipeline_generator_helper.py @@ -9,5 +9,6 @@ def step_should_run(step: TestStep, run_all: bool, list_file_diff: List[str]) -> if not step.source_file_dependencies or run_all: return True return any(source_file in diff_file - for source_file in step.source_file_dependencies - for diff_file in list_file_diff) \ No newline at end of file + for source_file in step.source_file_dependencies + for diff_file in list_file_diff + ) diff --git a/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py b/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py index b7e1bf3..d0a9003 100644 --- a/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py +++ b/scripts/tests/pipeline_generator/test_pipeline_generator_helper.py @@ -2,8 +2,49 @@ import sys from scripts.pipeline_generator.pipeline_generator_helper import step_should_run +from scripts.pipeline_generator.step import TestStep +def _get_test_step(): + return TestStep( + label="Test", + command="echo 'Hello, World!'", + ) +@pytest.mark.parametrize( + ("run_all, source_file_dependencies, list_file_diff, expected"), + [ + (False, None, [], True), + (True, None, [], True), + (False, ["file1", "file2"], [], False), + (True, ["file1", "file2"], [], True), + (False, ["file1", "file2"], ["file1"], True), + (False, ["file1", "file2"], ["file3"], False), + (True, ["file1", "file2"], ["file3"], True), + ] +) +def test_step_should_run(run_all, source_file_dependencies, list_file_diff, expected): + test_step = _get_test_step() + test_step.source_file_dependencies = source_file_dependencies + assert step_should_run(test_step, run_all, list_file_diff) == expected + +@pytest.mark.parametrize( + ("run_all, source_file_dependencies, list_file_diff"), + [ + (False, None, []), + (True, None, []), + (False, ["file1", "file2"], []), + (True, ["file1", "file2"], []), + (False, ["file1", "file2"], ["file1"]), + (False, ["file1", "file2"], ["file3"]), + (True, ["file1", "file2"], ["file3"]), + ] +) +def test_step_should_run_optional(run_all, source_file_dependencies, list_file_diff): + test_step = _get_test_step() + test_step.optional = True # When optional is True, step should not run at all + test_step.source_file_dependencies = source_file_dependencies + + assert step_should_run(test_step, run_all, list_file_diff) == False if __name__ == "__main__": sys.exit(pytest.main(["-v", __file__]))