-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ✨ implement rule logic #108
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
be2128d
feat: :sparkles: implement rule logic
martonvago 161aab0
test: :white_check_mark: add tests for rule
martonvago 6a90dff
test: :white_check_mark: add tests for rule with exclude
martonvago 9db8eeb
refactor: :recycle: rename function
martonvago b43273b
build: :wrench: update lockfile
martonvago f4de7f5
refactor: :recycle: match _flat_map in other PR
martonvago 189e86f
refactor: :recycle: review markups
martonvago 5cdac82
chore: :wrench: update vulture allowlist
martonvago 3f6d974
Merge branch 'main' into feat/rules
martonvago 6f34449
Merge branch 'main' into feat/rules
martonvago 26fdb45
refactor: :recycle: move flatmap to own function
martonvago 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| from check_datapackage.check import check | ||
| from check_datapackage.config import Config | ||
| from check_datapackage.examples import ( | ||
| example_package_descriptor, | ||
| example_resource_descriptor, | ||
| ) | ||
| from check_datapackage.issue import Issue | ||
| from check_datapackage.rule import Rule | ||
|
|
||
| lowercase_rule = Rule( | ||
| jsonpath="$.name", | ||
| message="Name must be lowercase.", | ||
| check=lambda name: name.islower(), | ||
| type="lowercase", | ||
| ) | ||
| resource_name_rule = Rule( | ||
| jsonpath="$.resources[*].name", | ||
| message="Resource name must start with 'woolly'.", | ||
| check=lambda name: name.startswith("woolly"), | ||
| type="resource-name", | ||
| ) | ||
|
|
||
|
|
||
| def test_direct_jsonpath(): | ||
| descriptor = example_package_descriptor() | ||
| descriptor["name"] = "ALLCAPS" | ||
| config = Config(rules=[lowercase_rule]) | ||
| issues = check(descriptor, config=config) | ||
|
|
||
| assert issues == [ | ||
| Issue( | ||
| jsonpath=lowercase_rule.jsonpath, | ||
| type=lowercase_rule.type, | ||
| message=lowercase_rule.message, | ||
| ) | ||
| ] | ||
|
|
||
|
|
||
| def test_indirect_jsonpath(): | ||
| descriptor = example_package_descriptor() | ||
| descriptor["resources"].append(example_resource_descriptor()) | ||
| descriptor["resources"][1]["name"] = "not starting with woolly" | ||
|
|
||
| config = Config(rules=[resource_name_rule]) | ||
| issues = check(descriptor, config=config) | ||
|
|
||
| assert issues == [ | ||
| Issue( | ||
| jsonpath="$.resources[1].name", | ||
| type=resource_name_rule.type, | ||
| message=resource_name_rule.message, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def test_multiple_rules(): | ||
| descriptor = example_package_descriptor() | ||
| descriptor["name"] = "ALLCAPS" | ||
| descriptor["resources"][0]["name"] = "not starting with woolly" | ||
|
|
||
| config = Config(rules=[lowercase_rule, resource_name_rule]) | ||
| issues = check(descriptor, config=config) | ||
|
|
||
| assert issues == [ | ||
| Issue( | ||
| jsonpath=lowercase_rule.jsonpath, | ||
| type=lowercase_rule.type, | ||
| message=lowercase_rule.message, | ||
| ), | ||
| Issue( | ||
| jsonpath="$.resources[0].name", | ||
| type=resource_name_rule.type, | ||
| message=resource_name_rule.message, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| def test_rules_and_default_checks(): | ||
| descriptor = example_package_descriptor() | ||
| descriptor["name"] = "ALLCAPS" | ||
| del descriptor["resources"] | ||
| config = Config(rules=[lowercase_rule]) | ||
| issues = check(descriptor, config=config) | ||
|
|
||
| assert [issue.type for issue in issues] == ["lowercase", "required"] | ||
|
|
||
|
|
||
| def test_no_matching_jsonpath(): | ||
| descriptor = example_package_descriptor() | ||
| rule = Rule( | ||
| jsonpath="$.missing", | ||
| message="This check always fails.", | ||
| check=lambda value: False, | ||
| type="always-fail", | ||
| ) | ||
| config = Config(rules=[rule]) | ||
| issues = check(descriptor, config=config) | ||
|
|
||
| assert issues == [] |
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 |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| # ruff: noqa | ||
| # mypy: ignore-errors | ||
| rules # unused variable (src/check_datapackage/config.py:38) | ||
| version # unused variable (src/check_datapackage/config.py:40) |
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.