Skip to content

Commit

Permalink
Add test cases for #960
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Jul 22, 2020
1 parent 943262a commit 09cf66c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
4 changes: 3 additions & 1 deletion isort/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ def is_skipped(self, file_path: Path) -> bool:
os_path = str(file_path)

if self.skip_gitignore:
result = subprocess.run(["git", "check-ignore", "--quiet", os_path]) # nosec
result = subprocess.run( # nosec
["git", "-C", file_path.resolve().parent, "check-ignore", "--quiet", os_path]
)
if result.returncode == 0:
return True

Expand Down
15 changes: 15 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import subprocess
import sys
from datetime import datetime
from io import BytesIO, TextIOWrapper
Expand Down Expand Up @@ -227,6 +228,20 @@ def test_main(capsys, tmpdir):
# without filter options passed in should successfully sort files
main.main([str(python_file), str(should_skip), "--verbose", "--atomic"])

# should respect gitignore if requested.
out, error = capsys.readouterr() # clear sysoutput before tests
subprocess.run(["git", "init", str(tmpdir)])
main.main([str(python_file), "--skip-gitignore", "--filter-files"])
out, error = capsys.readouterr()
assert "Skipped" not in out
tmpdir.join(".gitignore").write("has_imports.py")
main.main([str(python_file)])
out, error = capsys.readouterr()
assert "Skipped" not in out
main.main([str(python_file), "--skip-gitignore", "--filter-files"])
out, error = capsys.readouterr()
assert "Skipped" in out


def test_isort_command():
"""Ensure ISortCommand got registered, otherwise setuptools error must have occured"""
Expand Down

0 comments on commit 09cf66c

Please sign in to comment.