summaryrefslogtreecommitdiff
path: root/tests/unit/test_main.py
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2020-11-12 23:52:28 -0800
committerTimothy Crosley <timothy.crosley@gmail.com>2020-11-12 23:52:28 -0800
commitb04ff9fb8f4098bc4498d60a05e19c711a0524d9 (patch)
treef133f85987fa354ed26d20bfa4629994f3fedfea /tests/unit/test_main.py
parent66ba8c6e43b723e6748e30149cfb640c0e42bd6f (diff)
downloadisort-b04ff9fb8f4098bc4498d60a05e19c711a0524d9.tar.gz
Implemented #1596: Provide ways for extension formatting and file paths to be specified when using streaming input from CLI.
Diffstat (limited to 'tests/unit/test_main.py')
-rw-r--r--tests/unit/test_main.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py
index 70eafb3a..08f27463 100644
--- a/tests/unit/test_main.py
+++ b/tests/unit/test_main.py
@@ -348,6 +348,66 @@ def test_isort_command():
assert main.ISortCommand
+def test_isort_filename_overrides(tmpdir, capsys):
+ """Tests isorts available approaches for overriding filename and extension based behavior"""
+ input_text = """
+import b
+import a
+
+def function():
+ pass
+"""
+
+ def build_input_content():
+ return UnseekableTextIOWrapper(BytesIO(input_text.encode("utf8")))
+
+ main.main(["-"], stdin=build_input_content())
+ out, error = capsys.readouterr()
+ assert not error
+ assert out == (
+ """
+import a
+import b
+
+
+def function():
+ pass
+"""
+ )
+
+ main.main(["-", "--ext-format", "pyi"], stdin=build_input_content())
+ out, error = capsys.readouterr()
+ assert not error
+ assert out == (
+ """
+import a
+import b
+
+def function():
+ pass
+"""
+ )
+
+ tmp_file = tmpdir.join("tmp.pyi")
+ tmp_file.write_text(input_text, encoding="utf8")
+ main.main(["-", "--filename", str(tmp_file)], stdin=build_input_content())
+ out, error = capsys.readouterr()
+ assert not error
+ assert out == (
+ """
+import a
+import b
+
+def function():
+ pass
+"""
+ )
+
+ # setting a filename override when file is passed in as non-stream is not supported.
+ with pytest.raises(SystemExit):
+ main.main([str(tmp_file), "--filename", str(tmp_file)], stdin=build_input_content())
+
+
def test_isort_with_stdin(capsys):
# ensures that isort sorts stdin without any flags