diff options
author | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-01 17:38:14 -0800 |
---|---|---|
committer | Timothy Crosley <timothy.crosley@gmail.com> | 2019-03-01 17:38:14 -0800 |
commit | 89b45d1e276408218ae0cff36062ab6fc5aa297d (patch) | |
tree | ac17bead080d437c94ff6330add42b8af2f70c43 | |
parent | 1a80f6a5750dfb89e53bebe8d751aa2dee861cfc (diff) | |
download | isort-89b45d1e276408218ae0cff36062ab6fc5aa297d.tar.gz |
Attempt to restore full windows compatiblity
-rw-r--r-- | isort/settings.py | 8 | ||||
-rw-r--r-- | test_isort.py | 18 |
2 files changed, 16 insertions, 10 deletions
diff --git a/isort/settings.py b/isort/settings.py index 2fb0c9bd..2801e780 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -315,10 +315,12 @@ def _get_config_data(file_path, sections): return settings -def should_skip(filename, config, path='/'): +def should_skip(filename, config, path=''): """Returns True if the file should be skipped based on the passed in settings.""" - normalized_path = posixpath.join(path.replace('\\', '/'), filename) - os_path = os.path.normpath(normalized_path) + os_path = os.path.join(path, filename) + normalized_path = os_path.replace('\\', '/') + if normalized_path[1:2] == ':': + normalized_path = normalized_path[2:] if config['safety_excludes'] and safety_exclude_re.search(normalized_path): return True diff --git a/test_isort.py b/test_isort.py index 353978ac..17f686b9 100644 --- a/test_isort.py +++ b/test_isort.py @@ -2710,17 +2710,18 @@ def test_command_line(tmpdir, capfd, multiprocess): from isort.main import main tmpdir.join("file1.py").write("import re\nimport os\n\nimport contextlib\n\n\nimport isort") tmpdir.join("file2.py").write("import collections\nimport time\n\nimport abc\n\n\nimport isort") - arguments = ["-rc", str(tmpdir)] + arguments = ["-rc", str(tmpdir), '--settings-path', os.getcwd()] if multiprocess: arguments.extend(['--jobs', '2']) main(arguments) assert tmpdir.join("file1.py").read() == "import contextlib\nimport os\nimport re\n\nimport isort\n" assert tmpdir.join("file2.py").read() == "import abc\nimport collections\nimport time\n\nimport isort\n" - out, err = capfd.readouterr() - assert not err - # it informs us about fixing the files: - assert str(tmpdir.join("file1.py")) in out - assert str(tmpdir.join("file2.py")) in out + if not sys.platform.startswith('win'): + out, err = capfd.readouterr() + assert not err + # it informs us about fixing the files: + assert str(tmpdir.join("file1.py")) in out + assert str(tmpdir.join("file2.py")) in out @pytest.mark.parametrize('enabled', (False, True)) @@ -2730,12 +2731,15 @@ def test_safety_excludes(tmpdir, enabled): tmpdir.mkdir("lib").mkdir("python3.7").join("importantsystemlibrary.py").write("# ...") config = dict(settings.default.copy(), safety_excludes=enabled) skipped = [] + codes = [str(tmpdir)], + main.iter_source_code(codes, config, skipped) file_names = set(os.path.relpath(f, str(tmpdir)) for f in main.iter_source_code([str(tmpdir)], config, skipped)) if enabled: assert file_names == {'victim.py'} assert len(skipped) == 2 else: - assert file_names == {'.tox/verysafe.py', 'lib/python3.7/importantsystemlibrary.py', 'victim.py'} + assert file_names == {os.sep.join(('.tox', 'verysafe.py')), + os.sep.join(('lib', 'python3.7', 'importantsystemlibrary.py')), 'victim.py'} assert not skipped |