Skip to content

Commit

Permalink
Merge pull request #1524 from anirudnits/correcting_misplaced_test_fo…
Browse files Browse the repository at this point in the history
…r_only_modified_with_stdin

Corrected a misplaced test and added another.
  • Loading branch information
timothycrosley committed Oct 4, 2020
2 parents 7aa7d1f + 4045450 commit 6c6fb41
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions tests/unit/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,22 @@ def test_isort_with_stdin(capsys):
"""
)

# ensures that only-modified flag works with stdin
input_content = TextIOWrapper(
BytesIO(
b"""
import a
import b
"""
)
)

main.main(["-", "--verbose", "--only-modified"], stdin=input_content)
out, error = capsys.readouterr()

assert "else-type place_module for a returned THIRDPARTY" not in out
assert "else-type place_module for b returned THIRDPARTY" not in out


def test_unsupported_encodings(tmpdir, capsys):
tmp_file = tmpdir.join("file.py")
Expand Down Expand Up @@ -752,22 +768,6 @@ def test_unsupported_encodings(tmpdir, capsys):
main.main([str(tmp_file), str(normal_file), "--verbose"])
out, error = capsys.readouterr()

# ensures that only-modified flag works with stdin
input_content = TextIOWrapper(
BytesIO(
b"""
import a
import b
"""
)
)

main.main(["-", "--verbose", "--only-modified"], stdin=input_content)
out, error = capsys.readouterr()

assert "else-type place_module for a returned THIRDPARTY" not in out
assert "else-type place_module for b returned THIRDPARTY" not in out


def test_only_modified_flag(tmpdir, capsys):
# ensures there is no verbose output for correct files with only-modified flag
Expand Down Expand Up @@ -852,3 +852,20 @@ def test_only_modified_flag(tmpdir, capsys):
)

assert not error

file4 = tmpdir.join("file4.py")
file4.write(
"""
import sys
import os
"""
)

with pytest.raises(SystemExit):
main.main([str(file2), str(file4), "--check-only", "--verbose", "--only-modified"])
out, error = capsys.readouterr()

assert "else-type place_module for sys returned STDLIB" in out
assert "else-type place_module for os returned STDLIB" in out
assert "else-type place_module for math returned STDLIB" not in out
assert "else-type place_module for pandas returned THIRDPARTY" not in out

0 comments on commit 6c6fb41

Please sign in to comment.