diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-12 01:10:36 +0000 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-11-12 01:10:36 +0000 |
| commit | 72eecbddcd72bfa3ee52abe08b764092c89f8b49 (patch) | |
| tree | 40ea24007e9869c8320b9c66e21ba11a3a54aff4 /tests | |
| parent | 22233b6b4fc6f36ed1757b31f7306192fa8d6e05 (diff) | |
| parent | 5dfb93c0d0ee4d6e14d959ab7d6bd390b98e59c0 (diff) | |
| download | flake8-72eecbddcd72bfa3ee52abe08b764092c89f8b49.tar.gz | |
Merge branch 'bug/245' into 'master'
Do not print the source when provided with -q
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
See merge request !140
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/unit/test_filenameonly_formatter.py | 38 | ||||
| -rw-r--r-- | tests/unit/test_nothing_formatter.py | 28 |
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/unit/test_filenameonly_formatter.py b/tests/unit/test_filenameonly_formatter.py new file mode 100644 index 0000000..caa0ae3 --- /dev/null +++ b/tests/unit/test_filenameonly_formatter.py @@ -0,0 +1,38 @@ +"""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 diff --git a/tests/unit/test_nothing_formatter.py b/tests/unit/test_nothing_formatter.py new file mode 100644 index 0000000..ce8087f --- /dev/null +++ b/tests/unit/test_nothing_formatter.py @@ -0,0 +1,28 @@ +"""Tests for the Nothing formatter obbject.""" +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_format_returns_nothing(): + """Verify Nothing.format returns None.""" + formatter = default.Nothing(options()) + error = style_guide.Error('code', 'file.py', 1, 1, 'text', '1') + + assert formatter.format(error) is None + + +def test_show_source_returns_nothing(): + """Verify Nothing.show_source returns None.""" + formatter = default.Nothing(options()) + error = style_guide.Error('code', 'file.py', 1, 1, 'text', '1') + + assert formatter.show_source(error) is None |
