Skip to content
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

Fix TypeError when using Pyproject.toml #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,21 @@ def test_load_config_overrides(toml, expected):
open_mock = mock.mock_open(read_data=toml)
with mock.patch("toml_sort.cli.open", open_mock):
section = cli.load_pyproject()
assert expected == cli.parse_config_overrides(section)
assert isinstance(section, dict)
parsed = cli.parse_config_overrides(section)
assert expected == parsed
# Make sure we are returning normal python types rather
# than TOMLKit types.
for key, value in parsed.items():
assert type(key) == str # pylint: disable=unidiomatic-typecheck
assert (
type(value) # pylint: disable=unidiomatic-typecheck
== SortOverrideConfiguration
)
assert (
type(value.first) # pylint: disable=unidiomatic-typecheck
== list
)


@pytest.mark.parametrize(
Expand Down
7 changes: 4 additions & 3 deletions toml_sort/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,10 @@ def parse_config_overrides(
"""Parse the tool.tomlsort.overrides section of the config."""
fields = dataclasses.fields(SortOverrideConfiguration)
settings_definition = {field.name: field.type for field in fields}
override_settings = dict(
tomlsort_section.get("overrides", tomlkit.document())
)
override_settings = tomlsort_section.get(
"overrides", tomlkit.document()
).unwrap()

overrides = {}
for path, settings in override_settings.items():
if not settings.keys() <= settings_definition.keys():
Expand Down