extend black formatting to tests as well

This commit is contained in:
Anthony Sottile 2021-04-18 09:17:48 -07:00
parent a7174759e9
commit af1668bf04
45 changed files with 1644 additions and 1307 deletions

View file

@ -4,19 +4,19 @@ import pytest
from flake8 import statistics as stats
from flake8 import style_guide
DEFAULT_ERROR_CODE = 'E100'
DEFAULT_FILENAME = 'file.py'
DEFAULT_TEXT = 'Default text'
DEFAULT_ERROR_CODE = "E100"
DEFAULT_FILENAME = "file.py"
DEFAULT_TEXT = "Default text"
def make_error(**kwargs):
"""Create errors with a bunch of default values."""
return style_guide.Violation(
code=kwargs.pop('code', DEFAULT_ERROR_CODE),
filename=kwargs.pop('filename', DEFAULT_FILENAME),
line_number=kwargs.pop('line_number', 1),
column_number=kwargs.pop('column_number', 1),
text=kwargs.pop('text', DEFAULT_TEXT),
code=kwargs.pop("code", DEFAULT_ERROR_CODE),
filename=kwargs.pop("filename", DEFAULT_FILENAME),
line_number=kwargs.pop("line_number", 1),
column_number=kwargs.pop("column_number", 1),
text=kwargs.pop("text", DEFAULT_TEXT),
physical_line=None,
)
@ -29,26 +29,29 @@ def test_key_creation():
assert key.code == DEFAULT_ERROR_CODE
@pytest.mark.parametrize('code, filename, args, expected_result', [
# Error prefix matches
('E123', 'file000.py', ('E', None), True),
('E123', 'file000.py', ('E1', None), True),
('E123', 'file000.py', ('E12', None), True),
('E123', 'file000.py', ('E123', None), True),
# Error prefix and filename match
('E123', 'file000.py', ('E', 'file000.py'), True),
('E123', 'file000.py', ('E1', 'file000.py'), True),
('E123', 'file000.py', ('E12', 'file000.py'), True),
('E123', 'file000.py', ('E123', 'file000.py'), True),
# Error prefix does not match
('E123', 'file000.py', ('W', None), False),
# Error prefix matches but filename does not
('E123', 'file000.py', ('E', 'file001.py'), False),
# Error prefix does not match but filename does
('E123', 'file000.py', ('W', 'file000.py'), False),
# Neither error prefix match nor filename
('E123', 'file000.py', ('W', 'file001.py'), False),
])
@pytest.mark.parametrize(
"code, filename, args, expected_result",
[
# Error prefix matches
("E123", "file000.py", ("E", None), True),
("E123", "file000.py", ("E1", None), True),
("E123", "file000.py", ("E12", None), True),
("E123", "file000.py", ("E123", None), True),
# Error prefix and filename match
("E123", "file000.py", ("E", "file000.py"), True),
("E123", "file000.py", ("E1", "file000.py"), True),
("E123", "file000.py", ("E12", "file000.py"), True),
("E123", "file000.py", ("E123", "file000.py"), True),
# Error prefix does not match
("E123", "file000.py", ("W", None), False),
# Error prefix matches but filename does not
("E123", "file000.py", ("E", "file001.py"), False),
# Error prefix does not match but filename does
("E123", "file000.py", ("W", "file000.py"), False),
# Neither error prefix match nor filename
("E123", "file000.py", ("W", "file001.py"), False),
],
)
def test_key_matching(code, filename, args, expected_result):
"""Verify Key#matches behaves as we expect with fthe above input."""
key = stats.Key.create_from(make_error(code=code, filename=filename))
@ -75,7 +78,7 @@ def test_statistic_increment():
def test_recording_statistics():
"""Verify that we appropriately create a new Statistic and store it."""
aggregator = stats.Statistics()
assert list(aggregator.statistics_for('E')) == []
assert list(aggregator.statistics_for("E")) == []
aggregator.record(make_error())
storage = aggregator._store
for key, value in storage.items():
@ -88,9 +91,9 @@ def test_recording_statistics():
def test_statistics_for_single_record():
"""Show we can retrieve the only statistic recorded."""
aggregator = stats.Statistics()
assert list(aggregator.statistics_for('E')) == []
assert list(aggregator.statistics_for("E")) == []
aggregator.record(make_error())
statistics = list(aggregator.statistics_for('E'))
statistics = list(aggregator.statistics_for("E"))
assert len(statistics) == 1
assert isinstance(statistics[0], stats.Statistic)
@ -98,11 +101,11 @@ def test_statistics_for_single_record():
def test_statistics_for_filters_by_filename():
"""Show we can retrieve the only statistic recorded."""
aggregator = stats.Statistics()
assert list(aggregator.statistics_for('E')) == []
assert list(aggregator.statistics_for("E")) == []
aggregator.record(make_error())
aggregator.record(make_error(filename='example.py'))
aggregator.record(make_error(filename="example.py"))
statistics = list(aggregator.statistics_for('E', DEFAULT_FILENAME))
statistics = list(aggregator.statistics_for("E", DEFAULT_FILENAME))
assert len(statistics) == 1
assert isinstance(statistics[0], stats.Statistic)
@ -111,11 +114,11 @@ def test_statistic_for_retrieves_more_than_one_value():
"""Show this works for more than a couple statistic values."""
aggregator = stats.Statistics()
for i in range(50):
aggregator.record(make_error(code=f'E1{i:02d}'))
aggregator.record(make_error(code=f'W2{i:02d}'))
aggregator.record(make_error(code=f"E1{i:02d}"))
aggregator.record(make_error(code=f"W2{i:02d}"))
statistics = list(aggregator.statistics_for('E'))
statistics = list(aggregator.statistics_for("E"))
assert len(statistics) == 50
statistics = list(aggregator.statistics_for('W22'))
statistics = list(aggregator.statistics_for("W22"))
assert len(statistics) == 10