def test_diff_stream() -> None: output = StringIO() assert api.sort_stream(StringIO("import b\nimport a\n"), output, show_diff=True) output.seek(0) assert "import a\n import b\n" in output.read()
def test_isort_literals_issue_1358(): assert ( isort.code( """ import x import a # isort: list __all__ = ["b", "a", "b"] # isort: unique-list __all__ = ["b", "a", "b"] # isort: tuple __all__ = ("b", "a", "b") # isort: unique-tuple __all__ = ("b", "a", "b") # isort: set __all__ = {"b", "a", "b"} def method(): # isort: list x = ["b", "a"] # isort: dict y = {"z": "z", "b": "b", "b": "c"}""" ) == """ import a import x # isort: list __all__ = ['a', 'b', 'b'] # isort: unique-list __all__ = ['a', 'b'] # isort: tuple __all__ = ('a', 'b', 'b') # isort: unique-tuple __all__ = ('a', 'b') # isort: set __all__ = {'a', 'b'} def method(): # isort: list x = ['a', 'b'] # isort: dict y = {'b': 'c', 'z': 'z'}""" ) assert ( isort.code( """ import x import a # isort: list __all__ = ["b", "a", "b"] # isort: unique-list __all__ = ["b", "a", "b"] # isort: tuple __all__ = ("b", "a", "b") # isort: unique-tuple __all__ = ("b", "a", "b") # isort: set __all__ = {"b", "a", "b"} def method(): # isort: list x = ["b", "a"] # isort: assignments d = 1 b = 2 a = 3 # isort: dict y = {"z": "z", "b": "b", "b": "c"}""", formatter="example", ) == """ import a import x # isort: list __all__ = ["a", "b", "b"] # isort: unique-list __all__ = ["a", "b"] # isort: tuple __all__ = ("a", "b", "b") # isort: unique-tuple __all__ = ("a", "b") # isort: set __all__ = {"a", "b"} def method(): # isort: list x = ["a", "b"] # isort: assignments a = 3 b = 2 d = 1 # isort: dict y = {"b": "c", "z": "z"}""" ) assert api.sort_stream( input_stream=StringIO( """ import a import x # isort: list __all__ = ["b", "a", "b"] # isort: unique-list __all__ = ["b", "a", "b"] # isort: tuple __all__ = ("b", "a", "b") # isort: unique-tuple __all__ = ("b", "a", "b") # isort: set __all__ = {"b", "a", "b"} def method(): # isort: list x = ["b", "a"] # isort: assignments d = 1 b = 2 a = 3 # isort: dict y = {"z": "z", "b": "b", "b": "c"}""", ), output_stream=StringIO(), )