From f34c8d4c8a4612f60e24aab6ca9716fa54349691 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 21:25:07 -0700 Subject: Add test case for issue #909 - settings path skip files ignored --- test_isort.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test_isort.py b/test_isort.py index 8c157c4e..c76f3720 100644 --- a/test_isort.py +++ b/test_isort.py @@ -30,6 +30,7 @@ import os.path import posixpath import sys import sysconfig +from subprocess import check_output import pytest @@ -2888,3 +2889,30 @@ def test_to_ensure_correctly_handling_of_whitespace_only_issue_811(capsys): out, err = capsys.readouterr() assert out == '' assert err == '' + + +def test_settings_path_skip_issue_909(tmpdir): + base_dir = tmpdir.mkdir('project') + config_dir = base_dir.mkdir('conf') + config_dir.join('.isort.cfg').write('[isort]\n' + 'skip =\n' + ' file_to_be_skipped.py\n' + 'skip_glob =\n' + ' *glob_skip*\n') + + base_dir.join('file_glob_skip.py').write('import os\n' + '\n' + 'print("Hello World")\n' + '\n' + 'import sys\n') + base_dir.join('file_to_be_skipped.py').write('import os\n' + '\n' + 'print("Hello World")' + '\n' + 'import sys\n') + + test_run_directory = os.getcwd() + os.chdir(str(base_dir)) + results = check_output(['isort', '--check-only', '--settings-path=conf/.isort.cfg']) + os.chdir(str(test_run_directory)) + assert b'skipped' in results -- cgit v1.2.1 From 6c04efcad926e3fa4837c7e57883948aa03c3b35 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 21:37:38 -0700 Subject: Sort test_isort.py's imports --- test_isort.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test_isort.py b/test_isort.py index c76f3720..7c44dd3f 100644 --- a/test_isort.py +++ b/test_isort.py @@ -23,7 +23,6 @@ OTHER DEALINGS IN THE SOFTWARE. """ from __future__ import absolute_import, division, print_function, unicode_literals -from tempfile import NamedTemporaryFile import io import os import os.path @@ -31,14 +30,15 @@ import posixpath import sys import sysconfig from subprocess import check_output +from tempfile import NamedTemporaryFile import pytest from isort import finders, main, settings from isort.isort import SortImports -from isort.utils import exists_case_sensitive from isort.main import is_python_file from isort.settings import WrapModes +from isort.utils import exists_case_sensitive try: import toml @@ -2915,4 +2915,5 @@ def test_settings_path_skip_issue_909(tmpdir): os.chdir(str(base_dir)) results = check_output(['isort', '--check-only', '--settings-path=conf/.isort.cfg']) os.chdir(str(test_run_directory)) - assert b'skipped' in results + + assert b'skipped 2' in results.lower() -- cgit v1.2.1 From d3be87ea58b1dab67ae76db5c9980b356f5893e6 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 21:38:01 -0700 Subject: Update main.py to take into account the provided settings path (if there is one) --- isort/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/isort/main.py b/isort/main.py index 24de5c0c..8c3ec9a3 100644 --- a/isort/main.py +++ b/isort/main.py @@ -345,7 +345,8 @@ def main(argv=None): arguments['recursive'] = True if not arguments.get('apply', False): arguments['ask_to_apply'] = True - config = from_path(os.path.abspath(file_names[0]) or os.getcwd()).copy() + + config = from_path(arguments.get('settings_path', '') or os.path.abspath(file_names[0]) or os.getcwd()).copy() config.update(arguments) wrong_sorted_files = False skipped = [] -- cgit v1.2.1 From 03741dbdb3d4292d058257d09dc1e58cd020bb81 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 21:40:36 -0700 Subject: Add both cases to test --- test_isort.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_isort.py b/test_isort.py index 7c44dd3f..df46a75a 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2913,6 +2913,8 @@ def test_settings_path_skip_issue_909(tmpdir): test_run_directory = os.getcwd() os.chdir(str(base_dir)) + with pytest.raises(Exception): # without the settings path provided: the command should not skip & identify errors + check_output(['isort', '--check-only']) results = check_output(['isort', '--check-only', '--settings-path=conf/.isort.cfg']) os.chdir(str(test_run_directory)) -- cgit v1.2.1 From bbcc06a1d54b41f154809c1d173ba5104b07ee92 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 21:41:56 -0700 Subject: Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85638132..d656640d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +### 4.3.16 - March 23, 2019 - hot fix release +- Fixed issue #909 - skip and skip-glob are not enforced when using settings-path + ### 4.3.15 - March 10, 2019 - hot fix release - Fixed a regression with handling streaming input from pipes (Issue #895) - Fixed handling of \x0c whitespace character (Issue #811) -- cgit v1.2.1 From cf2e435a420133d0ac87ba342c268647bf0c6bb1 Mon Sep 17 00:00:00 2001 From: Timothy Crosley Date: Sat, 23 Mar 2019 22:09:05 -0700 Subject: Fix config error --- test_isort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_isort.py b/test_isort.py index df46a75a..1e75c17e 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2913,7 +2913,7 @@ def test_settings_path_skip_issue_909(tmpdir): test_run_directory = os.getcwd() os.chdir(str(base_dir)) - with pytest.raises(Exception): # without the settings path provided: the command should not skip & identify errors + with pytest.raises(Exception): # without the settings path provided: the command should not skip & identify errors check_output(['isort', '--check-only']) results = check_output(['isort', '--check-only', '--settings-path=conf/.isort.cfg']) os.chdir(str(test_run_directory)) -- cgit v1.2.1