forked from spacetelescope/romancal
-
Notifications
You must be signed in to change notification settings - Fork 0
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
use pytest to collect test names #3
Merged
zacharyburnett
merged 1 commit into
zacharyburnett:scsb174
from
braingram:pytest_name_collection
Sep 11, 2024
Merged
Changes from all commits
Commits
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
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 |
---|---|---|
@@ -1,39 +1,22 @@ | ||
import json | ||
import re | ||
from pathlib import Path | ||
|
||
TEST_REQUIREMENTS_FILENAME = ( | ||
Path(__file__).parent.parent.parent / "test_requirements.json" | ||
) | ||
TEST_DIRECTORY = Path(__file__).parent.parent | ||
|
||
|
||
def test_requirements(): | ||
def test_requirements(all_test_names): | ||
test_requirements_filename = TEST_REQUIREMENTS_FILENAME.expanduser().absolute() | ||
test_directory = TEST_DIRECTORY.expanduser().absolute() | ||
|
||
with open(test_requirements_filename) as test_requirements_file: | ||
requirements = json.load(test_requirements_file) | ||
|
||
required_tests = sorted( | ||
{ | ||
test | ||
for requirement_tests in requirements.values() | ||
for test in requirement_tests | ||
} | ||
) | ||
required_test_names = { | ||
test | ||
for requirement_tests in requirements.values() | ||
for test in requirement_tests | ||
} | ||
|
||
existing_tests = [] | ||
test_regex = re.compile(r"def (test_[^\(]+)\(.*\):") | ||
for test_filename in test_directory.glob("**/test_*.py"): | ||
with open(test_filename) as test_file: | ||
test_file_contents = test_file.read() | ||
|
||
for match in re.finditer(test_regex, test_file_contents): | ||
test = f"{test_directory.stem}.{str(test_filename.relative_to(test_directory).parent).replace('/', '.')}.{test_filename.stem}.{match.group(1)}" | ||
if test in required_tests: | ||
existing_tests.append(test) | ||
|
||
existing_tests = sorted(existing_tests) | ||
|
||
assert existing_tests == required_tests | ||
missing_test_names = required_test_names - all_test_names | ||
assert not missing_test_names, f"Missing tests {missing_test_names} required by DMS" | ||
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.
nice!