Hashar has uploaded a new change for review. https://gerrit.wikimedia.org/r/243134
Change subject: Rough YAML linter for *.yaml.example files ...................................................................... Rough YAML linter for *.yaml.example files Iterate the repository for files matching '.yaml' or '.yaml.example' and attempt to safe_load() them. YAML files containing multiple documents are not supported, only the first document will be validated. That is because safe_load_all() does not raise any error for some reason. Add test-requirements.txt to ship nose and PyYAML. Introduce tox env 'yamllint' and add it to the default list of env to run (envlist). Usage is either: tox tox -eyamllint Bug: T114470 Change-Id: I076235213a81fd6431919f28fcead6c72f5cabb2 --- A test-requirements.txt A tests/yamllint.py M tox.ini 3 files changed, 26 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/tools refs/changes/34/243134/1 diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..9c7c637 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,2 @@ +nose +PyYAML diff --git a/tests/yamllint.py b/tests/yamllint.py new file mode 100644 index 0000000..0feeef8 --- /dev/null +++ b/tests/yamllint.py @@ -0,0 +1,19 @@ +import os.path +import yaml + + +def test_valid_yaml(): + basedir = os.path.realpath(os.path.join(__file__, '..', '..')) + yaml_files = [] + for dirpath, dirnames, filenames in os.walk(basedir): + yaml_files.extend( + [os.path.join(dirpath, f) for f in filenames + if f.endswith('.yaml') or f.endswith('.yaml.example')] + ) + for yaml_file in yaml_files: + yield is_valid_yaml, yaml_file + + +def is_valid_yaml(filename): + with open(filename, 'r') as f: + yaml.safe_load(f) diff --git a/tox.ini b/tox.ini index 416a825..b943a82 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,10 @@ [tox] skipsdist = True -envlist = flake8 +envlist = flake8,yamllint + +[testenv:yamllint] +commands = nosetests {posargs} {toxinidir}/tests/yamllint.py +deps = -rtest-requirements.txt [testenv:flake8] commands = flake8 {posargs} -- To view, visit https://gerrit.wikimedia.org/r/243134 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I076235213a81fd6431919f28fcead6c72f5cabb2 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/tools Gerrit-Branch: master Gerrit-Owner: Hashar <has...@free.fr> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits