Bug 1604079 - Add a unit test for mozlint yamllint r=ahal

+ some python 3 changes

Differential Revision: https://phabricator.services.mozilla.com/D57263

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sylvestre Ledru 2019-12-17 16:57:25 +00:00
Родитель 3d352aa73a
Коммит 08e2e04f2a
5 изменённых файлов: 43 добавлений и 3 удалений

Просмотреть файл

@ -0,0 +1,7 @@
---
yamllint:
description: YAML linteraaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax
include:
- .cron.yml
- browser/config/
- wrong

Просмотреть файл

@ -0,0 +1,6 @@
---
yamllint:
description: YAML linter
include:
- .cron.yml
- browser/config/

Просмотреть файл

@ -16,3 +16,4 @@ skip-if = os == "win"
[test_rst.py]
[test_codespell.py]
skip-if = os == "win" || os == "mac" # codespell installed on Linux
[test_yaml.py]

Просмотреть файл

@ -0,0 +1,26 @@
import pytest
import mozunit
from mozfile import which
LINTER = 'yaml'
pytestmark = pytest.mark.skipif(not which('yamllint'), reason="yamllint is not installed")
def test_basic(lint, paths):
results = lint(paths())
assert len(results) == 2
assert "line too long (122 > 80 characters)'" in results[0].message
assert results[0].level == "error"
assert "bad.yml" in results[0].relpath
assert results[0].lineno == 3
assert "wrong indentation: expected 4 but found 8" in results[1].message
assert results[1].level == "error"
assert "bad.yml" in results[1].relpath
assert results[0].lineno == 3
if __name__ == '__main__':
mozunit.main()

Просмотреть файл

@ -23,7 +23,7 @@ Try to install it manually with:
$ pip install -U --require-hashes -r {}
""".strip().format(YAMLLINT_REQUIREMENTS_PATH)
YAMLLINT_FORMAT_REGEX = re.compile(r'(.*):(.*):(.*): \[(error|warning)\] (.*) \((.*)\)$')
YAMLLINT_FORMAT_REGEX = re.compile(b'(.*):(.*):(.*): \[(error|warning)\] (.*) \((.*)\)$')
results = []
@ -43,8 +43,8 @@ class YAMLLintProcess(ProcessHandlerMixin):
print('Unable to match yaml regex against output: {}'.format(line))
return
res = {'path': os.path.relpath(abspath, self.config['root']),
'message': message,
res = {'path': os.path.relpath(str(abspath), self.config['root']),
'message': str(message),
'level': 'error',
'lineno': line,
'column': col,