def test_integration_non_isort_cfg(filename, tmpdir): with tmpdir.as_cwd(): tmpdir.join(filename).write('[isort]\nknown_third_party = cfgv\n') tmpdir.join('f.py').write('import pre_commit\nimport cfgv\n') _make_git() assert main(()) == 1 expected = '[isort]\nknown_third_party = cfgv,pre_commit\n' assert tmpdir.join(filename).read() == expected
def test_integration_editorconfig(tmpdir): with tmpdir.as_cwd(): tmpdir.join('.editorconfig').write('[*.py]\nknown_third_party=cfgv\n') tmpdir.join('f.py').write('import pre_commit\nimport cfgv\n') _make_git() assert main(()) == 1 expected = '[*.py]\nknown_third_party=cfgv,pre_commit\n' assert tmpdir.join('.editorconfig').read() == expected
def test_returns_zero_no_changes_pyproject_toml(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('pyproject.toml') cfg.write('[settings]\nknown_third_party=["cfgv"]\n') tmpdir.join('f.py').write('import cfgv\n') _make_git() assert main(()) == 0 assert cfg.read() == '[settings]\nknown_third_party=["cfgv"]\n'
def test_returns_zero_no_changes(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('.isort.cfg') cfg.write('[settings]\nknown_third_party=cfgv\n') tmpdir.join('f.py').write('import cfgv\n') _make_git() assert main(()) == 0 assert cfg.read() == '[settings]\nknown_third_party=cfgv\n'
def test_exclude(tmpdir): with tmpdir.as_cwd(): tmpdir.join('f.py').write('import cfgv\n') tmpdir.join('g.py').write('syntax error') _make_git() assert main(('--exclude', '^g.py$')) == 1 expected = '[settings]\nknown_third_party = cfgv\n' assert tmpdir.join('.isort.cfg').read() == expected
def test_integration_isort_cfg(tmpdir): with tmpdir.as_cwd(): tmpdir.join('.isort.cfg').write('[settings]\nknown_third_party=\n') tmpdir.join('f.py').write('import pre_commit\nimport cfgv\n') tmpdir.join('g.py').write('import f\nimport os\n') _make_git() assert main(()) == 1 expected = '[settings]\nknown_third_party=cfgv,pre_commit\n' assert tmpdir.join('.isort.cfg').read() == expected
def test_integration_settings_path(tmpdir): with tmpdir.as_cwd(): src = tmpdir.join('src').ensure_dir() src.join('f.py').write('import cfgv') _make_git() assert main(('--settings-path', 'cfg')) == 1 expected = '[settings]\nknown_third_party = cfgv\n' assert tmpdir.join('cfg/.isort.cfg').read() == expected assert not tmpdir.join('.isort.cfg').exists()
def test_integration_src_layout(tmpdir): with tmpdir.as_cwd(): src = tmpdir.join('src').ensure_dir() src.join('f.py').write('import cfgv') src.join('g.py').write('import f') _make_git() assert main(('--application-directories', 'src')) == 1 expected = '[settings]\nknown_third_party = cfgv\n' assert tmpdir.join('.isort.cfg').read() == expected
def test_integration_multiple_config_files_exist(tmpdir): with tmpdir.as_cwd(): tmpdir.join('setup.cfg').write('[bdist_wheel]\nuniversal = 1\n') tmpdir.join('tox.ini').write('[isort]\nknown_third_party=\n') tmpdir.join('f.py').write('import cfgv') _make_git() assert main(()) == 1 expected = '[isort]\nknown_third_party=cfgv\n' assert tmpdir.join('tox.ini').read() == expected
def test_integration_pyproject_toml(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('pyproject.toml') cfg.write('[tool.isort]\nknown_third_party = ["cfgv"]\n') tmpdir.join('f.py').write('import pre_commit\nimport cfgv\n') _make_git() assert main(()) == 1 expected = '[tool.isort]\nknown_third_party = ["cfgv", "pre_commit"]\n' assert cfg.read() == expected
def test_indentation_preserved(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('pyproject.toml') cfg.write_binary(b'[tool.isort]\n\tknown_third_party=\r\n') tmpdir.join('g.py').write('import cfgv\n') _make_git() assert main(()) == 1 expected = b'[tool.isort]\n\tknown_third_party=["cfgv"]\r\n' assert cfg.read_binary() == expected
def test_newlines_preserved(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('.isort.cfg') cfg.write_binary(b'[settings]\nknown_third_party=\r\n') tmpdir.join('g.py').write('import cfgv\n') _make_git() assert main(()) == 1 expected = b'[settings]\nknown_third_party=cfgv\r\n' assert cfg.read_binary() == expected
def test_output_file_changed(tmpdir, capsys): with tmpdir.as_cwd(): cfg = tmpdir.join('.isort.cfg') cfg.write_binary(b'[settings]\nknown_third_party=\r\n') tmpdir.join('g.py').write('import cfgv\n') _make_git() assert main(()) == 1 assert './.isort.cfg updated.\n' == capsys.readouterr().out expected = b'[settings]\nknown_third_party=cfgv\r\n' assert cfg.read_binary() == expected
def test_integration_known_packages(tmpdir): with tmpdir.as_cwd(): cfg = tmpdir.join('.isort.cfg') cfg.write('[settings]\nknown_django=django\nknown_third_party=\n') tmpdir.join('f.py').write('import pre_commit\nimport cfgv\n') tmpdir.join('g.py').write('import f\nimport os\nimport django\n') _make_git() assert main(()) == 1 expected = ('[settings]\n' 'known_django=django\n' 'known_third_party=cfgv,pre_commit\n') assert cfg.read() == expected
def test_removing_file_after_git_add(tmpdir): """regression test for issue #37""" with tmpdir.as_cwd(): tmpdir.join('.isort.cfg').write('[settings]\nknown_third_party=\n') tmpdir.join('f.py').write('import pre_commit\n') tmpdir.join('g.py').write('import cfgv\n') _make_git() tmpdir.join('g.py').remove() assert main(()) == 1 expected = '[settings]\nknown_third_party=pre_commit\n' assert tmpdir.join('.isort.cfg').read() == expected
def test_integration_no_section( tmpdir, initial_filesystem, expected_filesystem, ): with tmpdir.as_cwd(): tmpdir.join('f.py').write('import cfgv') for filename, initial in initial_filesystem: tmpdir.join(filename).write(initial) _make_git() assert main(()) == 1 for filename, expected in expected_filesystem: assert tmpdir.join(filename).read() == expected