-
Notifications
You must be signed in to change notification settings - Fork 457
Initial support for reading mapping configuration as TOML #1108
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 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
973fb4f
Rename parse_mapping to parse_mapping_cfg
akx 08ef31e
Remove duplicated test for parse_mapping_cfg
akx 888e85e
Add initial support for TOML mapping configuration
akx 6de4873
Be explicit about pyproject.toml `tool` table style
akx f0d9924
Support list `pattern`s in TOML mappings
akx 3b4db00
Prefer tomllib to tomli
akx f3ba705
Complain if an user attempts a `mapping` TOML key
akx 378f0ab
Do not allow a `babel` mapping in standalone config files
akx c76d6e9
Add test cases for bad TOML files
akx 4b348b6
Incorporate CR suggestion
akx 853a0ce
Give config-parsing errors an unique exception class
akx 7786b0c
Remove reference to non-existent function
akx a820cf5
Make `_parse_mapping_toml()` a private API for the time being
akx 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pathlib | ||
from io import BytesIO | ||
|
||
import pytest | ||
|
||
from babel.messages import frontend | ||
|
||
toml_test_cases_path = pathlib.Path(__file__).parent / "toml-test-cases" | ||
assert toml_test_cases_path.is_dir(), "toml-test-cases directory not found" | ||
|
||
|
||
def test_toml_mapping_multiple_patterns(): | ||
""" | ||
Test that patterns may be specified as a list in TOML, | ||
and are expanded to multiple entries in the method map. | ||
""" | ||
method_map, options_map = frontend.parse_mapping_toml(BytesIO(b""" | ||
[[mappings]] | ||
method = "python" | ||
pattern = ["xyz/**.py", "foo/**.py"] | ||
""")) | ||
assert len(method_map) == 2 | ||
assert method_map[0] == ('xyz/**.py', 'python') | ||
assert method_map[1] == ('foo/**.py', 'python') | ||
|
||
|
||
@pytest.mark.parametrize("test_case", toml_test_cases_path.glob("bad.*.toml"), ids=lambda p: p.name) | ||
def test_bad_toml_test_case(test_case: pathlib.Path): | ||
""" | ||
Test that bad TOML files raise a ValueError. | ||
""" | ||
with pytest.raises(frontend.ConfigurationError): | ||
with test_case.open("rb") as f: | ||
frontend.parse_mapping_toml( | ||
f, | ||
filename=test_case.name, | ||
style="pyproject.toml" if "pyproject" in test_case.name else "standalone", | ||
) |
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,2 @@ | ||
[extractors] | ||
custom = { module = "mypackage.module", func = "myfunc" } |
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 @@ | ||
[[extractors]] |
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,3 @@ | ||
[mapping] | ||
method = "jinja2" | ||
pattern = "**.html" |
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 @@ | ||
mappings = [8] |
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 @@ | ||
mappings = "python" |
2 changes: 2 additions & 0 deletions
2
tests/messages/toml-test-cases/bad.missing-extraction-method.toml
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,2 @@ | ||
[[mappings]] | ||
pattern = ["xyz/**.py", "foo/**.py"] |
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.