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

Fixed #1461: Quiet config option not respected by file API in some ci… #1464

Merged
merged 1 commit into from
Sep 5, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Find out more about isort's release policy [here](https://pycqa.github.io/isort/

### 5.6.0 TBD
- Fixed #1463: Better interactive documentation for future option.
- Fixed #1461: Quiet config option not respected by file API in some circumstances.

### 5.5.1 September 4, 2020
- Fixed #1454: Ensure indented import sections with import heading and a preceding comment don't cause import sorting loops.
Expand Down
3 changes: 1 addition & 2 deletions isort/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def sort_file(
"""
with io.File.read(filename) as source_file:
actual_file_path = file_path or source_file.path
config = _config(path=actual_file_path, config=config, **config_kwargs)
changed: bool = False
try:
if write_to_stdout:
Expand All @@ -309,7 +310,6 @@ def sort_file(
file_path=actual_file_path,
disregard_skip=disregard_skip,
extension=extension,
**config_kwargs,
)
else:
tmp_file = source_file.path.with_suffix(source_file.path.suffix + ".isorted")
Expand All @@ -325,7 +325,6 @@ def sort_file(
file_path=actual_file_path,
disregard_skip=disregard_skip,
extension=extension,
**config_kwargs,
)
if changed:
if show_diff or ask_to_apply:
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/test_ticketed_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,3 +657,65 @@ def test_isort_intelligently_places_noqa_comments_issue_1456():
profile="black",
show_diff=True,
)


def test_isort_respects_quiet_from_sort_file_api_see_1461(capsys, tmpdir):
"""Test to ensure isort respects the quiet API parameter when passed in via the API.
See: https://github.com/PyCQA/isort/issues/1461.
"""
settings_file = tmpdir.join(".isort.cfg")
custom_settings_file = tmpdir.join(".custom.isort.cfg")
tmp_file = tmpdir.join("file.py")
tmp_file.write("import b\nimport a\n")
isort.file(tmp_file)

out, error = capsys.readouterr()
assert not error
assert "Fixing" in out

# When passed in directly as a setting override
tmp_file.write("import b\nimport a\n")
isort.file(tmp_file, quiet=True)
out, error = capsys.readouterr()
assert not error
assert not out

# Present in an automatically loaded configuration file
isort.settings._find_config.cache_clear()
settings_file.write(
"""
[isort]
quiet = true
"""
)
tmp_file.write("import b\nimport a\n")
isort.file(tmp_file)
out, error = capsys.readouterr()
assert not error
assert not out

# In a custom configuration file
settings_file.write(
"""
[isort]
quiet = false
"""
)
custom_settings_file.write(
"""
[isort]
quiet = true
"""
)
tmp_file.write("import b\nimport a\n")
isort.file(tmp_file, settings_file=str(custom_settings_file))
out, error = capsys.readouterr()
assert not error
assert not out

# Reused configuration object
custom_config = Config(settings_file=str(custom_settings_file))
isort.file(tmp_file, config=custom_config)
out, error = capsys.readouterr()
assert not error
assert not out