-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for reading mapping configuration as TOML (#1108)
* Rename parse_mapping to parse_mapping_cfg and remove duplicated test * Add initial support for TOML mapping configuration (prefer tomllib to tomli) --------- Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Tomas R <[email protected]>
- Loading branch information
1 parent
34ed517
commit d26a669
Showing
15 changed files
with
274 additions
and
66 deletions.
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
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 |
---|---|---|
@@ -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 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 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 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 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 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 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.