This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
173 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
"""Test against sample modules using the explain option in all supported config sources.""" | ||
|
||
import os | ||
import re | ||
|
||
import flake8.main | ||
import pytest | ||
|
||
EXPECTED = list() | ||
EXPECTED.append("""\ | ||
./sample.py:1:1: D100 Missing docstring in public module | ||
All modules should normally have docstrings. [...] all functions and | ||
classes exported by a module should also have docstrings. Public | ||
methods (including the __init__ constructor) should also have | ||
docstrings. | ||
Note: Public (exported) definitions are either those with names listed | ||
in __all__ variable (if present), or those that do not start | ||
with a single underscore. | ||
./sample.py:5:1: D300 Use \"\"\"triple double quotes\"\"\" (found \'\'\'-quotes) | ||
For consistency, always use \"\"\"triple double quotes\"\"\" around | ||
docstrings. Use r\"\"\"raw triple double quotes\"\"\" if you use any | ||
backslashes in your docstrings. For Unicode docstrings, use | ||
u\"\"\"Unicode triple-quoted strings\"\"\". | ||
Note: Exception to this is made if the docstring contains | ||
\"\"\" quotes in its body. | ||
./sample.py:5:1: D401 First line should be in imperative mood (\'Print\', not \'Prints\') | ||
[Docstring] prescribes the function or method's effect as a command: | ||
("Do this", "Return that"), not as a description; e.g. don't write | ||
"Returns the pathname ...". | ||
./sample.py:14:1: D203 1 blank line required before class docstring (found 0) | ||
Insert a blank line before and after all docstrings (one-line or | ||
multi-line) that document a class -- generally speaking, the class's | ||
methods are separated from each other by a single blank line, and the | ||
docstring needs to be offset from the first method by a blank line; | ||
for symmetry, put a blank line between the class header and the | ||
docstring. | ||
./sample.py:14:1: D204 1 blank line required after class docstring (found 0) | ||
Insert a blank line before and after all docstrings (one-line or | ||
multi-line) that document a class -- generally speaking, the class's | ||
methods are separated from each other by a single blank line, and the | ||
docstring needs to be offset from the first method by a blank line; | ||
for symmetry, put a blank line between the class header and the | ||
docstring. | ||
./sample.py:14:1: D300 Use \"\"\"triple double quotes\"\"\" (found \'\'\'-quotes) | ||
For consistency, always use \"\"\"triple double quotes\"\"\" around | ||
docstrings. Use r\"\"\"raw triple double quotes\"\"\" if you use any | ||
backslashes in your docstrings. For Unicode docstrings, use | ||
u\"\"\"Unicode triple-quoted strings\"\"\". | ||
Note: Exception to this is made if the docstring contains | ||
\"\"\" quotes in its body. | ||
""") | ||
EXPECTED.append("""\ | ||
./sample_unicode.py:1:1: D100 Missing docstring in public module | ||
All modules should normally have docstrings. [...] all functions and | ||
classes exported by a module should also have docstrings. Public | ||
methods (including the __init__ constructor) should also have | ||
docstrings. | ||
Note: Public (exported) definitions are either those with names listed | ||
in __all__ variable (if present), or those that do not start | ||
with a single underscore. | ||
./sample_unicode.py:15:1: D300 Use \"\"\"triple double quotes\"\"\" (found '''-quotes) | ||
For consistency, always use \"\"\"triple double quotes\"\"\" around | ||
docstrings. Use r\"\"\"raw triple double quotes\"\"\" if you use any | ||
backslashes in your docstrings. For Unicode docstrings, use | ||
u\"\"\"Unicode triple-quoted strings\"\"\". | ||
Note: Exception to this is made if the docstring contains | ||
\"\"\" quotes in its body. | ||
./sample_unicode.py:15:1: D401 First line should be in imperative mood ('Print', not 'Prints') | ||
[Docstring] prescribes the function or method's effect as a command: | ||
("Do this", "Return that"), not as a description; e.g. don't write | ||
"Returns the pathname ...". | ||
./sample_unicode.py:24:1: D203 1 blank line required before class docstring (found 0) | ||
Insert a blank line before and after all docstrings (one-line or | ||
multi-line) that document a class -- generally speaking, the class's | ||
methods are separated from each other by a single blank line, and the | ||
docstring needs to be offset from the first method by a blank line; | ||
for symmetry, put a blank line between the class header and the | ||
docstring. | ||
./sample_unicode.py:24:1: D204 1 blank line required after class docstring (found 0) | ||
Insert a blank line before and after all docstrings (one-line or | ||
multi-line) that document a class -- generally speaking, the class's | ||
methods are separated from each other by a single blank line, and the | ||
docstring needs to be offset from the first method by a blank line; | ||
for symmetry, put a blank line between the class header and the | ||
docstring. | ||
./sample_unicode.py:24:1: D300 Use \"\"\"triple double quotes\"\"\" (found '''-quotes) | ||
For consistency, always use \"\"\"triple double quotes\"\"\" around | ||
docstrings. Use r\"\"\"raw triple double quotes\"\"\" if you use any | ||
backslashes in your docstrings. For Unicode docstrings, use | ||
u\"\"\"Unicode triple-quoted strings\"\"\". | ||
Note: Exception to this is made if the docstring contains | ||
\"\"\" quotes in its body. | ||
""") | ||
|
||
|
||
@pytest.mark.parametrize('stdin', ['', 'sample_unicode.py', 'sample.py']) | ||
@pytest.mark.parametrize('which_cfg', ['tox.ini', 'tox.ini flake8', 'setup.cfg', '.pep257']) | ||
def test_direct(capsys, monkeypatch, tempdir, stdin, which_cfg): | ||
"""Test by calling flake8.main.main() using the same running python process. | ||
:param capsys: pytest fixture. | ||
:param monkeypatch: pytest fixture. | ||
:param tempdir: conftest fixture. | ||
:param str stdin: Pipe this file to stdin of flake8. | ||
:param str which_cfg: Which config file to test with. | ||
""" | ||
# Prepare. | ||
monkeypatch.chdir(tempdir.join('empty' if stdin else '')) | ||
monkeypatch.setattr('sys.argv', ['flake8', '-' if stdin else '.', '-j1']) | ||
if stdin: | ||
monkeypatch.setattr('pep8.stdin_get_value', lambda: tempdir.join(stdin).read()) | ||
|
||
# Write configuration. | ||
cfg = which_cfg.split() | ||
section = cfg[1] if len(cfg) > 1 else 'pep257' | ||
key = 'show-pep257' if section == 'flake8' else 'explain' | ||
tempdir.join('empty' if stdin else '', cfg[0]).write('[{0}]\n{1} = True\n'.format(section, key)) | ||
|
||
# Execute. | ||
with pytest.raises(SystemExit): | ||
flake8.main.main() | ||
out, err = capsys.readouterr() | ||
assert not err | ||
|
||
if stdin: | ||
expected = EXPECTED[0 if stdin == 'sample.py' else 1].replace('./{0}:'.format(stdin), 'stdin:') | ||
elif os.name == 'nt': | ||
expected = '\n\n'.join(EXPECTED).replace('./sample', r'.\sample') | ||
else: | ||
expected = '\n\n'.join(EXPECTED) | ||
out = re.sub(r'\n[\t ]+\n', r'\n\n', out) | ||
|
||
assert expected.strip() == out.strip() |
Oops, something went wrong.