mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
9a082a086c
Rather than using .lint.py files that contain a LINTER object, linter definitions are now in standalone .yml files. In the case of external linters that need to run python code, the payload is now of the form: <module path>:<object path> The <module path> is the import path to the module, and <object path> is the callable object to use within that module. It is up to the consumer of mozlint to ensure the <module path> lives on sys.path. For example, if an external lint's function lives in package 'foo', file 'bar.py' and function 'lint', the payload would read: foo.bar:lint This mechanism was borrowed from taskcluster. MozReview-Commit-ID: AIsfbVmozy4 --HG-- rename : python/mozlint/test/linters/badreturncode.lint.py => python/mozlint/test/linters/badreturncode.yml rename : python/mozlint/test/linters/explicit_path.lint.py => python/mozlint/test/linters/explicit_path.yml rename : python/mozlint/test/linters/external.lint.py => python/mozlint/test/linters/external.yml rename : python/mozlint/test/linters/invalid_exclude.lint.py => python/mozlint/test/linters/invalid_exclude.yml rename : python/mozlint/test/linters/invalid_extension.lnt => python/mozlint/test/linters/invalid_extension.ym rename : python/mozlint/test/linters/invalid_include.lint.py => python/mozlint/test/linters/invalid_include.yml rename : python/mozlint/test/linters/invalid_type.lint.py => python/mozlint/test/linters/invalid_type.yml rename : python/mozlint/test/linters/missing_attrs.lint.py => python/mozlint/test/linters/missing_attrs.yml rename : python/mozlint/test/linters/missing_definition.lint.py => python/mozlint/test/linters/missing_definition.yml rename : python/mozlint/test/linters/raises.lint.py => python/mozlint/test/linters/raises.yml rename : python/mozlint/test/linters/regex.lint.py => python/mozlint/test/linters/regex.yml rename : python/mozlint/test/linters/string.lint.py => python/mozlint/test/linters/string.yml rename : python/mozlint/test/linters/structured.lint.py => python/mozlint/test/linters/structured.yml extra : rebase_source : bda3926712234123355c5af71c6453ce869b19fc
83 lines
2.1 KiB
Python
83 lines
2.1 KiB
Python
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
from mozlint import ResultContainer
|
|
from mozlint.errors import LintersNotConfigured, LintException
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
linters = ('string.yml', 'regex.yml', 'external.yml')
|
|
|
|
|
|
def test_roll_no_linters_configured(lint, files):
|
|
with pytest.raises(LintersNotConfigured):
|
|
lint.roll(files)
|
|
|
|
|
|
def test_roll_successful(lint, linters, files):
|
|
lint.read(linters)
|
|
|
|
result = lint.roll(files)
|
|
assert len(result) == 1
|
|
assert lint.failed == []
|
|
|
|
path = result.keys()[0]
|
|
assert os.path.basename(path) == 'foobar.js'
|
|
|
|
errors = result[path]
|
|
assert isinstance(errors, list)
|
|
assert len(errors) == 6
|
|
|
|
container = errors[0]
|
|
assert isinstance(container, ResultContainer)
|
|
assert container.rule == 'no-foobar'
|
|
|
|
|
|
def test_roll_catch_exception(lint, lintdir, files):
|
|
lint.read(os.path.join(lintdir, 'raises.yml'))
|
|
|
|
# suppress printed traceback from test output
|
|
old_stderr = sys.stderr
|
|
sys.stderr = open(os.devnull, 'w')
|
|
with pytest.raises(LintException):
|
|
lint.roll(files)
|
|
sys.stderr = old_stderr
|
|
|
|
|
|
def test_roll_with_excluded_path(lint, linters, files):
|
|
lint.lintargs.update({'exclude': ['**/foobar.js']})
|
|
|
|
lint.read(linters)
|
|
result = lint.roll(files)
|
|
|
|
assert len(result) == 0
|
|
assert lint.failed == []
|
|
|
|
|
|
def test_roll_with_invalid_extension(lint, lintdir, filedir):
|
|
lint.read(os.path.join(lintdir, 'external.yml'))
|
|
result = lint.roll(os.path.join(filedir, 'foobar.py'))
|
|
assert len(result) == 0
|
|
assert lint.failed == []
|
|
|
|
|
|
def test_roll_with_failure_code(lint, lintdir, files):
|
|
lint.read(os.path.join(lintdir, 'badreturncode.yml'))
|
|
|
|
assert lint.failed is None
|
|
result = lint.roll(files)
|
|
assert len(result) == 0
|
|
assert lint.failed == ['BadReturnCodeLinter']
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(pytest.main(['--verbose', __file__]))
|