Skip to content

Commit

Permalink
Merge pull request #1464 from PyCQA/issue/1461/respect-quiet-in-api
Browse files Browse the repository at this point in the history
Fixed #1461: Quiet config option not respected by file API in some ci…
  • Loading branch information
timothycrosley committed Sep 5, 2020
2 parents 8971fe4 + 5c2362b commit ae1ae9b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit ae1ae9b

Please sign in to comment.