-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5/n][pipeline-gen] Helper method to determine whether test should automatically run #41
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 | ||
) |
50 changes: 50 additions & 0 deletions
50
scripts/tests/pipeline_generator/test_pipeline_generator_helper.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pytest | ||
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__])) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do these input args come from? I feel that without the context, this function (and the test) does not really serve much purpose.
you should put a more meaningful
TestStep
s into context, and test with that.like there are many other fields in
TestStep
? why does this function need to send the entireTestStep
in together? why is this not a member function ofTestStep
but a standalone function? whyrun_all
does not really "run all", but will skip the optional ones?