mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Merge pull request #1726 from PyCQA/sorted-results
ensure results are sorted for file traversal
This commit is contained in:
commit
0acd10b881
2 changed files with 23 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import contextlib
|
||||||
import errno
|
import errno
|
||||||
import logging
|
import logging
|
||||||
import multiprocessing.pool
|
import multiprocessing.pool
|
||||||
|
import operator
|
||||||
import signal
|
import signal
|
||||||
import tokenize
|
import tokenize
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
@ -180,8 +181,9 @@ class Manager:
|
||||||
A tuple of the total results found and the results reported.
|
A tuple of the total results found and the results reported.
|
||||||
"""
|
"""
|
||||||
results_reported = results_found = 0
|
results_reported = results_found = 0
|
||||||
|
self.results.sort(key=operator.itemgetter(0))
|
||||||
for filename, results, _ in self.results:
|
for filename, results, _ in self.results:
|
||||||
results.sort(key=lambda tup: (tup[1], tup[2]))
|
results.sort(key=operator.itemgetter(1, 2))
|
||||||
with self.style_guide.processing_file(filename):
|
with self.style_guide.processing_file(filename):
|
||||||
results_reported += self._handle_results(filename, results)
|
results_reported += self._handle_results(filename, results)
|
||||||
results_found += len(results)
|
results_found += len(results)
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,26 @@ t.py:1:1: F401 'os' imported but unused
|
||||||
assert err == ""
|
assert err == ""
|
||||||
|
|
||||||
|
|
||||||
|
def test_errors_sorted(tmpdir, capsys):
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
for c in "abcde":
|
||||||
|
tmpdir.join(f"{c}.py").write("import os\n")
|
||||||
|
assert cli.main(["./"]) == 1
|
||||||
|
|
||||||
|
# file traversal was done in inode-order before
|
||||||
|
# this uses a significant number of files such that it's unlikely to pass
|
||||||
|
expected = """\
|
||||||
|
./a.py:1:1: F401 'os' imported but unused
|
||||||
|
./b.py:1:1: F401 'os' imported but unused
|
||||||
|
./c.py:1:1: F401 'os' imported but unused
|
||||||
|
./d.py:1:1: F401 'os' imported but unused
|
||||||
|
./e.py:1:1: F401 'os' imported but unused
|
||||||
|
"""
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert out == expected
|
||||||
|
assert err == ""
|
||||||
|
|
||||||
|
|
||||||
def test_extend_exclude(tmpdir, capsys):
|
def test_extend_exclude(tmpdir, capsys):
|
||||||
"""Ensure that `flake8 --extend-exclude` works."""
|
"""Ensure that `flake8 --extend-exclude` works."""
|
||||||
for d in ["project", "vendor", "legacy", ".git", ".tox", ".hg"]:
|
for d in ["project", "vendor", "legacy", ".git", ".tox", ".hg"]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue