mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
Add --verbose flag, and tests for it.
The new warnings associated with the --jobs argument should only appear when the --verbose flag is passed.
This commit is contained in:
parent
c3f5d144bc
commit
59ae3dfec7
3 changed files with 55 additions and 36 deletions
|
|
@ -124,7 +124,10 @@ def get_style_guide(**kwargs):
|
|||
for options_hook in options_hooks:
|
||||
options_hook(options)
|
||||
|
||||
if options.jobs and options.jobs.isdigit() and int(options.jobs) > 1:
|
||||
if (options.verbose
|
||||
and options.jobs
|
||||
and options.jobs.isdigit()
|
||||
and int(options.jobs) > 1):
|
||||
if not multiprocessing:
|
||||
warnings.warn("The multiprocessing module is not available. "
|
||||
"Ignoring --jobs arguments.")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
"""
|
||||
toast_warnings.py
|
||||
_test_warnings.py
|
||||
|
||||
Tests for the warnings that are emitted by flake8.
|
||||
|
||||
This module is named toast_warnings instead of test_warnings so that a
|
||||
This module is named _test_warnings instead of test_warnings so that a
|
||||
normal nosetests run does not collect it. The tests in this module pass
|
||||
when they are run alone, but they fail when they are run along with other
|
||||
tests (nosetests --with-isolation doesn't help).
|
||||
|
|
@ -29,6 +29,12 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
"""Integration style tests to check that warnings are issued properly for
|
||||
different command line options."""
|
||||
|
||||
windows_warning_text = ("The --jobs option is not available on Windows."
|
||||
" Ignoring --jobs arguments.")
|
||||
stdin_warning_text = ("The --jobs option is not compatible with"
|
||||
" supplying input using - . Ignoring --jobs"
|
||||
" arguments.")
|
||||
|
||||
def this_file(self):
|
||||
"""Return the real path of this file."""
|
||||
this_file = os.path.realpath(__file__)
|
||||
|
|
@ -66,7 +72,7 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
# warnings.
|
||||
return (style_guide, collected_warnings)
|
||||
|
||||
def verify_warnings(self, collected_warnings, expected_warnings=None):
|
||||
def verify_warnings(self, collected_warnings, expected_warnings):
|
||||
"""
|
||||
Verifies that collected_warnings is a sequence that contains user
|
||||
warnings that match the sequence of string values passed in as
|
||||
|
|
@ -90,8 +96,11 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
def check_files_collect_warnings(self,
|
||||
arglist=[],
|
||||
explicit_stdin=False,
|
||||
count=0):
|
||||
count=0,
|
||||
verbose=False):
|
||||
"""Call check_files and collect any warnings that are issued."""
|
||||
if verbose:
|
||||
arglist.append('--verbose')
|
||||
if explicit_stdin:
|
||||
target_file = "-"
|
||||
else:
|
||||
|
|
@ -109,36 +118,30 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
def check_files_no_warnings_allowed(self,
|
||||
arglist=[],
|
||||
explicit_stdin=False,
|
||||
count=0):
|
||||
count=0,
|
||||
verbose=False):
|
||||
"""Call check_files, and assert that there were no warnings issued."""
|
||||
(style_guide,
|
||||
report,
|
||||
collected_warnings,
|
||||
) = self.check_files_collect_warnings(arglist=arglist,
|
||||
explicit_stdin=explicit_stdin,
|
||||
count=count)
|
||||
self.verify_warnings(collected_warnings)
|
||||
count=count,
|
||||
verbose=verbose)
|
||||
self.verify_warnings(collected_warnings, expected_warnings=None)
|
||||
return style_guide, report
|
||||
|
||||
def test_no_args_no_warnings(self):
|
||||
# assert there are no reported errors or warnings
|
||||
self.check_files_no_warnings_allowed()
|
||||
|
||||
def _job_tester(self, jobs):
|
||||
def _job_tester(self, jobs, verbose=False):
|
||||
# mock stdout.flush so we can count the number of jobs created
|
||||
with mock.patch('sys.stdout.flush') as mocked:
|
||||
(guide,
|
||||
report,
|
||||
collected_warnings,
|
||||
) = self.check_files_collect_warnings(arglist=['--jobs=%s'
|
||||
% jobs])
|
||||
) = self.check_files_collect_warnings(
|
||||
arglist=['--jobs=%s' % jobs],
|
||||
verbose=verbose)
|
||||
|
||||
expected_warings = []
|
||||
if is_windows():
|
||||
expected_warings.append("The --jobs option is not "
|
||||
"available on Windows. Ignoring "
|
||||
"--jobs arguments.")
|
||||
|
||||
# The code path where guide.options.jobs gets converted to an
|
||||
# int is not run on windows. So, do the int conversion here.
|
||||
self.assertEqual(int(guide.options.jobs), jobs)
|
||||
|
|
@ -147,13 +150,20 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
else:
|
||||
self.assertEqual(guide.options.jobs, jobs)
|
||||
self.assertEqual(mocked.call_count, jobs)
|
||||
|
||||
expected_warings = []
|
||||
if verbose and is_windows():
|
||||
expected_warings.append(self.windows_warning_text)
|
||||
self.verify_warnings(collected_warnings, expected_warings)
|
||||
|
||||
def test_jobs(self):
|
||||
self._job_tester(2)
|
||||
self._job_tester(10)
|
||||
def test_jobs(self, verbose=False):
|
||||
self._job_tester(2, verbose=verbose)
|
||||
self._job_tester(10, verbose=verbose)
|
||||
|
||||
def test_stdin_jobs_warning(self):
|
||||
def test_no_args_no_warnings(self, verbose=False):
|
||||
self.check_files_no_warnings_allowed(verbose=verbose)
|
||||
|
||||
def test_stdin_jobs_warning(self, verbose=False):
|
||||
self.count = 0
|
||||
|
||||
def fake_stdin():
|
||||
|
|
@ -165,20 +175,26 @@ class IntegrationTestCaseWarnings(unittest.TestCase):
|
|||
(style_guide,
|
||||
report,
|
||||
collected_warnings,
|
||||
) = self.check_files_collect_warnings(
|
||||
arglist=['--jobs=4'],
|
||||
explicit_stdin=True)
|
||||
|
||||
expected_warings = ["The --jobs option is not compatible with "
|
||||
"supplying input using - . Ignoring --jobs "
|
||||
"arguments."]
|
||||
if is_windows():
|
||||
expected_warings.append("The --jobs option is not "
|
||||
"available on Windows. Ignoring "
|
||||
"--jobs arguments.")
|
||||
) = self.check_files_collect_warnings(arglist=['--jobs=4'],
|
||||
explicit_stdin=True,
|
||||
verbose=verbose)
|
||||
expected_warings = []
|
||||
if verbose:
|
||||
expected_warings.append(self.stdin_warning_text)
|
||||
if is_windows():
|
||||
expected_warings.append(self.windows_warning_text)
|
||||
self.verify_warnings(collected_warnings, expected_warings)
|
||||
self.assertEqual(self.count, 1)
|
||||
|
||||
def test_jobs_verbose(self):
|
||||
self.test_jobs(verbose=True)
|
||||
|
||||
def test_no_args_no_warnings_verbose(self):
|
||||
self.test_no_args_no_warnings(verbose=True)
|
||||
|
||||
def test_stdin_jobs_warning_verbose(self):
|
||||
self.test_stdin_jobs_warning(verbose=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
2
tox.ini
2
tox.ini
|
|
@ -11,7 +11,7 @@ deps =
|
|||
commands =
|
||||
python setup.py test -q
|
||||
python setup.py flake8
|
||||
nosetests flake8.tests.toast_warnings
|
||||
nosetests flake8.tests._test_warnings
|
||||
|
||||
[testenv:py27-flake8]
|
||||
basepython = python2.7
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue