Skip to content

Commit

Permalink
Make _parse_mapping_toml() a private API for the time being
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Aug 7, 2024
1 parent 7786b0c commit a820cf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions babel/messages/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def _get_mappings(self):
if os.path.basename(self.mapping_file) == "pyproject.toml"
else "standalone"
)
method_map, options_map = parse_mapping_toml(
method_map, options_map = _parse_mapping_toml(

Check warning on line 551 in babel/messages/frontend.py

View check run for this annotation

Codecov / codecov/patch

babel/messages/frontend.py#L551

Added line #L551 was not covered by tests
fileobj,
filename=self.mapping_file,
style=file_style,
Expand Down Expand Up @@ -1086,13 +1086,15 @@ def _parse_config_object(config: dict, *, filename="(unknown)"):
return method_map, options_map


def parse_mapping_toml(
def _parse_mapping_toml(
fileobj: BinaryIO,
filename: str = "(unknown)",
style: Literal["standalone", "pyproject.toml"] = "standalone",
):
"""Parse an extraction method mapping from a binary file-like object.
.. warning: As of this version of Babel, this is a private API subject to changes.
:param fileobj: a readable binary file-like object containing the configuration TOML to parse
:param filename: the name of the file being parsed, for error messages
:param style: whether the file is in the style of a `pyproject.toml` file, i.e. whether to look for `tool.babel`.
Expand Down
4 changes: 2 additions & 2 deletions tests/messages/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,13 +1448,13 @@ def test_update_init_missing(self):
),
(
mapping_toml,
frontend.parse_mapping_toml,
frontend._parse_mapping_toml,
None,
True,
),
(
mapping_toml,
partial(frontend.parse_mapping_toml, style="pyproject.toml"),
partial(frontend._parse_mapping_toml, style="pyproject.toml"),
lambda s: re.sub(r"^(\[+)", r"\1tool.babel.", s, flags=re.MULTILINE),
True,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/messages/test_toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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"""
method_map, options_map = frontend._parse_mapping_toml(BytesIO(b"""
[[mappings]]
method = "python"
pattern = ["xyz/**.py", "foo/**.py"]
Expand All @@ -31,7 +31,7 @@ def test_bad_toml_test_case(test_case: pathlib.Path):
"""
with pytest.raises(frontend.ConfigurationError):
with test_case.open("rb") as f:
frontend.parse_mapping_toml(
frontend._parse_mapping_toml(
f,
filename=test_case.name,
style="pyproject.toml" if "pyproject" in test_case.name else "standalone",
Expand Down

0 comments on commit a820cf5

Please sign in to comment.