Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 14, 2024
1 parent 0a7e341 commit 9d4ee42
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/flake8_json_reporter/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def stop(self):
if self.files_reported_count > 0:
self.write_line("\n")
self.write_line("}\n")
super(DefaultJSON, self).stop() # DefaultJSON.stop would write and extra close brace
super(
DefaultJSON, self
).stop() # DefaultJSON.stop would write and extra close brace

def beginning(self, filename):
"""We're starting a new file."""
Expand Down
54 changes: 36 additions & 18 deletions tests/flake8_json_reporter_test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from argparse import Namespace
import json
from argparse import Namespace

import pytest
from flake8.violation import Violation


from flake8_json_reporter.reporters import DefaultJSON, FormattedJSON
from flake8_json_reporter.reporters import DefaultJSON
from flake8_json_reporter.reporters import FormattedJSON


@pytest.fixture
Expand All @@ -19,15 +19,19 @@ def pretty_formatter():
@pytest.fixture
def default_formatter_output_file(tmp_path):
"""Return a ``DefaultJSON`` instance that captures output to a file"""
options = Namespace(output_file=tmp_path / "output.json", color=False, tee=False)
options = Namespace(
output_file=tmp_path / "output.json", color=False, tee=False
)
formatter = DefaultJSON(options)
return formatter


@pytest.fixture
def pretty_formatter_output_file(tmp_path):
"""Return a ``DefaultJSON`` instance that captures output to a file"""
options = Namespace(output_file=tmp_path / "output.json", color=False, tee=False)
options = Namespace(
output_file=tmp_path / "output.json", color=False, tee=False
)
formatter = FormattedJSON(options)
return formatter

Expand Down Expand Up @@ -83,7 +87,9 @@ def test_pretty_multiple_files_no_violations(capsys, pretty_formatter):
assert stdout == expected


def test_pretty_single_file_single_violation(capsys, pretty_formatter, violation):
def test_pretty_single_file_single_violation(
capsys, pretty_formatter, violation
):
run(pretty_formatter, {"main.py": [violation]})
stdout, _ = capsys.readouterr()
expected = """\
Expand All @@ -103,7 +109,9 @@ def test_pretty_single_file_single_violation(capsys, pretty_formatter, violation
assert stdout == expected


def test_pretty_single_file_multiple_violations(capsys, pretty_formatter, violation):
def test_pretty_single_file_multiple_violations(
capsys, pretty_formatter, violation
):
run(pretty_formatter, {"main.py": [violation] * 3})
stdout, _ = capsys.readouterr()
expected = """\
Expand Down Expand Up @@ -139,7 +147,9 @@ def test_pretty_single_file_multiple_violations(capsys, pretty_formatter, violat
assert stdout == expected


def test_pretty_single_file_single_file_capture(pretty_formatter_output_file, violation):
def test_pretty_single_file_single_file_capture(
pretty_formatter_output_file, violation
):
run(pretty_formatter_output_file, {"main.py": [violation]})
expected = """\
{
Expand All @@ -166,22 +176,30 @@ def test_default_no_files_file_capture(default_formatter_output_file):
assert actual == expected


def test_default_single_file_no_violations_file_capture(default_formatter_output_file):
def test_default_single_file_no_violations_file_capture(
default_formatter_output_file,
):
run(default_formatter_output_file, {"main.py": []})
expected = {"main.py": []}
actual = json.loads(default_formatter_output_file.filename.read_text())
assert actual == expected


def test_default_single_file_violations_file_capture(default_formatter_output_file, violation):
def test_default_single_file_violations_file_capture(
default_formatter_output_file, violation
):
run(default_formatter_output_file, {"main.py": [violation]})
expected = {'main.py': [{'code': 'E222',
'filename': 'main.py',
'line_number': 42,
'column_number': 4,
'text': 'multiple spaces after operator',
'physical_line': 'x = 1'}]}
expected = {
"main.py": [
{
"code": "E222",
"filename": "main.py",
"line_number": 42,
"column_number": 4,
"text": "multiple spaces after operator",
"physical_line": "x = 1",
}
]
}
actual = json.loads(default_formatter_output_file.filename.read_text())
assert actual == expected


0 comments on commit 9d4ee42

Please sign in to comment.