mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +00:00
Merge branch 'fix_statistics' into 'master'
Fix flake8 --statistics Closes #499 See merge request pycqa/flake8!295
This commit is contained in:
commit
cbffa49a0b
3 changed files with 37 additions and 10 deletions
|
|
@ -337,7 +337,7 @@ class StyleGuideManager(object):
|
|||
self.decider = decider or DecisionEngine(options)
|
||||
self.style_guides = []
|
||||
self.default_style_guide = StyleGuide(
|
||||
options, formatter, decider=decider
|
||||
options, formatter, self.stats, decider=decider
|
||||
)
|
||||
self.style_guides = list(
|
||||
itertools.chain(
|
||||
|
|
@ -436,14 +436,16 @@ class StyleGuideManager(object):
|
|||
class StyleGuide(object):
|
||||
"""Manage a Flake8 user's style guide."""
|
||||
|
||||
def __init__(self, options, formatter, filename=None, decider=None):
|
||||
def __init__(
|
||||
self, options, formatter, stats, filename=None, decider=None
|
||||
):
|
||||
"""Initialize our StyleGuide.
|
||||
|
||||
.. todo:: Add parameter documentation.
|
||||
"""
|
||||
self.options = options
|
||||
self.formatter = formatter
|
||||
self.stats = statistics.Statistics()
|
||||
self.stats = stats
|
||||
self.decider = decider or DecisionEngine(options)
|
||||
self.filename = filename
|
||||
if self.filename:
|
||||
|
|
@ -459,7 +461,9 @@ class StyleGuide(object):
|
|||
filename = filename or self.filename
|
||||
options = copy.deepcopy(self.options)
|
||||
options.ignore.extend(extend_ignore_with or [])
|
||||
return StyleGuide(options, self.formatter, filename=filename)
|
||||
return StyleGuide(
|
||||
options, self.formatter, self.stats, filename=filename
|
||||
)
|
||||
|
||||
@contextlib.contextmanager
|
||||
def processing_file(self, filename):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from flake8.main import application
|
|||
|
||||
|
||||
def test_diff_option(tmpdir, capsys):
|
||||
"""Ensure that FileChecker can handle --diff."""
|
||||
"""Ensure that `flake8 --diff` works."""
|
||||
t_py_contents = '''\
|
||||
import os
|
||||
import sys # unused but not part of diff
|
||||
|
|
@ -41,3 +41,20 @@ index d64ac39..7d943de 100644
|
|||
out, err = capsys.readouterr()
|
||||
assert out == "t.py:8:1: F821 undefined name 'y'\n"
|
||||
assert err == ''
|
||||
|
||||
|
||||
def test_statistics_option(tmpdir, capsys):
|
||||
"""Ensure that `flake8 --statistics` works."""
|
||||
with tmpdir.as_cwd():
|
||||
tmpdir.join('t.py').write('import os\nimport sys\n')
|
||||
|
||||
app = application.Application()
|
||||
app.run(['--statistics', 't.py'])
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert out == '''\
|
||||
t.py:1:1: F401 'os' imported but unused
|
||||
t.py:2:1: F401 'sys' imported but unused
|
||||
2 F401 'os' imported but unused
|
||||
'''
|
||||
assert err == ''
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import optparse
|
|||
import mock
|
||||
import pytest
|
||||
|
||||
from flake8 import statistics
|
||||
from flake8 import style_guide
|
||||
from flake8 import utils
|
||||
from flake8.formatting import base
|
||||
|
|
@ -24,8 +25,11 @@ def create_options(**kwargs):
|
|||
def test_handle_error_does_not_raise_type_errors():
|
||||
"""Verify that we handle our inputs better."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
guide = style_guide.StyleGuide(create_options(select=['T111'], ignore=[]),
|
||||
formatter=formatter)
|
||||
guide = style_guide.StyleGuide(
|
||||
create_options(select=['T111'], ignore=[]),
|
||||
formatter=formatter,
|
||||
stats=statistics.Statistics(),
|
||||
)
|
||||
|
||||
assert 1 == guide.handle_error(
|
||||
'T111', 'file.py', 1, None, 'error found', 'a = 1'
|
||||
|
|
@ -60,9 +64,11 @@ def test_style_guide_applies_to(style_guide_file, filename, expected):
|
|||
"""Verify that we match a file to its style guide."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
options = create_options()
|
||||
guide = style_guide.StyleGuide(options,
|
||||
formatter=formatter,
|
||||
filename=style_guide_file)
|
||||
guide = style_guide.StyleGuide(
|
||||
options,
|
||||
formatter=formatter,
|
||||
stats=statistics.Statistics(),
|
||||
filename=style_guide_file)
|
||||
assert guide.applies_to(filename) is expected
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue