mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-08 22:04:17 +00:00
Add tests for parse_unified_diff
We could probably use non-git diff fixtures, but those are what we have for now.
This commit is contained in:
parent
02bcbee245
commit
9ebaa5c69c
5 changed files with 243 additions and 3 deletions
|
|
@ -115,3 +115,38 @@ def test_parameters_for_function_plugin():
|
|||
plugin = plugin_manager.Plugin('plugin-name', object())
|
||||
plugin._plugin = fake_plugin
|
||||
assert utils.parameters_for(plugin) == ['physical_line', 'self', 'tree']
|
||||
|
||||
|
||||
def read_diff_file(filename):
|
||||
"""Read the diff file in its entirety."""
|
||||
with open(filename, 'r') as fd:
|
||||
content = fd.read()
|
||||
return content
|
||||
|
||||
|
||||
SINGLE_FILE_DIFF = read_diff_file('tests/fixtures/diffs/single_file_diff')
|
||||
SINGLE_FILE_INFO = {
|
||||
'flake8/utils.py': set(range(75, 83)).union(set(range(84, 94))),
|
||||
}
|
||||
TWO_FILE_DIFF = read_diff_file('tests/fixtures/diffs/two_file_diff')
|
||||
TWO_FILE_INFO = {
|
||||
'flake8/utils.py': set(range(75, 83)).union(set(range(84, 94))),
|
||||
'tests/unit/test_utils.py': set(range(115, 128)),
|
||||
}
|
||||
MULTI_FILE_DIFF = read_diff_file('tests/fixtures/diffs/multi_file_diff')
|
||||
MULTI_FILE_INFO = {
|
||||
'flake8/utils.py': set(range(75, 83)).union(set(range(84, 94))),
|
||||
'tests/unit/test_utils.py': set(range(115, 129)),
|
||||
'tests/fixtures/diffs/single_file_diff': set(range(1, 28)),
|
||||
'tests/fixtures/diffs/two_file_diff': set(range(1, 46)),
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("diff, parsed_diff", [
|
||||
(SINGLE_FILE_DIFF, SINGLE_FILE_INFO),
|
||||
(TWO_FILE_DIFF, TWO_FILE_INFO),
|
||||
(MULTI_FILE_DIFF, MULTI_FILE_INFO),
|
||||
])
|
||||
def test_parse_unified_diff(diff, parsed_diff):
|
||||
"""Verify that what we parse from a diff matches expectations."""
|
||||
assert utils.parse_unified_diff(diff) == parsed_diff
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue