break type checking cycles

This commit is contained in:
Anthony Sottile 2022-01-05 13:36:22 -05:00
parent f6267dd4d7
commit fa4c31fb97
10 changed files with 142 additions and 150 deletions

View file

@ -5,9 +5,9 @@ from unittest import mock
import pytest
from flake8 import style_guide
from flake8.formatting import _windows_color
from flake8.formatting import base
from flake8.violation import Violation
def options(**kwargs):
@ -48,7 +48,7 @@ def test_format_needs_to_be_implemented():
formatter = base.BaseFormatter(options())
with pytest.raises(NotImplementedError):
formatter.format(
style_guide.Violation("A000", "file.py", 1, 1, "error text", None)
Violation("A000", "file.py", 1, 1, "error text", None)
)
@ -57,9 +57,7 @@ def test_show_source_returns_nothing_when_not_showing_source():
formatter = base.BaseFormatter(options(show_source=False))
assert (
formatter.show_source(
style_guide.Violation(
"A000", "file.py", 1, 1, "error text", "line"
)
Violation("A000", "file.py", 1, 1, "error text", "line")
)
== ""
)
@ -70,7 +68,7 @@ def test_show_source_returns_nothing_when_there_is_source():
formatter = base.BaseFormatter(options(show_source=True))
assert (
formatter.show_source(
style_guide.Violation("A000", "file.py", 1, 1, "error text", None)
Violation("A000", "file.py", 1, 1, "error text", None)
)
== ""
)
@ -99,7 +97,7 @@ def test_show_source_returns_nothing_when_there_is_source():
def test_show_source_updates_physical_line_appropriately(line1, line2, column):
"""Ensure the error column is appropriately indicated."""
formatter = base.BaseFormatter(options(show_source=True))
error = style_guide.Violation("A000", "file.py", 1, column, "error", line1)
error = Violation("A000", "file.py", 1, column, "error", line1)
output = formatter.show_source(error)
assert output == line1 + line2
@ -208,7 +206,7 @@ def test_handle_formats_the_error():
"""Verify that a formatter will call format from handle."""
formatter = FormatFormatter(options(show_source=False))
filemock = formatter.output_fd = mock.Mock()
error = style_guide.Violation(
error = Violation(
code="A001",
filename="example.py",
line_number=1,

View file

@ -1,8 +1,8 @@
"""Tests for the FilenameOnly formatter object."""
import argparse
from flake8 import style_guide
from flake8.formatting import default
from flake8.violation import Violation
def options(**kwargs):
@ -18,16 +18,14 @@ def test_caches_filenames_already_printed():
formatter = default.FilenameOnly(options())
assert formatter.filenames_already_printed == set()
formatter.format(
style_guide.Violation("code", "file.py", 1, 1, "text", "l")
)
formatter.format(Violation("code", "file.py", 1, 1, "text", "l"))
assert formatter.filenames_already_printed == {"file.py"}
def test_only_returns_a_string_once_from_format():
"""Verify format ignores the second error with the same filename."""
formatter = default.FilenameOnly(options())
error = style_guide.Violation("code", "file.py", 1, 1, "text", "1")
error = Violation("code", "file.py", 1, 1, "text", "1")
assert formatter.format(error) == "file.py"
assert formatter.format(error) is None
@ -36,6 +34,6 @@ def test_only_returns_a_string_once_from_format():
def test_show_source_returns_nothing():
"""Verify show_source returns nothing."""
formatter = default.FilenameOnly(options())
error = style_guide.Violation("code", "file.py", 1, 1, "text", "1")
error = Violation("code", "file.py", 1, 1, "text", "1")
assert formatter.show_source(error) is None

View file

@ -1,8 +1,8 @@
"""Tests for the Nothing formatter obbject."""
import argparse
from flake8 import style_guide
from flake8.formatting import default
from flake8.violation import Violation
def options(**kwargs):
@ -16,7 +16,7 @@ def options(**kwargs):
def test_format_returns_nothing():
"""Verify Nothing.format returns None."""
formatter = default.Nothing(options())
error = style_guide.Violation("code", "file.py", 1, 1, "text", "1")
error = Violation("code", "file.py", 1, 1, "text", "1")
assert formatter.format(error) is None
@ -24,6 +24,6 @@ def test_format_returns_nothing():
def test_show_source_returns_nothing():
"""Verify Nothing.show_source returns None."""
formatter = default.Nothing(options())
error = style_guide.Violation("code", "file.py", 1, 1, "text", "1")
error = Violation("code", "file.py", 1, 1, "text", "1")
assert formatter.show_source(error) is None

View file

@ -2,7 +2,7 @@
import pytest
from flake8 import statistics as stats
from flake8 import style_guide
from flake8.violation import Violation
DEFAULT_ERROR_CODE = "E100"
DEFAULT_FILENAME = "file.py"
@ -16,7 +16,7 @@ def make_error(**kwargs):
kwargs.setdefault("line_number", 1)
kwargs.setdefault("column_number", 1)
kwargs.setdefault("text", DEFAULT_TEXT)
return style_guide.Violation(**kwargs, physical_line=None)
return Violation(**kwargs, physical_line=None)
def test_key_creation():

View file

@ -1,9 +1,9 @@
"""Tests for the flake8.style_guide.Violation class."""
"""Tests for the flake8.violation.Violation class."""
from unittest import mock
import pytest
from flake8 import style_guide
from flake8.violation import Violation
@pytest.mark.parametrize(
@ -33,9 +33,7 @@ from flake8 import style_guide
)
def test_is_inline_ignored(error_code, physical_line, expected_result):
"""Verify that we detect inline usage of ``# noqa``."""
error = style_guide.Violation(
error_code, "filename.py", 1, 1, "error text", None
)
error = Violation(error_code, "filename.py", 1, 1, "error text", None)
# We want `None` to be passed as the physical line so we actually use our
# monkey-patched linecache.getline value.
@ -45,9 +43,7 @@ def test_is_inline_ignored(error_code, physical_line, expected_result):
def test_disable_is_inline_ignored():
"""Verify that is_inline_ignored exits immediately if disabling NoQA."""
error = style_guide.Violation(
"E121", "filename.py", 1, 1, "error text", "line"
)
error = Violation("E121", "filename.py", 1, 1, "error text", "line")
with mock.patch("linecache.getline") as getline:
assert error.is_inline_ignored(True) is False
@ -67,13 +63,8 @@ def test_disable_is_inline_ignored():
)
def test_violation_is_in_diff(violation_file, violation_line, diff, expected):
"""Verify that we find violations within a diff."""
violation = style_guide.Violation(
"E001",
violation_file,
violation_line,
1,
"warning",
"line",
violation = Violation(
"E001", violation_file, violation_line, 1, "warning", "line"
)
assert violation.is_in(diff) is expected