-
Notifications
You must be signed in to change notification settings - Fork 114
Simplify #6
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
Simplify #6
Changes from all commits
Commits
Show all changes
6 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
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
| class InvalidClassifier(Exception): | ||
| pass | ||
|
|
||
|
|
||
| def trove_tester(classifiers, deprecated_classifiers): | ||
| # Check the classifiers | ||
| for classifier in classifiers: | ||
| split = classifier.split(" :: ") | ||
|
|
||
| # Check if this is an invalid top-level classifier | ||
| if len(split) == 1: | ||
| raise InvalidClassifier(f"Top-level classifier {classifier!r} is invalid") | ||
|
|
||
| # Check if all parent classifiers are specified | ||
| for i in range(2, len(split)): | ||
| parent = " :: ".join(split[:i]) | ||
| if parent not in classifiers: | ||
| raise InvalidClassifier(f"Classifier {parent!r} is missing") | ||
|
|
||
| # Check the sub-classifiers | ||
| for sub in split: | ||
|
|
||
| # Check for whitespace | ||
| if sub.strip().rstrip() != sub: | ||
| raise InvalidClassifier( | ||
| "Classifiers starting or ending with whitespace are invalid" | ||
| ) | ||
|
|
||
| # Check for private classifiers | ||
| if sub.lower().startswith("private"): | ||
| raise InvalidClassifier( | ||
| "Classifiers starting with 'Private' are invalid" | ||
| ) | ||
|
|
||
| # Check for stray colons | ||
| if ":" in sub: | ||
| raise InvalidClassifier("Classifiers containing ':' are invalid") | ||
|
|
||
| # Check the deprecated classifiers | ||
| for deprecated_classifier, deprecated_by in deprecated_classifiers.items(): | ||
|
|
||
| # Check if the classifier is in both lists | ||
| if deprecated_classifier in classifiers: | ||
| raise InvalidClassifier( | ||
| f"Classifier {deprecated_classifier!r} in both valid and deprecated classifiers" | ||
| ) | ||
|
|
||
| # Check if all deprecated_by classifiers exist | ||
| for new_classifier in deprecated_by: | ||
| if new_classifier not in classifiers: | ||
| raise InvalidClassifier(f"Classifier {new_classifier!r} does not exist") | ||
|
|
||
| print("All classifiers passed :)") |
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,4 @@ | ||
| from tester import trove_tester | ||
| from trove_classifiers import classifiers, deprecated_classifiers | ||
|
|
||
| trove_tester(classifiers, deprecated_classifiers) |
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
| import pytest | ||
|
|
||
| from tester import trove_tester, InvalidClassifier | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "classifiers, deprecated_classifiers", | ||
| [ | ||
| ({"Foo :: Bar", "Foo :: Bar :: Baz",}, {}), | ||
| ({"Foo :: Bar"}, {"Biz :: Baz": ["Foo :: Bar"]}), | ||
| ], | ||
| ) | ||
| def test_success(classifiers, deprecated_classifiers): | ||
| trove_tester(classifiers, deprecated_classifiers) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "classifiers, deprecated_classifiers, expected", | ||
| [ | ||
| ({"Foo", "Foo :: Bar"}, {}, "Top-level classifier 'Foo' is invalid",), | ||
| ({"Foo :: Bar :: Baz"}, {}, "Classifier 'Foo :: Bar' is missing"), | ||
| ( | ||
| {"Foo :: Bar",}, | ||
| {"Biz :: Baz": ["Bing :: Bang"]}, | ||
| "Classifier 'Bing :: Bang' does not exist", | ||
| ), | ||
| ( | ||
| {"Foo :: Bar",}, | ||
| {"Foo :: Bar": []}, | ||
| "Classifier 'Foo :: Bar' in both valid and deprecated classifiers", | ||
| ), | ||
| ({"Private :: Foo"}, {}, "Classifiers starting with 'Private' are invalid"), | ||
| ({"private :: Foo"}, {}, "Classifiers starting with 'Private' are invalid"), | ||
| ({"Foo :: Private"}, {}, "Classifiers starting with 'Private' are invalid"), | ||
| ({"Foo :: private"}, {}, "Classifiers starting with 'Private' are invalid"), | ||
| ( | ||
| {" Foo :: Bar"}, | ||
| {}, | ||
| "Classifiers starting or ending with whitespace are invalid", | ||
| ), | ||
| ( | ||
| {"Foo :: Bar "}, | ||
| {}, | ||
| "Classifiers starting or ending with whitespace are invalid", | ||
| ), | ||
| ({"Foo: :: Bar"}, {}, "Classifiers containing ':' are invalid",), | ||
| ({"Foo :: B:ar"}, {}, "Classifiers containing ':' are invalid",), | ||
| ({"Foo :: Bar: Baz"}, {}, "Classifiers containing ':' are invalid",), | ||
| ], | ||
| ) | ||
| def test_failure(classifiers, deprecated_classifiers, expected): | ||
| with pytest.raises(InvalidClassifier) as excinfo: | ||
| trove_tester(classifiers, deprecated_classifiers) | ||
|
|
||
| assert excinfo.value.args == (expected,) |
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
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.