예제 #1
0
def test_bad_encoding():
    # Make conflict between BOM and encoding Cookie.
    # https://docs.python.org/3/library/tokenize.html#tokenize.detect_encoding
    bad_encoding = "\ufeff\n# -*- coding: utf-32 -*-\nbad encoding"

    with reopenable_temp_file(bad_encoding) as tmp_path:
        assert refactor(tmp_path) == ""
예제 #2
0
def test_platform_non_native_linesep(non_native_linesep, source, result):
    with reopenable_temp_file(source, newline=non_native_linesep) as tmp_path:
        unimport.main.main(["--remove", tmp_path.as_posix()])
        with open(tmp_path, encoding="utf-8") as tmp_py_file:
            tmp_py_file.read()
            assert non_native_linesep == tmp_py_file.newlines
        assert result == unimport.utils.read(tmp_path)[0]
예제 #3
0
def test_read_newline_nonnative(non_native_linesep):
    source = "\n".join([
        "import sys",
        "",
        "print(sys.executable)\n",
    ])

    with reopenable_temp_file(source, newline=non_native_linesep) as tmp_path:
        assert (source, "utf-8", non_native_linesep) == utils.read(tmp_path)
예제 #4
0
def test_diff_file():
    with reopenable_temp_file("import os") as tmp_path:
        source = utils.read(tmp_path)[0]
        refactor_result = refactor(tmp_path)
        diff_file = utils.diff(
            source=source,
            refactor_result=refactor_result,
            fromfile=tmp_path,
        )
        diff = (
            f"--- {tmp_path.as_posix()}\n",
            "+++ \n",
            "@@ -1 +0,0 @@\n",
            "-import os",
        )
        assert diff == diff_file
예제 #5
0
def test_read():
    source = "b�se"

    with reopenable_temp_file(source) as tmp_path:
        assert (source, "utf-8", None) == utils.read(tmp_path)
예제 #6
0
def test_refactor_file():
    with reopenable_temp_file("import os") as tmp_path:
        assert refactor(tmp_path) == ""