commit f9a2f147b6fe6187e3ba8d1b5bffa5efce14fac1 Author: Damian Johnson atagar@torproject.org Date: Mon Jan 21 00:18:20 2013 -0800
Making static checks skip the data directory
Our static checkers (most noticeably pep8 and pyflakes) run over the test data directory. This was fine until I started using it for the python3 export. Now that it has python code these checkers have a lot to say about it, none of it helpful.
Simply ignoring the output if it concerns the data directory. This is a sucky solution since pyflakes/pep8 are still running over an extra copy of our codebase, taking a noticeable bit of extra time. However, pyflakes at least lacks any options for ignoring directories.
I'll probably simply move our python3 export to another location later if this annoys me. --- run_tests.py | 2 +- test/check_whitespace.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/run_tests.py b/run_tests.py index 7448999..566eb41 100755 --- a/run_tests.py +++ b/run_tests.py @@ -371,7 +371,7 @@ if __name__ == '__main__': exit_status = os.system("python3 %s %s" % (python3_runner, " ".join(sys.argv[1:]))) sys.exit(exit_status) else: - sys.exit(1) # failed to do python3 setup + sys.exit(1) # failed to do python3 setup
if not CONFIG["argument.unit"] and not CONFIG["argument.integ"] and not CONFIG["argument.style"]: test.output.print_line("Nothing to run (for usage provide --help)\n") diff --git a/test/check_whitespace.py b/test/check_whitespace.py index a6a9ead..2f758b8 100644 --- a/test/check_whitespace.py +++ b/test/check_whitespace.py @@ -27,7 +27,8 @@ DEFAULT_TARGET = os.path.sep.join(__file__.split(os.path.sep)[:-1]) PYFLAKES_IGNORE = None
CONFIG = conf.config_dict("test", { - "pyflakes.ignore": [] + "pyflakes.ignore": [], + "integ.test_directory": "./test/data", })
@@ -87,7 +88,9 @@ def pep8_issues(base_path = DEFAULT_TARGET):
if line_match: path, line, _, issue = line_match.groups() - issues.setdefault(path, []).append((int(line), issue)) + + if not _is_test_data(path): + issues.setdefault(path, []).append((int(line), issue))
return issues
@@ -131,7 +134,7 @@ def pyflakes_issues(base_path = DEFAULT_TARGET): if line_match: path, line, issue = line_match.groups()
- if not issue in PYFLAKES_IGNORE.get(path, []): + if not _is_test_data(path) and not issue in PYFLAKES_IGNORE.get(path, []): issues.setdefault(path, []).append((int(line), issue))
return issues @@ -153,6 +156,9 @@ def get_issues(base_path = DEFAULT_TARGET): issues = {}
for file_path in _get_files_with_suffix(base_path): + if _is_test_data(file_path): + continue + with open(file_path) as f: file_contents = f.read()
@@ -186,6 +192,10 @@ def get_issues(base_path = DEFAULT_TARGET): return issues
+def _is_test_data(path): + return os.path.normpath(path).startswith(os.path.normpath(CONFIG["integ.test_directory"])) + + def _get_files_with_suffix(base_path, suffix = ".py"): """ Iterates over files in a given directory, providing filenames with a certain
tor-commits@lists.torproject.org