-
Notifications
You must be signed in to change notification settings - Fork 91
refactor(integration-tests): Split ExternalAction into ClpAction and NonClpAction; deprecate subprocess_utils and logging_utils modules.
#2242
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
Open
quinntaylormitchell
wants to merge
10
commits into
y-scope:main
Choose a base branch
from
quinntaylormitchell:testing-migration-externalaction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7e4ab2f
Use ExternalAction flows throughout the testing suite.
quinntaylormitchell bb6d688
Rabbit.
quinntaylormitchell c64c205
Add from_cmd and from_args class methods.
quinntaylormitchell 6edf8b6
Raise RuntimeError instead of pytest.fail().
quinntaylormitchell 55fff1a
Rabbit.
quinntaylormitchell 8d6c494
Merge branch 'main' into feature branch
quinntaylormitchell 4848857
Merge branch 'main' into feature branch
quinntaylormitchell d9eaa68
Add assert_returncode() method.
quinntaylormitchell 4e4463f
Split some ExternalAction attributes into two derived classes.
quinntaylormitchell 3bcbff7
Merge branch 'main' into feature branch
quinntaylormitchell 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,64 @@ | ||
| """File structure validators.""" | ||
|
|
||
| from pathlib import Path | ||
| from tempfile import NamedTemporaryFile | ||
| from typing import IO | ||
|
|
||
| from tests.utils.classes import ExternalAction | ||
| from tests.utils.utils import get_binary_path | ||
|
|
||
|
|
||
| def is_dir_tree_content_equal(path1: Path, path2: Path) -> bool: | ||
| """ | ||
| :param path1: | ||
| :param path2: | ||
| :return: Whether two files/directories hold the exactly same content. | ||
| :raise: RuntimeError if the diff command fails due to execution errors. | ||
| """ | ||
| cmd = [get_binary_path("diff"), "--brief", "--recursive", str(path1), str(path2)] | ||
| diff_action = ExternalAction(cmd=cmd) | ||
| rc = diff_action.completed_proc.returncode | ||
| if rc == 0: | ||
| return True | ||
| if rc == 1: | ||
| return False | ||
| err_msg = f"Command failed {' '.join(cmd)}: {diff_action.completed_proc.stderr}" | ||
| raise RuntimeError(err_msg) | ||
|
|
||
|
|
||
| def is_json_file_structurally_equal(json_fp1: Path, json_fp2: Path) -> bool: | ||
| """ | ||
| :param json_fp1: | ||
| :param json_fp2: | ||
| :return: Whether two JSON files are structurally equal after sorting has been applied. | ||
| """ | ||
| with ( | ||
| _sort_json_keys_and_rows(json_fp1) as temp_file_1, | ||
| _sort_json_keys_and_rows(json_fp2) as temp_file_2, | ||
| ): | ||
| return is_dir_tree_content_equal(Path(temp_file_1.name), Path(temp_file_2.name)) | ||
|
|
||
|
|
||
| def _sort_json_keys_and_rows(json_fp: Path) -> IO[str]: | ||
| """ | ||
| Normalize a JSON file to a stable, deterministically ordered form for comparison. | ||
|
|
||
| :param json_fp: | ||
| :return: A named temporary file (delete on close) that contains the sorted JSON content. | ||
| :raise: RuntimeError if jq is missing or fails due to execution errors. | ||
| """ | ||
| jq_action = ExternalAction( | ||
| cmd=[get_binary_path("jq"), "--sort-keys", "--compact-output", ".", str(json_fp)], | ||
| ) | ||
| jq_rc = jq_action.completed_proc.returncode | ||
| if jq_rc != 0: | ||
| err_msg = f"jq failed with exit code {jq_rc} for {json_fp}" | ||
| raise RuntimeError(err_msg) | ||
|
|
||
| sorted_fp = NamedTemporaryFile(mode="w+", delete=True) # noqa: SIM115 | ||
| sorted_lines = sorted(jq_action.completed_proc.stdout.splitlines()) | ||
| for line in sorted_lines: | ||
| sorted_fp.write(f"{line}\n") | ||
| sorted_fp.flush() | ||
| sorted_fp.seek(0) | ||
|
quinntaylormitchell marked this conversation as resolved.
Outdated
|
||
| return sorted_fp | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.