summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorTimothy Crosley <timothy.crosley@gmail.com>2021-06-20 23:46:18 -0700
committerTimothy Crosley <timothy.crosley@gmail.com>2021-06-20 23:46:18 -0700
commit9bf7b356eeebc7b74322a33091dea217271d3041 (patch)
tree21af681883b7f8182538794f48bff95ab2e5eb3a /tests/unit
parent170583575dc8a9f1c50cbd2bb8eb79df1a98fb82 (diff)
downloadisort-9bf7b356eeebc7b74322a33091dea217271d3041.tar.gz
Address linting errors
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_exceptions.py28
-rw-r--r--tests/unit/test_isort.py63
-rw-r--r--tests/unit/test_main.py16
-rw-r--r--tests/unit/test_regressions.py4
-rw-r--r--tests/unit/test_settings.py2
5 files changed, 65 insertions, 48 deletions
diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py
index 81610557..d3a063a7 100644
--- a/tests/unit/test_exceptions.py
+++ b/tests/unit/test_exceptions.py
@@ -11,7 +11,9 @@ class TestISortError:
class TestExistingSyntaxErrors(TestISortError):
def setup_class(self):
- self.instance: exceptions.ExistingSyntaxErrors = exceptions.ExistingSyntaxErrors("file_path")
+ self.instance: exceptions.ExistingSyntaxErrors = exceptions.ExistingSyntaxErrors(
+ "file_path"
+ )
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -19,7 +21,9 @@ class TestExistingSyntaxErrors(TestISortError):
class TestIntroducedSyntaxErrors(TestISortError):
def setup_class(self):
- self.instance: exceptions.IntroducedSyntaxErrors = exceptions.IntroducedSyntaxErrors("file_path")
+ self.instance: exceptions.IntroducedSyntaxErrors = exceptions.IntroducedSyntaxErrors(
+ "file_path"
+ )
def test_variables(self):
assert self.instance.file_path == "file_path"
@@ -60,7 +64,9 @@ class TestProfileDoesNotExist(TestISortError):
class TestSortingFunctionDoesNotExist(TestISortError):
def setup_class(self):
- self.instance: exceptions.SortingFunctionDoesNotExist = exceptions.SortingFunctionDoesNotExist("round", ["square", "peg"])
+ self.instance: exceptions.SortingFunctionDoesNotExist = (
+ exceptions.SortingFunctionDoesNotExist("round", ["square", "peg"])
+ )
def test_variables(self):
assert self.instance.sort_order == "round"
@@ -69,7 +75,9 @@ class TestSortingFunctionDoesNotExist(TestISortError):
class TestLiteralParsingFailure(TestISortError):
def setup_class(self):
- self.instance: exceptions.LiteralParsingFailure = exceptions.LiteralParsingFailure("x = [", SyntaxError)
+ self.instance: exceptions.LiteralParsingFailure = exceptions.LiteralParsingFailure(
+ "x = [", SyntaxError
+ )
def test_variables(self):
assert self.instance.code == "x = ["
@@ -78,7 +86,9 @@ class TestLiteralParsingFailure(TestISortError):
class TestLiteralSortTypeMismatch(TestISortError):
def setup_class(self):
- self.instance: exceptions.LiteralSortTypeMismatch = exceptions.LiteralSortTypeMismatch(tuple, list)
+ self.instance: exceptions.LiteralSortTypeMismatch = exceptions.LiteralSortTypeMismatch(
+ tuple, list
+ )
def test_variables(self):
assert self.instance.kind == tuple
@@ -87,7 +97,9 @@ class TestLiteralSortTypeMismatch(TestISortError):
class TestAssignmentsFormatMismatch(TestISortError):
def setup_class(self):
- self.instance: exceptions.AssignmentsFormatMismatch = exceptions.AssignmentsFormatMismatch("print x")
+ self.instance: exceptions.AssignmentsFormatMismatch = exceptions.AssignmentsFormatMismatch(
+ "print x"
+ )
def test_variables(self):
assert self.instance.code == "print x"
@@ -95,7 +107,9 @@ class TestAssignmentsFormatMismatch(TestISortError):
class TestUnsupportedSettings(TestISortError):
def setup_class(self):
- self.instance: exceptions.UnsupportedSettings = exceptions.UnsupportedSettings({"apply": {"value": "true", "source": "/"}})
+ self.instance: exceptions.UnsupportedSettings = exceptions.UnsupportedSettings(
+ {"apply": {"value": "true", "source": "/"}}
+ )
def test_variables(self):
assert self.instance.unsupported_settings == {"apply": {"value": "true", "source": "/"}}
diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py
index 63a59f9a..526a7b8a 100644
--- a/tests/unit/test_isort.py
+++ b/tests/unit/test_isort.py
@@ -9,7 +9,7 @@ import subprocess
import sys
from io import StringIO
from tempfile import NamedTemporaryFile
-from typing import Any, Dict, Iterator, List, Set, Tuple, TYPE_CHECKING
+from typing import Any, Dict, Iterator, List, Set, Tuple, TYPE_CHECKING
import py
import pytest
@@ -231,10 +231,13 @@ def test_line_length() -> None:
)
with pytest.raises(ValueError):
test_output = isort.code(code=REALLY_LONG_IMPORT, line_length=80, wrap_length=99)
- assert isort.code(REALLY_LONG_IMPORT, line_length=100, wrap_length=99) == (
-"""from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12,
+ assert (
+ isort.code(REALLY_LONG_IMPORT, line_length=100, wrap_length=99)
+ == """
+from third_party import (lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12,
lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22)
-""")
+""".lstrip()
+ )
# Test Case described in issue #1015
test_output = isort.code(
@@ -1280,42 +1283,44 @@ import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
"""
- assert isort.code(code=test_input, force_sort_within_sections=True, length_sort=True) == test_input
+ assert (
+ isort.code(code=test_input, force_sort_within_sections=True, length_sort=True) == test_input
+ )
def test_titled_imports() -> None:
"""Tests setting custom titled/commented import sections."""
test_input = (
- "import sys\n"
- "import unicodedata\n"
- "import statistics\n"
- "import os\n"
- "import myproject.test\n"
- "import django.settings"
+ "import sys\n"
+ "import unicodedata\n"
+ "import statistics\n"
+ "import os\n"
+ "import myproject.test\n"
+ "import django.settings"
)
test_output = isort.code(
- code=test_input,
- known_first_party=["myproject"],
- import_heading_stdlib="Standard Library",
- import_heading_firstparty="My Stuff",
+ code=test_input,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
)
assert test_output == (
- "# Standard Library\n"
- "import os\n"
- "import statistics\n"
- "import sys\n"
- "import unicodedata\n"
- "\n"
- "import django.settings\n"
- "\n"
- "# My Stuff\n"
- "import myproject.test\n"
+ "# Standard Library\n"
+ "import os\n"
+ "import statistics\n"
+ "import sys\n"
+ "import unicodedata\n"
+ "\n"
+ "import django.settings\n"
+ "\n"
+ "# My Stuff\n"
+ "import myproject.test\n"
)
test_second_run = isort.code(
- code=test_output,
- known_first_party=["myproject"],
- import_heading_stdlib="Standard Library",
- import_heading_firstparty="My Stuff",
+ code=test_output,
+ known_first_party=["myproject"],
+ import_heading_stdlib="Standard Library",
+ import_heading_firstparty="My Stuff",
)
assert test_second_run == test_output
diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py
index e7697643..9039787c 100644
--- a/tests/unit/test_main.py
+++ b/tests/unit/test_main.py
@@ -21,6 +21,7 @@ if TYPE_CHECKING:
else:
from isort.wrap_modes import WrapModes
+
@given(
file_name=st.text(),
config=st.builds(Config),
@@ -41,15 +42,15 @@ def test_fuzz_sort_imports(file_name, config, check, ask_to_apply, write_to_stdo
def test_sort_imports(tmpdir):
tmp_file = tmpdir.join("file.py")
tmp_file.write("import os, sys\n")
- assert main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
+ assert main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore # noqa
main.sort_imports(str(tmp_file), DEFAULT_CONFIG)
- assert not main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
+ assert not main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore # noqa
skip_config = Config(skip=["file.py"])
assert main.sort_imports( # type: ignore
str(tmp_file), config=skip_config, check=True, disregard_skip=False
- ).skippedg
- assert main.sort_imports(str(tmp_file), config=skip_config, disregard_skip=False).skipped # type: ignore
+ ).skipped
+ assert main.sort_imports(str(tmp_file), config=skip_config, disregard_skip=False).skipped # type: ignore # noqa
def test_sort_imports_error_handling(tmpdir, mocker, capsys):
@@ -57,7 +58,7 @@ def test_sort_imports_error_handling(tmpdir, mocker, capsys):
tmp_file.write("import os, sys\n")
mocker.patch("isort.core.process").side_effect = IndexError("Example unhandled exception")
with pytest.raises(IndexError):
- main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore
+ main.sort_imports(str(tmp_file), DEFAULT_CONFIG, check=True).incorrectly_sorted # type: ignore # noqa
out, error = capsys.readouterr()
assert "Unrecoverable exception thrown when parsing" in error
@@ -347,11 +348,6 @@ import b
main.main(["-sp", str(config_file), "-"], stdin=input_content)
-def test_isort_command():
- """Ensure ISortCommand got registered, otherwise setuptools error must have occurred"""
- assert main.ISortCommand # type: ignore
-
-
def test_isort_filename_overrides(tmpdir, capsys):
"""Tests isorts available approaches for overriding filename and extension based behavior"""
input_text = """
diff --git a/tests/unit/test_regressions.py b/tests/unit/test_regressions.py
index a7933005..388aa8d3 100644
--- a/tests/unit/test_regressions.py
+++ b/tests/unit/test_regressions.py
@@ -233,7 +233,9 @@ def test_ensure_sre_parse_is_identified_as_stdlib_issue_1304():
"""Ensure sre_parse is idenified as STDLIB.
See: https://github.com/pycqa/isort/issues/1304.
"""
- assert isort.place_module("sre_parse") == isort.place_module("sre") == isort.settings.STDLIB # type: ignore
+ assert (
+ isort.place_module("sre_parse") == isort.place_module("sre") == isort.settings.STDLIB # type: ignore # noqa
+ )
def test_add_imports_shouldnt_move_lower_comments_issue_1300():
diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py
index ad0f3ae4..72b473d7 100644
--- a/tests/unit/test_settings.py
+++ b/tests/unit/test_settings.py
@@ -93,7 +93,7 @@ class TestConfig:
assert Config(src_paths=src_paths * 2).src_paths == tuple(src_full_paths)
def test_deprecated_multi_line_output(self):
- assert Config(multi_line_output=6).multi_line_output == WrapModes.VERTICAL_GRID_GROUPED # type: ignore
+ assert Config(multi_line_output=6).multi_line_output == WrapModes.VERTICAL_GRID_GROUPED # type: ignore # noqa
def test_as_list():