diff options
| author | anirudnits <aniruddha97bhatt@gmail.com> | 2020-10-10 20:30:40 +0530 |
|---|---|---|
| committer | anirudnits <aniruddha97bhatt@gmail.com> | 2020-10-10 20:30:40 +0530 |
| commit | e6ec382eed4432ef2ab43bd5964c83dc45ac615d (patch) | |
| tree | 4f25ae92b3ae1ce4e091b12001f81991d16ec50d /tests | |
| parent | 23897bf091e444c8556fcdec6f77db93653c2b3a (diff) | |
| download | isort-e6ec382eed4432ef2ab43bd5964c83dc45ac615d.tar.gz | |
Added tests for combine_straight_imports option
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_isort.py | 20 | ||||
| -rw-r--r-- | tests/unit/test_main.py | 21 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index c07d655d..703f8dab 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -4893,3 +4893,23 @@ def test_only_sections() -> None: test_input = "from foo import b, a, c\n" assert isort.code(test_input, only_sections=True) == test_input + + +def test_combine_straight_imports() -> None: + """ Tests to ensure that combine_straight_imports works correctly """ + + test_input = ( + "import os\n" "import sys\n" "# this is a comment\n" "import math # inline comment\n" + ) + + assert isort.code(test_input, combine_straight_imports=True) == ( + "# this is a comment\n" "import math os sys # inline comment\n" + ) + + # test to ensure that combine_straight_import works with only_sections + + test_input = "import sys\n" "import a\n" "import math\n" "import os\n" "import b\n" + + assert isort.code(test_input, combine_straight_imports=True, only_sections=True) == ( + "import sys math os\n" "\n" "import a b\n" + ) diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 59e224ae..0fa4cd76 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -77,6 +77,8 @@ def test_parse_args(): assert main.parse_args(["--os"]) == {"only_sections": True} assert main.parse_args(["--om"]) == {"only_modified": True} assert main.parse_args(["--only-modified"]) == {"only_modified": True} + assert main.parse_args(["--csi"]) == {"combine_straight_imports": True} + assert main.parse_args(["--combine-straight-imports"]) == {"combine_straight_imports": True} def test_ascii_art(capsys): @@ -762,6 +764,25 @@ import b assert "else-type place_module for a returned THIRDPARTY" not in out assert "else-type place_module for b returned THIRDPARTY" not in out + # ensures that combine-straight-imports flag works with stdin + input_content = UnseekableTextIOWrapper( + BytesIO( + b""" +import a +import b +""" + ) + ) + + main.main(["-", "--combine-straight-imports"], stdin=input_content) + out, error = capsys.readouterr() + + assert out == ( + """ +import a b +""" + ) + def test_unsupported_encodings(tmpdir, capsys): tmp_file = tmpdir.join("file.py") |
