mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 16:34:46 +00:00
Slightly simplify our conditionals
Test warnings by default
This commit is contained in:
parent
59ae3dfec7
commit
a6fc242c5e
5 changed files with 18 additions and 13 deletions
|
|
@ -9,7 +9,7 @@ from flake8 import __version__
|
||||||
from flake8 import callbacks
|
from flake8 import callbacks
|
||||||
from flake8.reporter import (multiprocessing, BaseQReport, FileQReport,
|
from flake8.reporter import (multiprocessing, BaseQReport, FileQReport,
|
||||||
QueueReport)
|
QueueReport)
|
||||||
from flake8.util import OrderedSet, is_windows, is_using_stdin
|
from flake8 import util
|
||||||
|
|
||||||
_flake8_noqa = re.compile(r'\s*# flake8[:=]\s*noqa', re.I).search
|
_flake8_noqa = re.compile(r'\s*# flake8[:=]\s*noqa', re.I).search
|
||||||
|
|
||||||
|
|
@ -18,7 +18,7 @@ EXTRA_EXCLUDE = ['.tox', '.eggs', '*.egg']
|
||||||
|
|
||||||
def _register_extensions():
|
def _register_extensions():
|
||||||
"""Register all the extensions."""
|
"""Register all the extensions."""
|
||||||
extensions = OrderedSet()
|
extensions = util.OrderedSet()
|
||||||
extensions.add(('pep8', pep8.__version__))
|
extensions.add(('pep8', pep8.__version__))
|
||||||
parser_hooks = []
|
parser_hooks = []
|
||||||
options_hooks = []
|
options_hooks = []
|
||||||
|
|
@ -124,17 +124,14 @@ def get_style_guide(**kwargs):
|
||||||
for options_hook in options_hooks:
|
for options_hook in options_hooks:
|
||||||
options_hook(options)
|
options_hook(options)
|
||||||
|
|
||||||
if (options.verbose
|
if util.warn_when_using_jobs(options):
|
||||||
and options.jobs
|
|
||||||
and options.jobs.isdigit()
|
|
||||||
and int(options.jobs) > 1):
|
|
||||||
if not multiprocessing:
|
if not multiprocessing:
|
||||||
warnings.warn("The multiprocessing module is not available. "
|
warnings.warn("The multiprocessing module is not available. "
|
||||||
"Ignoring --jobs arguments.")
|
"Ignoring --jobs arguments.")
|
||||||
if is_windows():
|
if util.is_windows():
|
||||||
warnings.warn("The --jobs option is not available on Windows. "
|
warnings.warn("The --jobs option is not available on Windows. "
|
||||||
"Ignoring --jobs arguments.")
|
"Ignoring --jobs arguments.")
|
||||||
if is_using_stdin(styleguide.paths):
|
if util.is_using_stdin(styleguide.paths):
|
||||||
warnings.warn("The --jobs option is not compatible with supplying "
|
warnings.warn("The --jobs option is not compatible with supplying "
|
||||||
"input using - . Ignoring --jobs arguments.")
|
"input using - . Ignoring --jobs arguments.")
|
||||||
if options.diff:
|
if options.diff:
|
||||||
|
|
@ -145,7 +142,7 @@ def get_style_guide(**kwargs):
|
||||||
if options.diff:
|
if options.diff:
|
||||||
options.jobs = None
|
options.jobs = None
|
||||||
|
|
||||||
force_disable_jobs = is_windows() or is_using_stdin(styleguide.paths)
|
force_disable_jobs = util.force_disable_jobs(styleguide)
|
||||||
|
|
||||||
if multiprocessing and options.jobs and not force_disable_jobs:
|
if multiprocessing and options.jobs and not force_disable_jobs:
|
||||||
if options.jobs.isdigit():
|
if options.jobs.isdigit():
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ class TestEngine(unittest.TestCase):
|
||||||
with mock.patch('flake8.engine.get_parser') as get_parser:
|
with mock.patch('flake8.engine.get_parser') as get_parser:
|
||||||
m.ignored_extensions = []
|
m.ignored_extensions = []
|
||||||
StyleGuide.return_value.options.jobs = '42'
|
StyleGuide.return_value.options.jobs = '42'
|
||||||
|
StyleGuide.return_value.options.diff = False
|
||||||
get_parser.return_value = (m, [])
|
get_parser.return_value = (m, [])
|
||||||
engine.get_style_guide(foo='bar')
|
engine.get_style_guide(foo='bar')
|
||||||
get_parser.assert_called_once_with()
|
get_parser.assert_called_once_with()
|
||||||
|
|
@ -85,13 +86,13 @@ class TestEngine(unittest.TestCase):
|
||||||
# ourselves) what system we may be testing on.
|
# ourselves) what system we may be testing on.
|
||||||
|
|
||||||
def test_windows_disables_jobs(self):
|
def test_windows_disables_jobs(self):
|
||||||
with mock.patch('flake8.engine.is_windows') as is_windows:
|
with mock.patch('flake8.util.is_windows') as is_windows:
|
||||||
is_windows.return_value = True
|
is_windows.return_value = True
|
||||||
guide = engine.get_style_guide()
|
guide = engine.get_style_guide()
|
||||||
assert isinstance(guide, reporter.BaseQReport) is False
|
assert isinstance(guide, reporter.BaseQReport) is False
|
||||||
|
|
||||||
def test_stdin_disables_jobs(self):
|
def test_stdin_disables_jobs(self):
|
||||||
with mock.patch('flake8.engine.is_using_stdin') as is_using_stdin:
|
with mock.patch('flake8.util.is_using_stdin') as is_using_stdin:
|
||||||
is_using_stdin.return_value = True
|
is_using_stdin.return_value = True
|
||||||
guide = engine.get_style_guide()
|
guide = engine.get_style_guide()
|
||||||
assert isinstance(guide, reporter.BaseQReport) is False
|
assert isinstance(guide, reporter.BaseQReport) is False
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,15 @@ def is_using_stdin(paths):
|
||||||
return '-' in paths
|
return '-' in paths
|
||||||
|
|
||||||
|
|
||||||
|
def warn_when_using_jobs(options):
|
||||||
|
return (options.verbose and options.jobs and options.jobs.isdigit() and
|
||||||
|
int(options.jobs) > 1)
|
||||||
|
|
||||||
|
|
||||||
|
def force_disable_jobs(styleguide):
|
||||||
|
return is_windows() or is_using_stdin(styleguide.paths)
|
||||||
|
|
||||||
|
|
||||||
def flag_on(val):
|
def flag_on(val):
|
||||||
"""Return true if flag is on"""
|
"""Return true if flag is on"""
|
||||||
return str(val).upper() in ('1', 'T', 'TRUE', 'ON')
|
return str(val).upper() in ('1', 'T', 'TRUE', 'ON')
|
||||||
|
|
|
||||||
2
tox.ini
2
tox.ini
|
|
@ -6,12 +6,10 @@ envlist =
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
deps =
|
deps =
|
||||||
nose
|
|
||||||
mock
|
mock
|
||||||
commands =
|
commands =
|
||||||
python setup.py test -q
|
python setup.py test -q
|
||||||
python setup.py flake8
|
python setup.py flake8
|
||||||
nosetests flake8.tests._test_warnings
|
|
||||||
|
|
||||||
[testenv:py27-flake8]
|
[testenv:py27-flake8]
|
||||||
basepython = python2.7
|
basepython = python2.7
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue