From a6fc242c5ef89571f1550e7fce33ac8b806a3451 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sat, 7 Mar 2015 20:21:58 -0600 Subject: [PATCH] Slightly simplify our conditionals Test warnings by default --- flake8/engine.py | 15 ++++++--------- flake8/tests/test_engine.py | 5 +++-- .../tests/{_test_warnings.py => test_warnings.py} | 0 flake8/util.py | 9 +++++++++ tox.ini | 2 -- 5 files changed, 18 insertions(+), 13 deletions(-) rename flake8/tests/{_test_warnings.py => test_warnings.py} (100%) diff --git a/flake8/engine.py b/flake8/engine.py index be539db..0711f8d 100644 --- a/flake8/engine.py +++ b/flake8/engine.py @@ -9,7 +9,7 @@ from flake8 import __version__ from flake8 import callbacks from flake8.reporter import (multiprocessing, BaseQReport, FileQReport, 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 @@ -18,7 +18,7 @@ EXTRA_EXCLUDE = ['.tox', '.eggs', '*.egg'] def _register_extensions(): """Register all the extensions.""" - extensions = OrderedSet() + extensions = util.OrderedSet() extensions.add(('pep8', pep8.__version__)) parser_hooks = [] options_hooks = [] @@ -124,17 +124,14 @@ def get_style_guide(**kwargs): for options_hook in options_hooks: options_hook(options) - if (options.verbose - and options.jobs - and options.jobs.isdigit() - and int(options.jobs) > 1): + if util.warn_when_using_jobs(options): if not multiprocessing: warnings.warn("The multiprocessing module is not available. " "Ignoring --jobs arguments.") - if is_windows(): + if util.is_windows(): warnings.warn("The --jobs option is not available on Windows. " "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 " "input using - . Ignoring --jobs arguments.") if options.diff: @@ -145,7 +142,7 @@ def get_style_guide(**kwargs): if options.diff: 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 options.jobs.isdigit(): diff --git a/flake8/tests/test_engine.py b/flake8/tests/test_engine.py index b7f7f5f..06fe62a 100644 --- a/flake8/tests/test_engine.py +++ b/flake8/tests/test_engine.py @@ -39,6 +39,7 @@ class TestEngine(unittest.TestCase): with mock.patch('flake8.engine.get_parser') as get_parser: m.ignored_extensions = [] StyleGuide.return_value.options.jobs = '42' + StyleGuide.return_value.options.diff = False get_parser.return_value = (m, []) engine.get_style_guide(foo='bar') get_parser.assert_called_once_with() @@ -85,13 +86,13 @@ class TestEngine(unittest.TestCase): # ourselves) what system we may be testing on. 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 guide = engine.get_style_guide() assert isinstance(guide, reporter.BaseQReport) is False 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 guide = engine.get_style_guide() assert isinstance(guide, reporter.BaseQReport) is False diff --git a/flake8/tests/_test_warnings.py b/flake8/tests/test_warnings.py similarity index 100% rename from flake8/tests/_test_warnings.py rename to flake8/tests/test_warnings.py diff --git a/flake8/util.py b/flake8/util.py index 5a954f8..fda6331 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -54,6 +54,15 @@ def is_using_stdin(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): """Return true if flag is on""" return str(val).upper() in ('1', 'T', 'TRUE', 'ON') diff --git a/tox.ini b/tox.ini index 5ff17ed..b21e44c 100644 --- a/tox.ini +++ b/tox.ini @@ -6,12 +6,10 @@ envlist = [testenv] usedevelop = True deps = - nose mock commands = python setup.py test -q python setup.py flake8 - nosetests flake8.tests._test_warnings [testenv:py27-flake8] basepython = python2.7