mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 12:16:53 +00:00
When users specify any number of -q's on the command-line, we should not show the source even if they have otherwwise configured Flake8 to do so. Closes #245
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
"""Tests for the FilenameOnly formatter object."""
|
|
import optparse
|
|
|
|
from flake8 import style_guide
|
|
from flake8.formatting import default
|
|
|
|
|
|
def options(**kwargs):
|
|
"""Create an optparse.Values instance."""
|
|
kwargs.setdefault('output_file', None)
|
|
kwargs.setdefault('tee', False)
|
|
return optparse.Values(kwargs)
|
|
|
|
|
|
def test_caches_filenames_already_printed():
|
|
"""Verify we cache filenames when we format them."""
|
|
formatter = default.FilenameOnly(options())
|
|
assert formatter.filenames_already_printed == set()
|
|
|
|
formatter.format(style_guide.Error('code', 'file.py', 1, 1, 'text', 'l'))
|
|
assert formatter.filenames_already_printed == {'file.py'}
|
|
|
|
|
|
def test_only_returns_a_string_once_from_format():
|
|
"""Verify format ignores the second error with the same filename."""
|
|
formatter = default.FilenameOnly(options())
|
|
error = style_guide.Error('code', 'file.py', 1, 1, 'text', '1')
|
|
|
|
assert formatter.format(error) == 'file.py'
|
|
assert formatter.format(error) is None
|
|
|
|
|
|
def test_show_source_returns_nothing():
|
|
"""Verify show_source returns nothing."""
|
|
formatter = default.FilenameOnly(options())
|
|
error = style_guide.Error('code', 'file.py', 1, 1, 'text', '1')
|
|
|
|
assert formatter.show_source(error) is None
|