diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-05 06:05:04 -0700 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2020-09-05 06:05:04 -0700 |
commit | 5c2362bc4c873aaa6f9e5aa5cd96ee12bc704e2d (patch) | |
tree | 3465c91b007b23359382a2870efa0df2e4f4a277 | |
parent | b8d2290a76c3adf6098c3fb4886225dc94ada6a9 (diff) | |
download | isort-issue/1461/respect-quiet-in-api.tar.gz |
Fixed #1461: Quiet config option not respected by file API in some circumstances.issue/1461/respect-quiet-in-api
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | isort/api.py | 3 | ||||
-rw-r--r-- | tests/unit/test_ticketed_features.py | 62 |
3 files changed, 64 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bb54d3c..53b30a0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/isort/api.py b/isort/api.py index cbcc3e6e..f59bc6d9 100644 --- a/isort/api.py +++ b/isort/api.py @@ -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: @@ -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") @@ -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: diff --git a/tests/unit/test_ticketed_features.py b/tests/unit/test_ticketed_features.py index dc5c7781..2fd9073e 100644 --- a/tests/unit/test_ticketed_features.py +++ b/tests/unit/test_ticketed_features.py @@ -657,3 +657,65 @@ from my.horribly.long.import.line.that.just.keeps.on.going.and.going.and.going i 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 |