summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2021-06-17 01:54:26 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2021-06-17 01:54:26 -0700
commit9bc8c9a91725f6b8f27d8e1c4d97a3377e6ce64f (patch)
tree766b3f8f97cecc9fe571cb9411bbd661d1d455d1 /tests
parentec527fc004b1951757eba31eab5c62463796689c (diff)
downloadisort-9bc8c9a91725f6b8f27d8e1c4d97a3377e6ce64f.tar.gz
Full coverage for isort/api.py
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_isort.py15
-rw-r--r--tests/unit/test_ticketed_features.py16
2 files changed, 30 insertions, 1 deletions
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py
index ec2fd5d6..754d47f6 100644
--- a/tests/unit/test_isort.py
+++ b/tests/unit/test_isort.py
@@ -2198,6 +2198,21 @@ def test_other_file_encodings(tmpdir) -> None:
assert tmp_fname.read_text(encoding) == file_contents
+def test_other_file_encodings_in_place(tmpdir) -> None:
+ """Test to ensure file encoding is respected when overwritten in place."""
+ for encoding in ("latin1", "utf8"):
+ tmp_fname = tmpdir.join(f"test_{encoding}.py")
+ file_contents = f"# coding: {encoding}\n\ns = u'ã'\n"
+ tmp_fname.write_binary(file_contents.encode(encoding))
+ api.sort_file(
+ Path(tmp_fname),
+ file_path=Path(tmp_fname),
+ settings_path=os.getcwd(),
+ overwrite_in_place=True,
+ )
+ assert tmp_fname.read_text(encoding) == file_contents
+
+
def test_encoding_not_in_comment(tmpdir) -> None:
"""Test that 'encoding' not in a comment is ignored"""
tmp_fname = tmpdir.join("test_encoding.py")
diff --git a/tests/unit/test_ticketed_features.py b/tests/unit/test_ticketed_features.py
index 0a4a5e9e..a2970053 100644
--- a/tests/unit/test_ticketed_features.py
+++ b/tests/unit/test_ticketed_features.py
@@ -893,7 +893,6 @@ def test_api_to_allow_custom_diff_and_output_stream_1583(capsys, tmpdir):
to a different stream.
See: https://github.com/PyCQA/isort/issues/1583
"""
-
tmp_file = tmpdir.join("file.py")
tmp_file.write("import b\nimport a\n")
@@ -914,6 +913,21 @@ def test_api_to_allow_custom_diff_and_output_stream_1583(capsys, tmpdir):
isort_output.seek(0)
assert isort_output.read().splitlines() == ["import a", "import b"]
+ # should still work with no diff produced
+ tmp_file2 = tmpdir.join("file2.py")
+ tmp_file2.write("import a\nimport b\n")
+
+ isort_diff2 = StringIO()
+ isort_output2 = StringIO()
+
+ isort.file(tmp_file2, show_diff=isort_diff2, output=isort_output2)
+
+ _, error = capsys.readouterr()
+ assert not error
+
+ isort_diff2.seek(0)
+ assert not isort_diff2.read()
+
def test_autofix_mixed_indent_imports_1575():
"""isort should automatically fix import statements that are sent in