Repository navigation
Fix testcase order #522
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
Merged
Merged
Fix testcase order #522
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 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,35 @@ | ||
| from pathlib import Path | ||
|
|
||
| from problemtools.metadata import load_metadata | ||
| from problemtools.model import load_files, load_testdata | ||
| from problemtools.model.testdata import TestCase, TestDataGroup | ||
|
|
||
| # Not test classes -- just named that way by the model. Tell pytest not to collect them. | ||
| TestCase.__test__ = False # type: ignore[attr-defined] | ||
| TestDataGroup.__test__ = False # type: ignore[attr-defined] | ||
|
|
||
|
|
||
| def test_items_are_ordered_by_base_name(tmp_path: Path) -> None: | ||
| (tmp_path / 'problem.yaml').write_text('name: Test\n') | ||
| secret = tmp_path / 'data' / 'secret' | ||
| for name in ['foo', 'foo-bar', 'foo-baz/1', 'foo.a/1']: | ||
| (secret / name).parent.mkdir(parents=True, exist_ok=True) | ||
| (secret / f'{name}.in').write_text('') | ||
| (secret / f'{name}.ans').write_text('') | ||
|
|
||
| testdata = load_testdata(load_files(tmp_path), load_metadata(tmp_path)) | ||
|
|
||
| secret_group = testdata.items[0] | ||
| assert isinstance(secret_group, TestDataGroup) | ||
| assert [str(item.path) for item in secret_group.items] == [ | ||
| 'secret/foo', | ||
| 'secret/foo-bar', | ||
| 'secret/foo-baz', | ||
| 'secret/foo.a', | ||
| ] | ||
| assert [str(case.path) for case in testdata.get_all_testcases()] == [ | ||
| 'secret/foo', | ||
| 'secret/foo-bar', | ||
| 'secret/foo-baz/1', | ||
| 'secret/foo.a/1', | ||
| ] | ||
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.
My PyTest is a bit rusty, but this looks out of place to me. Shouldn't this be in in the class bodies in
model/testdata.py?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.
Yes, that's another way to do it. I have a somewhat strong preference to not clutter our production code with test cruft.
Admittedly, for these two classes, I am considering making an exception. But not in this PR.