This essentially tests tools/lint/python/flake8.py. Though it also adds a basic framework for testing all the other linters as well. Getting this added now will allow others to collaborate on adding more tests without needing to get to 100% coverage for all linters right off the bat. All python tests under tools/lint/test will run as part of the 'ml' task on Linux, and the build task on Windows (OSX coverage is currently missing for python tests). The flake8 linter currently has a bug where the 'exclude' argument is ignored. This is why we need to also exclude 'tools/lint/test/files' in topsrcdir/.flake8, even though it is already listed in the 'mach_commands.py'. Other linters shouldn't need to do this, the exclusion in 'mach_commands.py' should be good enough. See bug 1277851 for more details. MozReview-Commit-ID: 9ho8C83eeuj
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import mozunit
|
|
import pytest
|
|
|
|
LINTER = 'flake8'
|
|
|
|
|
|
def test_lint_single_file(lint, paths):
|
|
results = lint(paths('bad.py'))
|
|
assert len(results) == 2
|
|
assert results[0].rule == 'F401'
|
|
assert results[1].rule == 'E501'
|
|
assert results[1].lineno == 5
|
|
|
|
# run lint again to make sure the previous results aren't counted twice
|
|
results = lint(paths('bad.py'))
|
|
assert len(results) == 2
|
|
|
|
|
|
def test_lint_custom_config(lint, paths):
|
|
results = lint(paths('custom'))
|
|
assert len(results) == 0
|
|
|
|
results = lint(paths('custom/good.py'))
|
|
assert len(results) == 0
|
|
|
|
results = lint(paths('custom', 'bad.py'))
|
|
assert len(results) == 2
|
|
|
|
|
|
@pytest.mark.xfail(
|
|
strict=True, reason="Bug 1277851 - custom configs are ignored if specifying a parent path")
|
|
def test_lint_custom_config_from_parent_path(lint, paths):
|
|
results = lint(paths(), collapse_results=True)
|
|
assert paths('custom/good.py')[0] not in results
|
|
|
|
|
|
@pytest.mark.xfail(strict=True, reason="Bug 1277851 - 'exclude' argument is ignored")
|
|
def test_lint_excluded_file(lint, paths):
|
|
paths = paths('bad.py')
|
|
results = lint(paths, exclude=paths)
|
|
assert len(results) == 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
mozunit.main()
|