yamllint-1.10.0/ 0000755 0002322 0002322 00000000000 13177553503 014001 5 ustar debalance debalance yamllint-1.10.0/.pre-commit-hooks.yaml 0000644 0002322 0002322 00000000326 13177553503 020141 0 ustar debalance debalance ---
# For use with pre-commit.
# See usage instructions at http://pre-commit.com
- id: yamllint
name: yamllint
description: This hook runs yamllint.
entry: yamllint
language: python
types: [file, yaml]
yamllint-1.10.0/README.rst 0000644 0002322 0002322 00000005542 13177553503 015476 0 ustar debalance debalance yamllint
========
A linter for YAML files.
yamllint does not only check for syntax validity, but for weirdnesses like key
repetition and cosmetic problems such as lines length, trailing spaces,
indentation, etc.
.. image::
https://travis-ci.org/adrienverge/yamllint.svg?branch=master
:target: https://travis-ci.org/adrienverge/yamllint
:alt: CI tests status
.. image::
https://coveralls.io/repos/github/adrienverge/yamllint/badge.svg?branch=master
:target: https://coveralls.io/github/adrienverge/yamllint?branch=master
:alt: Code coverage status
.. image:: https://readthedocs.org/projects/yamllint/badge/?version=latest
:target: https://yamllint.readthedocs.io/en/latest/?badge=latest
:alt: Documentation status
Written in Python (compatible with Python 2 & 3).
Documentation
-------------
https://yamllint.readthedocs.io/
Overview
--------
Screenshot
^^^^^^^^^^
.. image:: docs/screenshot.png
:alt: yamllint screenshot
Installation
^^^^^^^^^^^^
On Fedora / CentOS:
.. code:: bash
sudo dnf install yamllint
On Debian 8+ / Ubuntu 16.04+:
.. code:: bash
sudo apt-get install yamllint
Alternatively using pip, the Python package manager:
.. code:: bash
sudo pip install yamllint
Usage
^^^^^
.. code:: bash
# Lint one or more files
yamllint my_file.yml my_other_file.yaml ...
.. code:: bash
# Lint all YAML files in a directory
yamllint .
.. code:: bash
# Use a pre-defined lint configuration
yamllint -d relaxed file.yaml
# Use a custom lint configuration
yamllint -c /path/to/myconfig file-to-lint.yaml
.. code:: bash
# Output a parsable format (for syntax checking in editors like Vim, emacs...)
yamllint -f parsable file.yaml
`Read more in the complete documentation! `_
Features
^^^^^^^^
Here is a yamllint configuration file example:
.. code:: yaml
extends: default
rules:
# 80 chars should be enough, but don't fail if a line is longer
line-length:
max: 80
level: warning
# don't bother me with this rule
indentation: disable
Within a YAML file, special comments can be used to disable checks for a single
line:
.. code:: yaml
This line is waaaaaaaaaay too long # yamllint disable-line
or for a whole block:
.. code:: yaml
# yamllint disable rule:colons
- Lorem : ipsum
dolor : sit amet,
consectetur : adipiscing elit
# yamllint enable
Specific files can be ignored (totally or for some rules only) using a
``.gitignore``-style pattern:
.. code:: yaml
# For all rules
ignore: |
*.dont-lint-me.yaml
/bin/
!/bin/*.lint-me-anyway.yaml
rules:
key-duplicates:
ignore: |
generated
*.template.yaml
trailing-spaces:
ignore: |
*.ignore-trailing-spaces.yaml
/ascii-art/*
`Read more in the complete documentation! `_
License
-------
`GPL version 3 `_
yamllint-1.10.0/CHANGELOG.rst 0000644 0002322 0002322 00000001536 13177553503 016027 0 ustar debalance debalance Changelog
=========
1.10.0 (2017-11-05)
-------------------
- Fix colored output on Windows
- Check documentation compilation on continuous integration
- Add a new `empty-values` rule
- Make sure test files are included in dist bundle
- Tests: Use en_US.UTF-8 locale when C.UTF-8 not available
- Tests: Dynamically detect Python executable path
1.9.0 (2017-10-16)
------------------
- Add a new `key-ordering` rule
- Fix indentation rule for key following empty list
1.8.2 (2017-10-10)
------------------
- Be clearer about the `ignore` conf type
- Update pre-commit hook file
- Add documentation for pre-commit
1.8.1 (2017-07-04)
------------------
- Require pathspec >= 0.5.3
- Support Python 2.6
- Add a changelog
1.8.0 (2017-06-28)
------------------
- Refactor argparse with mutually_exclusive_group
- Add support to ignore paths in configuration
yamllint-1.10.0/tests/ 0000755 0002322 0002322 00000000000 13177553503 015143 5 ustar debalance debalance yamllint-1.10.0/tests/test_linter.py 0000644 0002322 0002322 00000004165 13177553503 020057 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import io
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
from yamllint.config import YamlLintConfig
from yamllint import linter
class LinterTestCase(unittest.TestCase):
def fake_config(self):
return YamlLintConfig('extends: default')
def test_run_on_string(self):
linter.run('test: document', self.fake_config())
def test_run_on_bytes(self):
linter.run(b'test: document', self.fake_config())
def test_run_on_unicode(self):
linter.run(u'test: document', self.fake_config())
def test_run_on_stream(self):
linter.run(io.StringIO(u'hello'), self.fake_config())
def test_run_on_int(self):
self.assertRaises(TypeError, linter.run, 42, self.fake_config())
def test_run_on_list(self):
self.assertRaises(TypeError, linter.run,
['h', 'e', 'l', 'l', 'o'], self.fake_config())
def test_run_on_non_ascii_chars(self):
s = (u'- hétérogénéité\n'
u'# 19.99 €\n')
linter.run(s, self.fake_config())
linter.run(s.encode('utf-8'), self.fake_config())
linter.run(s.encode('iso-8859-15'), self.fake_config())
s = (u'- お早う御座います。\n'
u'# الأَبْجَدِيَّة العَرَبِيَّة\n')
linter.run(s, self.fake_config())
linter.run(s.encode('utf-8'), self.fake_config())
yamllint-1.10.0/tests/test_cli.py 0000644 0002322 0002322 00000032340 13177553503 017325 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import fcntl
import locale
import os
import pty
import shutil
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
from yamllint import cli
from tests.common import build_temp_workspace
@unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported')
class CommandLineTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(CommandLineTestCase, cls).setUpClass()
cls.wd = build_temp_workspace({
# .yaml file at root
'a.yaml': '---\n'
'- 1 \n'
'- 2',
# file with only one warning
'warn.yaml': 'key: value\n',
# .yml file at root
'empty.yml': '',
# file in dir
'sub/ok.yaml': '---\n'
'key: value\n',
# file in very nested dir
's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n'
'key: value\n'
'key: other value\n',
# empty dir
'empty-dir': [],
# non-YAML file
'no-yaml.json': '---\n'
'key: value\n',
# non-ASCII chars
'non-ascii/utf-8': (
u'---\n'
u'- hétérogénéité\n'
u'# 19.99 €\n'
u'- お早う御座います。\n'
u'# الأَبْجَدِيَّة العَرَبِيَّة\n').encode('utf-8'),
})
@classmethod
def tearDownClass(cls):
super(CommandLineTestCase, cls).tearDownClass()
shutil.rmtree(cls.wd)
def test_find_files_recursively(self):
self.assertEqual(
sorted(cli.find_files_recursively([self.wd])),
[os.path.join(self.wd, 'a.yaml'),
os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'),
os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'warn.yaml')],
)
items = [os.path.join(self.wd, 'sub/ok.yaml'),
os.path.join(self.wd, 'empty-dir')]
self.assertEqual(
sorted(cli.find_files_recursively(items)),
[os.path.join(self.wd, 'sub/ok.yaml')],
)
items = [os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 's')]
self.assertEqual(
sorted(cli.find_files_recursively(items)),
[os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml')],
)
items = [os.path.join(self.wd, 'sub'),
os.path.join(self.wd, '/etc/another/file')]
self.assertEqual(
sorted(cli.find_files_recursively(items)),
[os.path.join(self.wd, '/etc/another/file'),
os.path.join(self.wd, 'sub/ok.yaml')],
)
def test_run_with_bad_arguments(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(())
self.assertNotEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^usage')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('--unknown-arg', ))
self.assertNotEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^usage')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-c', './conf.yaml', '-d', 'relaxed', 'file'))
self.assertNotEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(
err.splitlines()[-1],
r'^yamllint: error: argument -d\/--config-data: '
r'not allowed with argument -c\/--config-file$'
)
def test_run_with_bad_config(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-d', 'rules: {a: b}', 'file'))
self.assertEqual(ctx.exception.code, -1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^invalid config: no such rule')
def test_run_with_empty_config(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-d', '', 'file'))
self.assertEqual(ctx.exception.code, -1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'^invalid config: not a dict')
def test_run_with_config_file(self):
with open(os.path.join(self.wd, 'config'), 'w') as f:
f.write('rules: {trailing-spaces: disable}')
with self.assertRaises(SystemExit) as ctx:
cli.run(('-c', f.name, os.path.join(self.wd, 'a.yaml')))
self.assertEqual(ctx.exception.code, 0)
with open(os.path.join(self.wd, 'config'), 'w') as f:
f.write('rules: {trailing-spaces: enable}')
with self.assertRaises(SystemExit) as ctx:
cli.run(('-c', f.name, os.path.join(self.wd, 'a.yaml')))
self.assertEqual(ctx.exception.code, 1)
def test_run_with_user_global_config_file(self):
home = os.path.join(self.wd, 'fake-home')
os.mkdir(home)
dir = os.path.join(home, '.config')
os.mkdir(dir)
dir = os.path.join(dir, 'yamllint')
os.mkdir(dir)
config = os.path.join(dir, 'config')
temp = os.environ['HOME']
os.environ['HOME'] = home
with open(config, 'w') as f:
f.write('rules: {trailing-spaces: disable}')
with self.assertRaises(SystemExit) as ctx:
cli.run((os.path.join(self.wd, 'a.yaml'), ))
self.assertEqual(ctx.exception.code, 0)
with open(config, 'w') as f:
f.write('rules: {trailing-spaces: enable}')
with self.assertRaises(SystemExit) as ctx:
cli.run((os.path.join(self.wd, 'a.yaml'), ))
self.assertEqual(ctx.exception.code, 1)
os.environ['HOME'] = temp
def test_run_version(self):
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('--version', ))
self.assertEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertRegexpMatches(out + err, r'yamllint \d+\.\d+')
def test_run_non_existing_file(self):
file = os.path.join(self.wd, 'i-do-not-exist.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
self.assertEqual(ctx.exception.code, -1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertRegexpMatches(err, r'No such file or directory')
def test_run_one_problem_file(self):
file = os.path.join(self.wd, 'a.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
self.assertEqual(ctx.exception.code, 1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, (
'%s:2:4: [error] trailing spaces (trailing-spaces)\n'
'%s:3:4: [error] no new line character at the end of file '
'(new-line-at-end-of-file)\n') % (file, file))
self.assertEqual(err, '')
def test_run_one_warning(self):
file = os.path.join(self.wd, 'warn.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
self.assertEqual(ctx.exception.code, 0)
def test_run_warning_in_strict_mode(self):
file = os.path.join(self.wd, 'warn.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', '--strict', file))
self.assertEqual(ctx.exception.code, 2)
def test_run_one_ok_file(self):
file = os.path.join(self.wd, 'sub', 'ok.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
self.assertEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertEqual(err, '')
def test_run_empty_file(self):
file = os.path.join(self.wd, 'empty.yml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
self.assertEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertEqual(err, '')
def test_run_non_ascii_file(self):
file = os.path.join(self.wd, 'non-ascii', 'utf-8')
# Make sure the default localization conditions on this "system"
# support UTF-8 encoding.
loc = locale.getlocale()
try:
locale.setlocale(locale.LC_ALL, 'C.UTF-8')
except locale.Error:
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(('-f', 'parsable', file))
locale.setlocale(locale.LC_ALL, loc)
self.assertEqual(ctx.exception.code, 0)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, '')
self.assertEqual(err, '')
def test_run_multiple_files(self):
items = [os.path.join(self.wd, 'empty.yml'),
os.path.join(self.wd, 's')]
file = items[1] + '/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run(['-f', 'parsable'] + items)
self.assertEqual(ctx.exception.code, 1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, (
'%s:3:1: [error] duplication of key "key" in mapping '
'(key-duplicates)\n') % file)
self.assertEqual(err, '')
def test_run_piped_output_nocolor(self):
file = os.path.join(self.wd, 'a.yaml')
sys.stdout, sys.stderr = StringIO(), StringIO()
with self.assertRaises(SystemExit) as ctx:
cli.run((file, ))
self.assertEqual(ctx.exception.code, 1)
out, err = sys.stdout.getvalue(), sys.stderr.getvalue()
self.assertEqual(out, (
'%s\n'
' 2:4 error trailing spaces (trailing-spaces)\n'
' 3:4 error no new line character at the end of file '
'(new-line-at-end-of-file)\n'
'\n' % file))
self.assertEqual(err, '')
def test_run_colored_output(self):
file = os.path.join(self.wd, 'a.yaml')
# Create a pseudo-TTY and redirect stdout to it
master, slave = pty.openpty()
sys.stdout = sys.stderr = os.fdopen(slave, 'w')
with self.assertRaises(SystemExit) as ctx:
cli.run((file, ))
sys.stdout.flush()
self.assertEqual(ctx.exception.code, 1)
# Read output from TTY
output = os.fdopen(master, 'r')
flag = fcntl.fcntl(master, fcntl.F_GETFD)
fcntl.fcntl(master, fcntl.F_SETFL, flag | os.O_NONBLOCK)
out = output.read().replace('\r\n', '\n')
sys.stdout.close()
sys.stderr.close()
output.close()
self.assertEqual(out, (
'\033[4m%s\033[0m\n'
' \033[2m2:4\033[0m \033[31merror\033[0m '
'trailing spaces \033[2m(trailing-spaces)\033[0m\n'
' \033[2m3:4\033[0m \033[31merror\033[0m '
'no new line character at the end of file '
'\033[2m(new-line-at-end-of-file)\033[0m\n'
'\n' % file))
yamllint-1.10.0/tests/test_module.py 0000644 0002322 0002322 00000006644 13177553503 020053 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2017 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import os
import shutil
import subprocess
import tempfile
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
PYTHON = sys.executable or 'python'
@unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported')
class ModuleTestCase(unittest.TestCase):
def setUp(self):
self.wd = tempfile.mkdtemp(prefix='yamllint-tests-')
# file with only one warning
with open(os.path.join(self.wd, 'warn.yaml'), 'w') as f:
f.write('key: value\n')
# file in dir
os.mkdir(os.path.join(self.wd, 'sub'))
with open(os.path.join(self.wd, 'sub', 'nok.yaml'), 'w') as f:
f.write('---\n'
'list: [ 1, 1, 2, 3, 5, 8] \n')
def tearDown(self):
shutil.rmtree(self.wd)
def test_run_module_no_args(self):
with self.assertRaises(subprocess.CalledProcessError) as ctx:
subprocess.check_output([PYTHON, '-m', 'yamllint'],
stderr=subprocess.STDOUT)
self.assertEqual(ctx.exception.returncode, 2)
self.assertRegexpMatches(ctx.exception.output.decode(),
r'^usage: yamllint')
def test_run_module_on_bad_dir(self):
with self.assertRaises(subprocess.CalledProcessError) as ctx:
subprocess.check_output([PYTHON, '-m', 'yamllint',
'/does/not/exist'],
stderr=subprocess.STDOUT)
self.assertRegexpMatches(ctx.exception.output.decode(),
r'No such file or directory')
def test_run_module_on_file(self):
out = subprocess.check_output(
[PYTHON, '-m', 'yamllint', os.path.join(self.wd, 'warn.yaml')])
lines = out.decode().splitlines()
self.assertIn('/warn.yaml', lines[0])
self.assertEqual('\n'.join(lines[1:]),
' 1:1 warning missing document start "---"'
' (document-start)\n')
def test_run_module_on_dir(self):
with self.assertRaises(subprocess.CalledProcessError) as ctx:
subprocess.check_output([PYTHON, '-m', 'yamllint', self.wd])
self.assertEqual(ctx.exception.returncode, 1)
files = ctx.exception.output.decode().split('\n\n')
self.assertIn(
'/warn.yaml\n'
' 1:1 warning missing document start "---"'
' (document-start)',
files[0])
self.assertIn(
'/sub/nok.yaml\n'
' 2:9 error too many spaces inside brackets'
' (brackets)\n'
' 2:27 error trailing spaces (trailing-spaces)',
files[1])
yamllint-1.10.0/tests/test_yamllint_directives.py 0000644 0002322 0002322 00000030571 13177553503 022634 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class YamllintDirectivesTestCase(RuleTestCase):
conf = ('commas: disable\n'
'trailing-spaces: {}\n'
'colons: {max-spaces-before: 1}\n')
def test_disable_directive(self):
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(4, 8, 'colons'),
problem3=(6, 7, 'colons'),
problem4=(6, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'# yamllint disable\n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem=(3, 18, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint enable\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(8, 7, 'colons'),
problem2=(8, 26, 'trailing-spaces'))
def test_disable_directive_with_rules(self):
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'# yamllint disable rule:trailing-spaces\n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(5, 8, 'colons'),
problem3=(7, 7, 'colons'))
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable rule:trailing-spaces\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint enable rule:trailing-spaces\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(5, 8, 'colons'),
problem2=(8, 7, 'colons'),
problem3=(8, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable rule:trailing-spaces\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint enable\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(5, 8, 'colons'),
problem2=(8, 7, 'colons'),
problem3=(8, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint enable rule:trailing-spaces\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem=(8, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable rule:colons\n'
'- trailing spaces \n'
'# yamllint disable rule:trailing-spaces\n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint enable rule:colons\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(4, 18, 'trailing-spaces'),
problem2=(9, 7, 'colons'))
def test_disable_line_directive(self):
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'# yamllint disable-line\n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(7, 7, 'colons'),
problem3=(7, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon # yamllint disable-line\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(6, 7, 'colons'),
problem3=(6, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML] # yamllint disable-line\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(4, 8, 'colons'),
problem3=(6, 7, 'colons'),
problem4=(6, 26, 'trailing-spaces'))
def test_disable_line_directive_with_rules(self):
self.check('---\n'
'- [valid , YAML]\n'
'# yamllint disable-line rule:colons\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(4, 18, 'trailing-spaces'),
problem2=(5, 8, 'colons'),
problem3=(7, 7, 'colons'),
problem4=(7, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces # yamllint disable-line rule:colons \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 55, 'trailing-spaces'),
problem2=(4, 8, 'colons'),
problem3=(6, 7, 'colons'),
problem4=(6, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'# yamllint disable-line rule:colons\n'
'- bad : colon\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(7, 7, 'colons'),
problem3=(7, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon # yamllint disable-line rule:colons\n'
'- [valid , YAML]\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(6, 7, 'colons'),
problem3=(6, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint disable-line rule:colons\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(4, 8, 'colons'),
problem3=(7, 26, 'trailing-spaces'))
self.check('---\n'
'- [valid , YAML]\n'
'- trailing spaces \n'
'- bad : colon\n'
'- [valid , YAML]\n'
'# yamllint disable-line rule:colons rule:trailing-spaces\n'
'- bad : colon and spaces \n'
'- [valid , YAML]\n',
self.conf,
problem1=(3, 18, 'trailing-spaces'),
problem2=(4, 8, 'colons'))
def test_directive_on_last_line(self):
conf = 'new-line-at-end-of-file: {}'
self.check('---\n'
'no new line',
conf,
problem=(2, 12, 'new-line-at-end-of-file'))
self.check('---\n'
'# yamllint disable\n'
'no new line',
conf)
self.check('---\n'
'no new line # yamllint disable',
conf)
def test_indented_directive(self):
conf = 'brackets: {min-spaces-inside: 0, max-spaces-inside: 0}'
self.check('---\n'
'- a: 1\n'
' b:\n'
' c: [ x]\n',
conf,
problem=(4, 12, 'brackets'))
self.check('---\n'
'- a: 1\n'
' b:\n'
' # yamllint disable-line rule:brackets\n'
' c: [ x]\n',
conf)
def test_directive_on_itself(self):
conf = ('comments: {min-spaces-from-content: 2}\n'
'comments-indentation: {}\n')
self.check('---\n'
'- a: 1 # comment too close\n'
' b:\n'
' # wrong indentation\n'
' c: [x]\n',
conf,
problem1=(2, 8, 'comments'),
problem2=(4, 2, 'comments-indentation'))
self.check('---\n'
'# yamllint disable\n'
'- a: 1 # comment too close\n'
' b:\n'
' # wrong indentation\n'
' c: [x]\n',
conf)
self.check('---\n'
'- a: 1 # yamllint disable-line\n'
' b:\n'
' # yamllint disable-line\n'
' # wrong indentation\n'
' c: [x]\n',
conf)
self.check('---\n'
'- a: 1 # yamllint disable-line rule:comments\n'
' b:\n'
' # yamllint disable-line rule:comments-indentation\n'
' # wrong indentation\n'
' c: [x]\n',
conf)
self.check('---\n'
'# yamllint disable\n'
'- a: 1 # comment too close\n'
' # yamllint enable rule:comments-indentation\n'
' b:\n'
' # wrong indentation\n'
' c: [x]\n',
conf,
problem=(6, 2, 'comments-indentation'))
yamllint-1.10.0/tests/test_spec_examples.py 0000644 0002322 0002322 00000016620 13177553503 021411 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from io import open
import os
from tests.common import RuleTestCase
# This file checks examples from YAML 1.2 specification [1] against yamllint.
#
# [1]: http://www.yaml.org/spec/1.2/spec.html
#
# Example files generated with:
#
# from bs4 import BeautifulSoup
# with open('spec.html', encoding='iso-8859-1') as f:
# soup = BeautifulSoup(f, 'lxml')
# for ex in soup.find_all('div', class_='example'):
# title = ex.find('p', class_='title').find('b').get_text()
# id = '-'.join(title.split('\xa0')[:2])[:-1].lower()
# span = ex.find('span', class_='database')
# for br in span.find_all("br"):
# br.replace_with("\n")
# text = text.replace('\u2193', '') # downwards arrow
# text = text.replace('\u21d3', '') # double downwards arrow
# text = text.replace('\u00b7', ' ') # visible space
# text = text.replace('\u21d4', '') # byte order mark
# text = text.replace('\u2192', '\t') # right arrow
# text = text.replace('\u00b0', '') # empty scalar
# with open('tests/yaml-1.2-spec-examples/%s' % id, 'w',
# encoding='utf-8') as g:
# g.write(text)
class SpecificationTestCase(RuleTestCase):
rule_id = None
conf_general = ('document-start: disable\n'
'comments: {min-spaces-from-content: 1}\n'
'braces: {min-spaces-inside: 1, max-spaces-inside: 1}\n'
'brackets: {min-spaces-inside: 1, max-spaces-inside: 1}\n')
conf_overrides = {
'example-2.2': ('colons: {max-spaces-after: 2}\n'),
'example-2.4': ('colons: {max-spaces-after: 3}\n'),
'example-2.5': ('empty-lines: {max-end: 2}\n'
'brackets: {min-spaces-inside: 0, max-spaces-inside: 2}\n'
'commas: {max-spaces-before: -1}\n'),
'example-2.6': ('braces: {min-spaces-inside: 0, max-spaces-inside: 0}\n'
'indentation: disable\n'),
'example-2.12': ('empty-lines: {max-end: 1}\n'
'colons: {max-spaces-before: -1}\n'),
'example-2.16': ('empty-lines: {max-end: 1}\n'),
'example-2.18': ('empty-lines: {max-end: 1}\n'),
'example-2.19': ('empty-lines: {max-end: 1}\n'),
'example-2.28': ('empty-lines: {max-end: 3}\n'),
'example-5.3': ('indentation: {indent-sequences: false}\n'
'colons: {max-spaces-before: 1}\n'),
'example-6.4': ('trailing-spaces: disable\n'),
'example-6.5': ('trailing-spaces: disable\n'),
'example-6.6': ('trailing-spaces: disable\n'),
'example-6.7': ('trailing-spaces: disable\n'),
'example-6.8': ('trailing-spaces: disable\n'),
'example-6.10': ('empty-lines: {max-end: 2}\n'
'trailing-spaces: disable\n'
'comments-indentation: disable\n'),
'example-6.11': ('empty-lines: {max-end: 1}\n'
'comments-indentation: disable\n'),
'example-6.13': ('comments-indentation: disable\n'),
'example-6.14': ('comments-indentation: disable\n'),
'example-6.23': ('colons: {max-spaces-before: 1}\n'),
'example-7.4': ('colons: {max-spaces-before: 1}\n'
'indentation: disable\n'),
'example-7.5': ('trailing-spaces: disable\n'),
'example-7.6': ('trailing-spaces: disable\n'),
'example-7.7': ('indentation: disable\n'),
'example-7.8': ('colons: {max-spaces-before: 1}\n'
'indentation: disable\n'),
'example-7.9': ('trailing-spaces: disable\n'),
'example-7.11': ('colons: {max-spaces-before: 1}\n'
'indentation: disable\n'),
'example-7.13': ('brackets: {min-spaces-inside: 0, max-spaces-inside: 1}\n'
'commas: {max-spaces-before: 1, min-spaces-after: 0}\n'),
'example-7.14': ('indentation: disable\n'),
'example-7.15': ('braces: {min-spaces-inside: 0, max-spaces-inside: 1}\n'
'commas: {max-spaces-before: 1, min-spaces-after: 0}\n'
'colons: {max-spaces-before: 1}\n'),
'example-7.16': ('indentation: disable\n'),
'example-7.17': ('indentation: disable\n'),
'example-7.18': ('indentation: disable\n'),
'example-7.19': ('indentation: disable\n'),
'example-7.20': ('colons: {max-spaces-before: 1}\n'
'indentation: disable\n'),
'example-8.1': ('empty-lines: {max-end: 1}\n'),
'example-8.2': ('trailing-spaces: disable\n'),
'example-8.5': ('comments-indentation: disable\n'
'trailing-spaces: disable\n'),
'example-8.6': ('empty-lines: {max-end: 1}\n'),
'example-8.7': ('empty-lines: {max-end: 1}\n'),
'example-8.8': ('trailing-spaces: disable\n'),
'example-8.9': ('empty-lines: {max-end: 1}\n'),
'example-8.14': ('colons: {max-spaces-before: 1}\n'),
'example-8.16': ('indentation: {spaces: 1}\n'),
'example-8.17': ('indentation: disable\n'),
'example-8.20': ('indentation: {indent-sequences: false}\n'
'colons: {max-spaces-before: 1}\n'),
'example-8.22': ('indentation: disable\n'),
'example-10.1': ('colons: {max-spaces-before: 2}\n'),
'example-10.2': ('indentation: {indent-sequences: false}\n'),
'example-10.8': ('truthy: disable\n'),
'example-10.9': ('truthy: disable\n'),
}
files = os.listdir(os.path.join(os.path.dirname(os.path.realpath(__file__)),
'yaml-1.2-spec-examples'))
assert len(files) == 132
def _gen_test(buffer, conf):
def test(self):
self.check(buffer, conf)
return test
# The following tests are blacklisted (i.e. will not be checked against
# yamllint), because pyyaml is currently not able to parse the contents
# (using yaml.parse()).
pyyaml_blacklist = (
'example-2.11',
'example-2.23',
'example-2.24',
'example-2.27',
'example-5.10',
'example-5.12',
'example-5.13',
'example-5.14',
'example-5.6',
'example-6.1',
'example-6.12',
'example-6.15',
'example-6.17',
'example-6.18',
'example-6.19',
'example-6.2',
'example-6.20',
'example-6.21',
'example-6.22',
'example-6.24',
'example-6.25',
'example-6.26',
'example-6.27',
'example-6.3',
'example-7.1',
'example-7.10',
'example-7.12',
'example-7.17',
'example-7.2',
'example-7.21',
'example-7.22',
'example-7.3',
'example-8.18',
'example-8.19',
'example-8.21',
'example-8.3',
'example-9.3',
'example-9.4',
'example-9.5',
)
for file in files:
if file in pyyaml_blacklist:
continue
with open('tests/yaml-1.2-spec-examples/' + file, encoding='utf-8') as f:
conf = conf_general + conf_overrides.get(file, '')
setattr(SpecificationTestCase, 'test_' + file,
_gen_test(f.read(), conf))
yamllint-1.10.0/tests/common.py 0000644 0002322 0002322 00000004600 13177553503 017005 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import os
import tempfile
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
import yaml
from yamllint.config import YamlLintConfig
from yamllint import linter
class RuleTestCase(unittest.TestCase):
def build_fake_config(self, conf):
if conf is None:
conf = {}
else:
conf = yaml.safe_load(conf)
conf = {'extends': 'default',
'rules': conf}
return YamlLintConfig(yaml.safe_dump(conf))
def check(self, source, conf, **kwargs):
expected_problems = []
for key in kwargs:
assert key.startswith('problem')
if len(kwargs[key]) > 2:
if kwargs[key][2] == 'syntax':
rule_id = None
else:
rule_id = kwargs[key][2]
else:
rule_id = self.rule_id
expected_problems.append(linter.LintProblem(
kwargs[key][0], kwargs[key][1], rule=rule_id))
expected_problems.sort()
real_problems = list(linter.run(source, self.build_fake_config(conf)))
self.assertEqual(real_problems, expected_problems)
def build_temp_workspace(files):
tempdir = tempfile.mkdtemp(prefix='yamllint-tests-')
for path, content in files.items():
path = os.path.join(tempdir, path)
if not os.path.exists(os.path.dirname(path)):
os.makedirs(os.path.dirname(path))
if type(content) is list:
os.mkdir(path)
else:
mode = 'wb' if isinstance(content, bytes) else 'w'
with open(path, mode) as f:
f.write(content)
return tempdir
yamllint-1.10.0/tests/__init__.py 0000644 0002322 0002322 00000001355 13177553503 017260 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import locale
locale.setlocale(locale.LC_ALL, 'C')
yamllint-1.10.0/tests/yaml-1.2-spec-examples/ 0000755 0002322 0002322 00000000000 13177553503 021147 5 ustar debalance debalance yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.4 0000644 0002322 0002322 00000000101 13177553503 023075 0 ustar debalance debalance !!null null: value for null key
key with null value: !!null null
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.14 0000644 0002322 0002322 00000000077 13177553503 023113 0 ustar debalance debalance --- >
Mark McGwire's
year was crippled
by a knee injury.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.23 0000644 0002322 0002322 00000000046 13177553503 023114 0 ustar debalance debalance - [ a, b ]
- { a: b }
- "a"
- 'b'
- c
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.8 0000644 0002322 0002322 00000000034 13177553503 023033 0 ustar debalance debalance "
foo
bar
baz
"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.21 0000644 0002322 0002322 00000000145 13177553503 023111 0 ustar debalance debalance %TAG !m! !my-
--- # Bulb here
!m!light fluorescent
...
%TAG !m! !my-
--- # Color here
!m!light green
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.13 0000644 0002322 0002322 00000000131 13177553503 023104 0 ustar debalance debalance "Fun with \\
\" \a \b \e \f \
\n \r \t \v \0 \
\ \_ \N \L \P \
\x41 \u0041 \U00000041"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.21 0000644 0002322 0002322 00000000060 13177553503 023107 0 ustar debalance debalance literal: |2
value
folded:
!foo
>1
value
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.8 0000644 0002322 0002322 00000000073 13177553503 023037 0 ustar debalance debalance 'implicit block key' : [
'implicit flow key' : value,
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.14 0000644 0002322 0002322 00000000050 13177553503 023110 0 ustar debalance debalance block sequence:
- one
- two : three
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.2 0000644 0002322 0002322 00000000202 13177553503 023075 0 ustar debalance debalance Block style: !!seq
- Clark Evans
- Ingy döt Net
- Oren Ben-Kiki
Flow style: !!seq [ Clark Evans, Ingy döt Net, Oren Ben-Kiki ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.13 0000644 0002322 0002322 00000000115 13177553503 023107 0 ustar debalance debalance %FOO bar baz # Should be ignored
# with a warning.
--- "foo"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.18 0000644 0002322 0002322 00000000076 13177553503 023124 0 ustar debalance debalance plain key: in-line value
: # Both empty
"quoted key":
- entry
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.5 0000644 0002322 0002322 00000000074 13177553503 023037 0 ustar debalance debalance %YAML 1.2
--- |
%!PS-Adobe-2.0
...
%YAML1.2
---
# Empty
...
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.15 0000644 0002322 0002322 00000000074 13177553503 023116 0 ustar debalance debalance - { one : two , three: four , }
- {five: six,seven : eight}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.10 0000644 0002322 0002322 00000000177 13177553503 023110 0 ustar debalance debalance ---
hr:
- Mark McGwire
# Following node labeled SS
- &SS Sammy Sosa
rbi:
- *SS # Subsequent occurrence
- Ken Griffey
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.3 0000644 0002322 0002322 00000000051 13177553503 023027 0 ustar debalance debalance - |
text
- >
text
text
- |2
text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.16 0000644 0002322 0002322 00000000063 13177553503 023114 0 ustar debalance debalance %TAG !yaml! tag:yaml.org,2002:
---
!yaml!str "foo"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.5 0000644 0002322 0002322 00000000077 13177553503 023040 0 ustar debalance debalance "folded
to a space,
to a line feed, or \
\ non-content"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.3 0000644 0002322 0002322 00000000034 13177553503 023026 0 ustar debalance debalance - foo: bar
- - baz
- baz
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.17 0000644 0002322 0002322 00000000112 13177553503 023111 0 ustar debalance debalance {
unquoted : "separate",
http://foo.com,
omitted value:,
: omitted key,
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.7 0000644 0002322 0002322 00000000157 13177553503 023113 0 ustar debalance debalance negative: !!float -1
zero: !!float 0
positive: !!float 2.3e4
infinity: !!float .inf
not a number: !!float .nan
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.27 0000644 0002322 0002322 00000001204 13177553503 023110 0 ustar debalance debalance --- !
invoice: 34843
date : 2001-01-23
bill-to: &id001
given : Chris
family : Dumars
address:
lines: |
458 Walkman Dr.
Suite #292
city : Royal Oak
state : MI
postal : 48046
ship-to: *id001
product:
- sku : BL394D
quantity : 4
description : Basketball
price : 450.00
- sku : BL4438H
quantity : 1
description : Super Hoop
price : 2392.00
tax : 251.42
total: 4443.52
comments:
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.9 0000644 0002322 0002322 00000000021 13177553503 023032 0 ustar debalance debalance >
folded
text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.20 0000644 0002322 0002322 00000000152 13177553503 023102 0 ustar debalance debalance canonical: 1.23015e+3
exponential: 12.3015e+02
fixed: 1230.15
negative infinity: -.inf
not a number: .NaN
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.12 0000644 0002322 0002322 00000000056 13177553503 023113 0 ustar debalance debalance 1st non-empty
2nd non-empty
3rd non-empty
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.28 0000644 0002322 0002322 00000000067 13177553503 023123 0 ustar debalance debalance # Assuming conventional resolution:
- "12"
- 12
- ! 12
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.28 0000644 0002322 0002322 00000000636 13177553503 023121 0 ustar debalance debalance ---
Time: 2001-11-23 15:01:42 -5
User: ed
Warning:
This is an error message
for the log file
---
Time: 2001-11-23 15:02:31 -5
User: ed
Warning:
A slightly different error
message.
---
Date: 2001-11-23 15:03:17 -5
User: ed
Fatal:
Unknown variable "bar"
Stack:
- file: TopClass.py
line: 23
code: |
x = MoreObject("345\n")
- file: MoreClass.py
line: 58
code: |-
foo = bar
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.4 0000644 0002322 0002322 00000000106 13177553503 023027 0 ustar debalance debalance plain: text
lines
quoted: "text
lines"
block: |
text
lines
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.29 0000644 0002322 0002322 00000000073 13177553503 023121 0 ustar debalance debalance First occurrence: &anchor Value
Second occurrence: *anchor
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.8 0000644 0002322 0002322 00000000053 13177553503 023036 0 ustar debalance debalance |
literal
text
# Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.1 0000644 0002322 0002322 00000000033 13177553503 023026 0 ustar debalance debalance # Comment
# lines
Document
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.6 0000644 0002322 0002322 00000000056 13177553503 023034 0 ustar debalance debalance anchored: !local &anchor value
alias: *anchor
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.23 0000644 0002322 0002322 00000000411 13177553503 023103 0 ustar debalance debalance ---
not-date: !!str 2002-04-28
picture: !!binary |
R0lGODlhDAAMAIQAAP//9/X
17unp5WZmZgAAAOfn515eXv
Pz7Y6OjuDg4J+fn5OTk6enp
56enmleECcgggoBADs=
application specific tag: !something |
The semantics of the tag
above may be different for
different documents.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.14 0000644 0002322 0002322 00000000131 13177553503 023107 0 ustar debalance debalance [
"double
quoted", 'single
quoted',
plain
text, [ nested ],
single: pair,
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.1 0000644 0002322 0002322 00000000052 13177553503 023020 0 ustar debalance debalance - Mark McGwire
- Sammy Sosa
- Ken Griffey
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.2 0000644 0002322 0002322 00000000034 13177553503 023025 0 ustar debalance debalance ? a
: - b
- - c
- d
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.24 0000644 0002322 0002322 00000000055 13177553503 023114 0 ustar debalance debalance ! foo :
! baz
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.27 0000644 0002322 0002322 00000000072 13177553503 023116 0 ustar debalance debalance %TAG !e! tag:example,2000:app/
---
- !e! foo
- !h!bar baz
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.18 0000644 0002322 0002322 00000000136 13177553503 023113 0 ustar debalance debalance plain:
This unquoted scalar
spans many lines.
quoted: "So does this
quoted scalar.\n"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.3 0000644 0002322 0002322 00000000133 13177553503 023101 0 ustar debalance debalance Block style: !!str |-
String: just a theory.
Flow style: !!str "String: just a theory."
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.13 0000644 0002322 0002322 00000000126 13177553503 023113 0 ustar debalance debalance >
folded
line
next
line
* bullet
* list
* line
last
line
# Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.4 0000644 0002322 0002322 00000000073 13177553503 023031 0 ustar debalance debalance sequence: [ one, two, ]
mapping: { sky: blue, sea: green }
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.9 0000644 0002322 0002322 00000000313 13177553503 023107 0 ustar debalance debalance A null: null
Also a null: # Empty
Not a null: ""
Booleans: [ true, True, false, FALSE ]
Integers: [ 0, 0o7, 0x3A, -19 ]
Floats: [ 0., -0.0, .5, +12e03, -2E+05 ]
Also floats: [ .inf, -.Inf, +.INF, .NAN ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.16 0000644 0002322 0002322 00000000033 13177553503 023113 0 ustar debalance debalance block mapping:
key: value
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.15 0000644 0002322 0002322 00000000030 13177553503 023105 0 ustar debalance debalance %YAML 1.2
%YAML 1.1
foo
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.15 0000644 0002322 0002322 00000000170 13177553503 023106 0 ustar debalance debalance >
Sammy Sosa completed another
fine season with great stats.
63 Home Runs
0.288 Batting Average
What a year!
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.9 0000644 0002322 0002322 00000000163 13177553503 023033 0 ustar debalance debalance ---
hr: # 1998 hr ranking
- Mark McGwire
- Sammy Sosa
rbi:
# 1998 rbi ranking
- Sammy Sosa
- Ken Griffey
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.11 0000644 0002322 0002322 00000000216 13177553503 023103 0 ustar debalance debalance ? - Detroit Tigers
- Chicago cubs
:
- 2001-07-23
? [ New York Yankees,
Atlanta Braves ]
: [ 2001-07-02, 2001-08-12,
2001-08-14 ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.3 0000644 0002322 0002322 00000000112 13177553503 023026 0 ustar debalance debalance Bare
document
...
# No document
...
|
%!PS-Adobe-2.0 # Not the first line
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.19 0000644 0002322 0002322 00000000077 13177553503 023120 0 ustar debalance debalance canonical: 12345
decimal: +12345
octal: 0o14
hexadecimal: 0xC
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.23 0000644 0002322 0002322 00000000053 13177553503 023111 0 ustar debalance debalance !!str &a1 "foo":
!!str bar
&a2 baz : *a1
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.9 0000644 0002322 0002322 00000000062 13177553503 023036 0 ustar debalance debalance ' 1st non-empty
2nd non-empty
3rd non-empty '
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.12 0000644 0002322 0002322 00000000141 13177553503 023105 0 ustar debalance debalance { first: Sammy, last: Sosa }:
# Statistics:
hr: # Home runs
65
avg: # Average
0.278
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.12 0000644 0002322 0002322 00000000210 13177553503 023076 0 ustar debalance debalance ---
# Products purchased
- item : Super Hoop
quantity: 1
- item : Basketball
quantity: 4
- item : Big Shoes
quantity: 1
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.2 0000644 0002322 0002322 00000000105 13177553503 023026 0 ustar debalance debalance - |
detected
- >
# detected
- |1
explicit
- >
detected
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.18 0000644 0002322 0002322 00000000122 13177553503 023112 0 ustar debalance debalance # Private
!foo "bar"
...
# Global
%TAG ! tag:example.com,2000:app/
---
!foo "bar"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.17 0000644 0002322 0002322 00000000261 13177553503 023111 0 ustar debalance debalance unicode: "Sosa did fine.\u263A"
control: "\b1998\t1999\t2000\n"
hex esc: "\x0d\x0a is \r\n"
single: '"Howdy!" he cried.'
quoted: ' # Not a ''comment''.'
tie-fighter: '|\-*-/|'
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.22 0000644 0002322 0002322 00000000173 13177553503 023107 0 ustar debalance debalance canonical: 2001-12-15T02:59:43.1Z
iso8601: 2001-12-14t21:59:43.10-05:00
spaced: 2001-12-14 21:59:43.10 -5
date: 2002-12-14
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.1 0000644 0002322 0002322 00000000020 13177553503 023016 0 ustar debalance debalance # Comment only.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.1 0000644 0002322 0002322 00000000204 13177553503 023025 0 ustar debalance debalance - | # Empty header
literal
- >1 # Indentation indicator
folded
- |+ # Chomping indicator
keep
- >1- # Both indicators
strip
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.11 0000644 0002322 0002322 00000000067 13177553503 023114 0 ustar debalance debalance implicit block key : [
implicit flow key : value,
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.2 0000644 0002322 0002322 00000000044 13177553503 023031 0 ustar debalance debalance %YAML 1.2
---
Document
... # Suffix
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.4 0000644 0002322 0002322 00000000136 13177553503 023026 0 ustar debalance debalance -
name: Mark McGwire
hr: 65
avg: 0.278
-
name: Sammy Sosa
hr: 63
avg: 0.288
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.21 0000644 0002322 0002322 00000000112 13177553503 023104 0 ustar debalance debalance - [ YAML : separate ]
- [ : empty key entry ]
- [ {JSON: like}:adjacent ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.8 0000644 0002322 0002322 00000000221 13177553503 023104 0 ustar debalance debalance A null: null
Booleans: [ true, false ]
Integers: [ 0, -0, 3, -19 ]
Floats: [ 0., -0.0, 12e03, -2E+05 ]
Invalid: [ True, Null, 0o7, 0x3A, +12.3 ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.5 0000644 0002322 0002322 00000000110 13177553503 023076 0 ustar debalance debalance YAML is a superset of JSON: !!bool true
Pluto is a planet: !!bool false
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.19 0000644 0002322 0002322 00000000015 13177553503 023115 0 ustar debalance debalance [
foo: bar
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.16 0000644 0002322 0002322 00000000052 13177553503 023113 0 ustar debalance debalance {
? explicit: entry,
implicit: entry,
?
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.5 0000644 0002322 0002322 00000000230 13177553503 023030 0 ustar debalance debalance # Strip
# Comments:
strip: |-
# text
# Clip
# comments:
clip: |
# text
# Keep
# comments:
keep: |+
# text
# Trail
# comments.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.4 0000644 0002322 0002322 00000000053 13177553503 023033 0 ustar debalance debalance ---
{ matches
% : 20 }
...
---
# Empty
...
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.8 0000644 0002322 0002322 00000000175 13177553503 023035 0 ustar debalance debalance ---
time: 20:03:20
player: Sammy Sosa
action: strike (miss)
...
---
time: 20:03:47
player: Sammy Sosa
action: grand slam
...
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.14 0000644 0002322 0002322 00000000033 13177553503 023106 0 ustar debalance debalance Bad escapes:
"\c
\xq-"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.6 0000644 0002322 0002322 00000000120 13177553503 023021 0 ustar debalance debalance Mark McGwire: {hr: 65, avg: 0.278}
Sammy Sosa: {
hr: 63,
avg: 0.288
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.6 0000644 0002322 0002322 00000000040 13177553503 023026 0 ustar debalance debalance >-
trimmed
as
space
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.26 0000644 0002322 0002322 00000000237 13177553503 023114 0 ustar debalance debalance # Ordered maps are represented as
# A sequence of mappings, with
# each mapping having one key
--- !!omap
- Mark McGwire: 65
- Sammy Sosa: 63
- Ken Griffy: 58
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.1 0000644 0002322 0002322 00000000154 13177553503 023030 0 ustar debalance debalance First occurrence: &anchor Foo
Second occurrence: *anchor
Override anchor: &anchor Bar
Reuse anchor: *anchor
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.5 0000644 0002322 0002322 00000000122 13177553503 023026 0 ustar debalance debalance Folding:
"Empty line
as a line feed"
Chomping: |
Clipped empty lines
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.20 0000644 0002322 0002322 00000000064 13177553503 023110 0 ustar debalance debalance %TAG !e! tag:example.com,2000:app/
---
!e!foo "bar"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.19 0000644 0002322 0002322 00000000112 13177553503 023112 0 ustar debalance debalance %TAG !! tag:example.com,2000:app/
---
!!int 1 - 3 # Interval, not integer
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.4 0000644 0002322 0002322 00000000073 13177553503 023033 0 ustar debalance debalance "implicit block key" : [
"implicit flow key" : value,
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.12 0000644 0002322 0002322 00000000140 13177553503 023103 0 ustar debalance debalance # Tabs and spaces
quoted: "Quoted "
block: |
void main() {
printf("Hello, world!\n");
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.26 0000644 0002322 0002322 00000000120 13177553503 023107 0 ustar debalance debalance %TAG !e! tag:example.com,2000:app/
---
- !local foo
- !!str bar
- !e!tag%21 baz
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.2 0000644 0002322 0002322 00000000042 13177553503 023025 0 ustar debalance debalance {
foo : !!str,
!!str : bar,
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.10 0000644 0002322 0002322 00000000130 13177553503 023103 0 ustar debalance debalance >
folded
line
next
line
* bullet
* list
* lines
last
line
# Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.4 0000644 0002322 0002322 00000000060 13177553503 023030 0 ustar debalance debalance strip: |-
text
clip: |
text
keep: |+
text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.9 0000644 0002322 0002322 00000000035 13177553503 023035 0 ustar debalance debalance key: # Comment
valueeof
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.7 0000644 0002322 0002322 00000000023 13177553503 023032 0 ustar debalance debalance |
literal
text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.19 0000644 0002322 0002322 00000000056 13177553503 023123 0 ustar debalance debalance - sun: yellow
- ? earth: blue
: moon: white
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.17 0000644 0002322 0002322 00000000034 13177553503 023113 0 ustar debalance debalance %TAG ! !foo
%TAG ! !foo
bar
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.11 0000644 0002322 0002322 00000000130 13177553503 023104 0 ustar debalance debalance >
folded
line
next
line
* bullet
* list
* lines
last
line
# Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.14 0000644 0002322 0002322 00000000102 13177553503 023104 0 ustar debalance debalance %YAML 1.3 # Attempt parsing
# with a warning
---
"foo"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.3 0000644 0002322 0002322 00000000076 13177553503 023033 0 ustar debalance debalance sequence:
- one
- two
mapping:
? sky
: blue
sea : green
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.10 0000644 0002322 0002322 00000000332 13177553503 023106 0 ustar debalance debalance # Outside flow collection:
- ::vector
- ": - ()"
- Up, up, and away!
- -123
- http://example.com/foo#bar
# Inside flow collection:
- [ ::vector,
": - ()",
"Up, up and away!",
-123,
http://example.com/foo#bar ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.5 0000644 0002322 0002322 00000000020 13177553503 023022 0 ustar debalance debalance # Comment only.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.10 0000644 0002322 0002322 00000000051 13177553503 023102 0 ustar debalance debalance commercial-at: @text
grave-accent: `text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.12 0000644 0002322 0002322 00000000127 13177553503 023113 0 ustar debalance debalance >
folded
line
next
line
* bullet
* list
* line
last
line
# Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.7 0000644 0002322 0002322 00000000027 13177553503 023035 0 ustar debalance debalance 'here''s to "quotes"'
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.25 0000644 0002322 0002322 00000000030 13177553503 023106 0 ustar debalance debalance - ! foo
- !<$:?> bar
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.6 0000644 0002322 0002322 00000000062 13177553503 023033 0 ustar debalance debalance " 1st non-empty
2nd non-empty
3rd non-empty "
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.25 0000644 0002322 0002322 00000000211 13177553503 023103 0 ustar debalance debalance # Sets are represented as a
# Mapping where each key is
# associated with a null value
--- !!set
? Mark McGwire
? Sammy Sosa
? Ken Griff
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.7 0000644 0002322 0002322 00000000061 13177553503 023031 0 ustar debalance debalance literal: |
some
text
folded: >
some
text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.22 0000644 0002322 0002322 00000000076 13177553503 023116 0 ustar debalance debalance [ foo
bar: invalid,
"foo...>1K characters...bar": invalid ]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.7 0000644 0002322 0002322 00000000032 13177553503 023030 0 ustar debalance debalance >
foo
bar
baz
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.20 0000644 0002322 0002322 00000000115 13177553503 023107 0 ustar debalance debalance -
"flow in block"
- >
Block scalar
- !!map # Block collection
foo : bar
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.1 0000644 0002322 0002322 00000000215 13177553503 023100 0 ustar debalance debalance Block style: !!map
Clark : Evans
Ingy : döt Net
Oren : Ben-Kiki
Flow style: !!map { Clark: Evans, Ingy: döt Net, Oren: Ben-Kiki }
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.2 0000644 0002322 0002322 00000000120 13177553503 023015 0 ustar debalance debalance hr: 65 # Home runs
avg: 0.278 # Batting average
rbi: 147 # Runs Batted In
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.15 0000644 0002322 0002322 00000000134 13177553503 023114 0 ustar debalance debalance - # Empty
- |
block node
- - one # Compact
- two # sequence
- one: two # Compact mapping
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.20 0000644 0002322 0002322 00000000025 13177553503 023106 0 ustar debalance debalance [
? foo
bar : baz
]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.6 0000644 0002322 0002322 00000000036 13177553503 023035 0 ustar debalance debalance strip: >-
clip: >
keep: |+
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.17 0000644 0002322 0002322 00000000136 13177553503 023120 0 ustar debalance debalance ? explicit key # Empty value
? |
block key
: - one # Explicit compact
- two # block value
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.24 0000644 0002322 0002322 00000000452 13177553503 023111 0 ustar debalance debalance %TAG ! tag:clarkevans.com,2002:
--- !shape
# Use the ! handle for presenting
# tag:clarkevans.com,2002:circle
- !circle
center: &ORIGIN {x: 73, y: 129}
radius: 7
- !line
start: *ORIGIN
finish: { x: 89, y: 102 }
- !label
start: *ORIGIN
color: 0xFFEEBB
text: Pretty vector drawing.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.1 0000644 0002322 0002322 00000000455 13177553503 023033 0 ustar debalance debalance # Leading comment line spaces are
# neither content nor indentation.
Not indented:
By one space: |
By four
spaces
Flow style: [ # Leading spaces
By two, # in flow style
Also by two, # are neither
Still by two # content nor
] # indentation.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.16 0000644 0002322 0002322 00000000213 13177553503 023105 0 ustar debalance debalance name: Mark McGwire
accomplishment: >
Mark set a major league
home run record in 1998.
stats: |
65 Home Runs
0.278 Batting Average
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.3 0000644 0002322 0002322 00000000205 13177553503 023022 0 ustar debalance debalance american:
- Boston Red Sox
- Detroit Tigers
- New York Yankees
national:
- New York Mets
- Chicago Cubs
- Atlanta Braves
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.2 0000644 0002322 0002322 00000000053 13177553503 023025 0 ustar debalance debalance - Invalid use of BOM
- Inside a document.
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-9.6 0000644 0002322 0002322 00000000065 13177553503 023040 0 ustar debalance debalance Document
---
# Empty
...
%YAML 1.2
---
matches %: 20
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.24 0000644 0002322 0002322 00000000062 13177553503 023113 0 ustar debalance debalance - !!str "a"
- 'b'
- &anchor "c"
- *anchor
- !!str
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-10.6 0000644 0002322 0002322 00000000065 13177553503 023110 0 ustar debalance debalance negative: !!int -12
zero: !!int 0
positive: !!int 34
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.9 0000644 0002322 0002322 00000000023 13177553503 023031 0 ustar debalance debalance %YAML 1.2
--- text
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.13 0000644 0002322 0002322 00000000054 13177553503 023105 0 ustar debalance debalance # ASCII Art
--- |
\//||\/||
// || ||__
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.22 0000644 0002322 0002322 00000000066 13177553503 023114 0 ustar debalance debalance %TAG !e! tag:example.com,2000:app/
---
- !e!foo "bar"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.5 0000644 0002322 0002322 00000000126 13177553503 023026 0 ustar debalance debalance - [name , hr, avg ]
- [Mark McGwire, 65, 0.278]
- [Sammy Sosa , 63, 0.288]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.10 0000644 0002322 0002322 00000000021 13177553503 023100 0 ustar debalance debalance # Comment
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.21 0000644 0002322 0002322 00000000061 13177553503 023102 0 ustar debalance debalance null:
booleans: [ true, false ]
string: '012345'
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.18 0000644 0002322 0002322 00000000062 13177553503 023116 0 ustar debalance debalance {
"adjacent":value,
"readable": value,
"empty":
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-8.22 0000644 0002322 0002322 00000000103 13177553503 023106 0 ustar debalance debalance sequence: !!seq
- entry
- !!seq
- nested
mapping: !!map
foo: bar
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.8 0000644 0002322 0002322 00000000036 13177553503 023034 0 ustar debalance debalance single: 'text'
double: "text"
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-5.11 0000644 0002322 0002322 00000000061 13177553503 023104 0 ustar debalance debalance |
Line break (no glyph)
Line break (glyphed)
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.3 0000644 0002322 0002322 00000000030 13177553503 023023 0 ustar debalance debalance {
? foo :,
: bar,
}
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-2.7 0000644 0002322 0002322 00000000202 13177553503 023023 0 ustar debalance debalance # Ranking of 1998 home runs
---
- Mark McGwire
- Sammy Sosa
- Ken Griffey
# Team ranking
---
- Chicago Cubs
- St Louis Cardinals
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-7.13 0000644 0002322 0002322 00000000040 13177553503 023105 0 ustar debalance debalance - [ one, two, ]
- [three ,four]
yamllint-1.10.0/tests/yaml-1.2-spec-examples/example-6.11 0000644 0002322 0002322 00000000053 13177553503 023106 0 ustar debalance debalance key: # Comment
# lines
value
yamllint-1.10.0/tests/test_syntax_errors.py 0000644 0002322 0002322 00000006075 13177553503 021506 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class YamlLintTestCase(RuleTestCase):
rule_id = None # syntax error
def test_syntax_errors(self):
self.check('---\n'
'this is not: valid: YAML\n', None, problem=(2, 19))
self.check('---\n'
'this is: valid YAML\n'
'\n'
'this is an error: [\n'
'\n'
'...\n', None, problem=(6, 1))
self.check('%YAML 1.2\n'
'%TAG ! tag:clarkevans.com,2002:\n'
'doc: ument\n'
'...\n', None, problem=(3, 1))
def test_empty_flows(self):
self.check('---\n'
'- []\n'
'- {}\n'
'- [\n'
']\n'
'- {\n'
'}\n'
'...\n', None)
def test_explicit_mapping(self):
self.check('---\n'
'? key\n'
': - value 1\n'
' - value 2\n'
'...\n', None)
self.check('---\n'
'?\n'
' key\n'
': {a: 1}\n'
'...\n', None)
self.check('---\n'
'?\n'
' key\n'
':\n'
' val\n'
'...\n', None)
def test_mapping_between_sequences(self):
# This is valid YAML. See http://www.yaml.org/spec/1.2/spec.html,
# example 2.11
self.check('---\n'
'? - Detroit Tigers\n'
' - Chicago cubs\n'
':\n'
' - 2001-07-23\n'
'\n'
'? [New York Yankees,\n'
' Atlanta Braves]\n'
': [2001-07-02, 2001-08-12,\n'
' 2001-08-14]\n', None)
def test_sets(self):
self.check('---\n'
'? key one\n'
'? key two\n'
'? [non, scalar, key]\n'
'? key with value\n'
': value\n'
'...\n', None)
self.check('---\n'
'? - multi\n'
' - line\n'
' - keys\n'
'? in:\n'
' a:\n'
' set\n'
'...\n', None)
yamllint-1.10.0/tests/test_parser.py 0000644 0002322 0002322 00000015172 13177553503 020056 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
import yaml
from yamllint.parser import (line_generator, token_or_comment_generator,
token_or_comment_or_line_generator,
Line, Token, Comment)
class ParserTestCase(unittest.TestCase):
def test_line_generator(self):
e = list(line_generator(''))
self.assertEqual(len(e), 1)
self.assertEqual(e[0].line_no, 1)
self.assertEqual(e[0].start, 0)
self.assertEqual(e[0].end, 0)
e = list(line_generator('\n'))
self.assertEqual(len(e), 2)
e = list(line_generator(' \n'))
self.assertEqual(len(e), 2)
self.assertEqual(e[0].line_no, 1)
self.assertEqual(e[0].start, 0)
self.assertEqual(e[0].end, 1)
e = list(line_generator('\n\n'))
self.assertEqual(len(e), 3)
e = list(line_generator('---\n'
'this is line 1\n'
'line 2\n'
'\n'
'3\n'))
self.assertEqual(len(e), 6)
self.assertEqual(e[0].line_no, 1)
self.assertEqual(e[0].content, '---')
self.assertEqual(e[2].content, 'line 2')
self.assertEqual(e[3].content, '')
self.assertEqual(e[5].line_no, 6)
e = list(line_generator('test with\n'
'no newline\n'
'at the end'))
self.assertEqual(len(e), 3)
self.assertEqual(e[2].line_no, 3)
self.assertEqual(e[2].content, 'at the end')
def test_token_or_comment_generator(self):
e = list(token_or_comment_generator(''))
self.assertEqual(len(e), 2)
self.assertEqual(e[0].prev, None)
self.assertIsInstance(e[0].curr, yaml.Token)
self.assertIsInstance(e[0].next, yaml.Token)
self.assertEqual(e[1].prev, e[0].curr)
self.assertEqual(e[1].curr, e[0].next)
self.assertEqual(e[1].next, None)
e = list(token_or_comment_generator('---\n'
'k: v\n'))
self.assertEqual(len(e), 9)
self.assertIsInstance(e[3].curr, yaml.KeyToken)
self.assertIsInstance(e[5].curr, yaml.ValueToken)
e = list(token_or_comment_generator('# start comment\n'
'- a\n'
'- key: val # key=val\n'
'# this is\n'
'# a block \n'
'# comment\n'
'- c\n'
'# end comment\n'))
self.assertEqual(len(e), 21)
self.assertIsInstance(e[1], Comment)
self.assertEqual(e[1], Comment(1, 1, '# start comment', 0))
self.assertEqual(e[11], Comment(3, 13, '# key=val', 0))
self.assertEqual(e[12], Comment(4, 1, '# this is', 0))
self.assertEqual(e[13], Comment(5, 1, '# a block ', 0))
self.assertEqual(e[14], Comment(6, 1, '# comment', 0))
self.assertEqual(e[18], Comment(8, 1, '# end comment', 0))
e = list(token_or_comment_generator('---\n'
'# no newline char'))
self.assertEqual(e[2], Comment(2, 1, '# no newline char', 0))
e = list(token_or_comment_generator('# just comment'))
self.assertEqual(e[1], Comment(1, 1, '# just comment', 0))
e = list(token_or_comment_generator('\n'
' # indented comment\n'))
self.assertEqual(e[1], Comment(2, 4, '# indented comment', 0))
e = list(token_or_comment_generator('\n'
'# trailing spaces \n'))
self.assertEqual(e[1], Comment(2, 1, '# trailing spaces ', 0))
e = [c for c in
token_or_comment_generator('# block\n'
'# comment\n'
'- data # inline comment\n'
'# block\n'
'# comment\n'
'- k: v # inline comment\n'
'- [ l, ist\n'
'] # inline comment\n'
'- { m: ap\n'
'} # inline comment\n'
'# block comment\n'
'- data # inline comment\n')
if isinstance(c, Comment)]
self.assertEqual(len(e), 10)
self.assertFalse(e[0].is_inline())
self.assertFalse(e[1].is_inline())
self.assertTrue(e[2].is_inline())
self.assertFalse(e[3].is_inline())
self.assertFalse(e[4].is_inline())
self.assertTrue(e[5].is_inline())
self.assertTrue(e[6].is_inline())
self.assertTrue(e[7].is_inline())
self.assertFalse(e[8].is_inline())
self.assertTrue(e[9].is_inline())
def test_token_or_comment_or_line_generator(self):
e = list(token_or_comment_or_line_generator('---\n'
'k: v # k=v\n'))
self.assertEqual(len(e), 13)
self.assertIsInstance(e[0], Token)
self.assertIsInstance(e[0].curr, yaml.StreamStartToken)
self.assertIsInstance(e[1], Token)
self.assertIsInstance(e[1].curr, yaml.DocumentStartToken)
self.assertIsInstance(e[2], Line)
self.assertIsInstance(e[3].curr, yaml.BlockMappingStartToken)
self.assertIsInstance(e[4].curr, yaml.KeyToken)
self.assertIsInstance(e[6].curr, yaml.ValueToken)
self.assertIsInstance(e[8], Comment)
self.assertIsInstance(e[9], Line)
self.assertIsInstance(e[12], Line)
yamllint-1.10.0/tests/rules/ 0000755 0002322 0002322 00000000000 13177553503 016275 5 ustar debalance debalance yamllint-1.10.0/tests/rules/test_indentation.py 0000644 0002322 0002322 00000230651 13177553503 022231 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
from yamllint.parser import token_or_comment_generator, Comment
from yamllint.rules.indentation import check
class IndentationStackTestCase(RuleTestCase):
# This test suite checks that the "indentation stack" built by the
# indentation rule is valid. It is important, since everything else in the
# rule relies on this stack.
maxDiff = None
def format_stack(self, stack):
"""Transform the stack at a given moment into a printable string like:
B_MAP:0 KEY:0 VAL:5
"""
return ' '.join(map(str, stack[1:]))
def full_stack(self, source):
conf = {'spaces': 2, 'indent-sequences': True,
'check-multi-line-strings': False}
context = {}
output = ''
for elem in [t for t in token_or_comment_generator(source)
if not isinstance(t, Comment)]:
list(check(conf, elem.curr, elem.prev, elem.next, elem.nextnext,
context))
token_type = (elem.curr.__class__.__name__
.replace('Token', '')
.replace('Block', 'B').replace('Flow', 'F')
.replace('Sequence', 'Seq')
.replace('Mapping', 'Map'))
if token_type in ('StreamStart', 'StreamEnd'):
continue
output += '%9s %s\n' % (token_type,
self.format_stack(context['stack']))
return output
def test_simple_mapping(self):
self.assertMultiLineEqual(
self.full_stack('key: val\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack(' key: val\n'),
'BMapStart B_MAP:5\n'
' Key B_MAP:5 KEY:5\n'
' Scalar B_MAP:5 KEY:5\n'
' Value B_MAP:5 KEY:5 VAL:10\n'
' Scalar B_MAP:5\n'
' BEnd \n')
def test_simple_sequence(self):
self.assertMultiLineEqual(
self.full_stack('- 1\n'
'- 2\n'
'- 3\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Scalar B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Scalar B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Scalar B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('key:\n'
' - 1\n'
' - 2\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n'
' BEnd B_MAP:0\n'
' BEnd \n')
def test_non_indented_sequences(self):
# There seems to be a bug in pyyaml: depending on the indentation, a
# sequence does not produce the same tokens. More precisely, the
# following YAML:
# usr:
# - lib
# produces a BlockSequenceStartToken and a BlockEndToken around the
# "lib" sequence, whereas the following:
# usr:
# - lib
# does not (both two tokens are omitted).
# So, yamllint must create fake 'B_SEQ'. This test makes sure it does.
self.assertMultiLineEqual(
self.full_stack('usr:\n'
' - lib\n'
'var: cache\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:2\n'
' BEnd B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('usr:\n'
'- lib\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Scalar B_MAP:0\n'
# missing BEnd here
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('usr:\n'
'- lib\n'
'var: cache\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Scalar B_MAP:0\n'
# missing BEnd here
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('usr:\n'
'- []\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
'FSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 F_SEQ:3\n'
' FSeqEnd B_MAP:0\n'
# missing BEnd here
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('usr:\n'
'- k:\n'
' v\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
'BMapStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2\n'
' Key B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n'
' Value B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2 VAL:4\n' # noqa
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_MAP:2\n'
' BEnd B_MAP:0\n'
# missing BEnd here
' BEnd \n')
def test_flows(self):
self.assertMultiLineEqual(
self.full_stack('usr: [\n'
' {k:\n'
' v}\n'
' ]\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
'FSeqStart B_MAP:0 KEY:0 VAL:5 F_SEQ:2\n'
'FMapStart B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3\n'
' Key B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3\n'
' Scalar B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3\n'
' Value B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3 KEY:3 VAL:5\n'
' Scalar B_MAP:0 KEY:0 VAL:5 F_SEQ:2 F_MAP:3\n'
' FMapEnd B_MAP:0 KEY:0 VAL:5 F_SEQ:2\n'
' FSeqEnd B_MAP:0\n'
' BEnd \n')
def test_anchors(self):
self.assertMultiLineEqual(
self.full_stack('key: &anchor value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
' Anchor B_MAP:0 KEY:0 VAL:5\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('key: &anchor\n'
' value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Anchor B_MAP:0 KEY:0 VAL:2\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('- &anchor value\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Anchor B_SEQ:0 B_ENT:2\n'
' Scalar B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('- &anchor\n'
' value\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Anchor B_SEQ:0 B_ENT:2\n'
' Scalar B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('- &anchor\n'
' - 1\n'
' - 2\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Anchor B_SEQ:0 B_ENT:2\n'
'BSeqStart B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEnd B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('&anchor key:\n'
' value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Anchor B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('pre:\n'
' &anchor1 0\n'
'&anchor2 key:\n'
' value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Anchor B_MAP:0 KEY:0 VAL:2\n'
' Scalar B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Anchor B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('sequence: &anchor\n'
'- entry\n'
'- &anchor\n'
' - nested\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Anchor B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Anchor B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEnd B_MAP:0\n'
# missing BEnd here
' BEnd \n')
def test_tags(self):
self.assertMultiLineEqual(
self.full_stack('key: !!tag value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:5\n'
' Tag B_MAP:0 KEY:0 VAL:5\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('- !!map # Block collection\n'
' foo : bar\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Tag B_SEQ:0 B_ENT:2\n'
'BMapStart B_SEQ:0 B_ENT:2 B_MAP:2\n'
' Key B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n'
' Scalar B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2\n'
' Value B_SEQ:0 B_ENT:2 B_MAP:2 KEY:2 VAL:8\n'
' Scalar B_SEQ:0 B_ENT:2 B_MAP:2\n'
' BEnd B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('- !!seq\n'
' - nested item\n'),
'BSeqStart B_SEQ:0\n'
' BEntry B_SEQ:0 B_ENT:2\n'
' Tag B_SEQ:0 B_ENT:2\n'
'BSeqStart B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEntry B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEnd B_SEQ:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('sequence: !!seq\n'
'- entry\n'
'- !!seq\n'
' - nested\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
' Scalar B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:2\n'
' Tag B_MAP:0 KEY:0 VAL:2\n'
# missing BSeqStart here
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
' Tag B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2\n'
'BSeqStart B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEntry B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2 B_ENT:4\n'
' Scalar B_MAP:0 KEY:0 VAL:2 B_SEQ:0 B_ENT:2 B_SEQ:2\n'
' BEnd B_MAP:0\n'
# missing BEnd here
' BEnd \n')
def test_flows_imbrication(self):
self.assertMultiLineEqual(
self.full_stack('[[val]]\n'),
'FSeqStart F_SEQ:1\n'
'FSeqStart F_SEQ:1 F_SEQ:2\n'
' Scalar F_SEQ:1 F_SEQ:2\n'
' FSeqEnd F_SEQ:1\n'
' FSeqEnd \n')
self.assertMultiLineEqual(
self.full_stack('[[val], [val2]]\n'),
'FSeqStart F_SEQ:1\n'
'FSeqStart F_SEQ:1 F_SEQ:2\n'
' Scalar F_SEQ:1 F_SEQ:2\n'
' FSeqEnd F_SEQ:1\n'
' FEntry F_SEQ:1\n'
'FSeqStart F_SEQ:1 F_SEQ:9\n'
' Scalar F_SEQ:1 F_SEQ:9\n'
' FSeqEnd F_SEQ:1\n'
' FSeqEnd \n')
self.assertMultiLineEqual(
self.full_stack('{{key}}\n'),
'FMapStart F_MAP:1\n'
'FMapStart F_MAP:1 F_MAP:2\n'
' Scalar F_MAP:1 F_MAP:2\n'
' FMapEnd F_MAP:1\n'
' FMapEnd \n')
self.assertMultiLineEqual(
self.full_stack('[key]: value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
'FSeqStart B_MAP:0 KEY:0 F_SEQ:1\n'
' Scalar B_MAP:0 KEY:0 F_SEQ:1\n'
' FSeqEnd B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:7\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('[[key]]: value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
'FSeqStart B_MAP:0 KEY:0 F_SEQ:1\n'
'FSeqStart B_MAP:0 KEY:0 F_SEQ:1 F_SEQ:2\n'
' Scalar B_MAP:0 KEY:0 F_SEQ:1 F_SEQ:2\n'
' FSeqEnd B_MAP:0 KEY:0 F_SEQ:1\n'
' FSeqEnd B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:9\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('{key}: value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
'FMapStart B_MAP:0 KEY:0 F_MAP:1\n'
' Scalar B_MAP:0 KEY:0 F_MAP:1\n'
' FMapEnd B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:7\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('{key: value}: value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
'FMapStart B_MAP:0 KEY:0 F_MAP:1\n'
' Key B_MAP:0 KEY:0 F_MAP:1 KEY:1\n'
' Scalar B_MAP:0 KEY:0 F_MAP:1 KEY:1\n'
' Value B_MAP:0 KEY:0 F_MAP:1 KEY:1 VAL:6\n'
' Scalar B_MAP:0 KEY:0 F_MAP:1\n'
' FMapEnd B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:14\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('{{key}}: value\n'),
'BMapStart B_MAP:0\n'
' Key B_MAP:0 KEY:0\n'
'FMapStart B_MAP:0 KEY:0 F_MAP:1\n'
'FMapStart B_MAP:0 KEY:0 F_MAP:1 F_MAP:2\n'
' Scalar B_MAP:0 KEY:0 F_MAP:1 F_MAP:2\n'
' FMapEnd B_MAP:0 KEY:0 F_MAP:1\n'
' FMapEnd B_MAP:0 KEY:0\n'
' Value B_MAP:0 KEY:0 VAL:9\n'
' Scalar B_MAP:0\n'
' BEnd \n')
self.assertMultiLineEqual(
self.full_stack('{{key}: val, {key2}: {val2}}\n'),
'FMapStart F_MAP:1\n'
' Key F_MAP:1 KEY:1\n'
'FMapStart F_MAP:1 KEY:1 F_MAP:2\n'
' Scalar F_MAP:1 KEY:1 F_MAP:2\n'
' FMapEnd F_MAP:1 KEY:1\n'
' Value F_MAP:1 KEY:1 VAL:8\n'
' Scalar F_MAP:1\n'
' FEntry F_MAP:1\n'
' Key F_MAP:1 KEY:1\n'
'FMapStart F_MAP:1 KEY:1 F_MAP:14\n'
' Scalar F_MAP:1 KEY:1 F_MAP:14\n'
' FMapEnd F_MAP:1 KEY:1\n'
' Value F_MAP:1 KEY:1 VAL:21\n'
'FMapStart F_MAP:1 KEY:1 VAL:21 F_MAP:22\n'
' Scalar F_MAP:1 KEY:1 VAL:21 F_MAP:22\n'
' FMapEnd F_MAP:1\n'
' FMapEnd \n')
self.assertMultiLineEqual(
self.full_stack('{[{{[val]}}, [{[key]: val2}]]}\n'),
'FMapStart F_MAP:1\n'
'FSeqStart F_MAP:1 F_SEQ:2\n'
'FMapStart F_MAP:1 F_SEQ:2 F_MAP:3\n'
'FMapStart F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4\n'
'FSeqStart F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4 F_SEQ:5\n'
' Scalar F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4 F_SEQ:5\n'
' FSeqEnd F_MAP:1 F_SEQ:2 F_MAP:3 F_MAP:4\n'
' FMapEnd F_MAP:1 F_SEQ:2 F_MAP:3\n'
' FMapEnd F_MAP:1 F_SEQ:2\n'
' FEntry F_MAP:1 F_SEQ:2\n'
'FSeqStart F_MAP:1 F_SEQ:2 F_SEQ:14\n'
'FMapStart F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15\n'
' Key F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15\n'
'FSeqStart F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 F_SEQ:16\n'
' Scalar F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 F_SEQ:16\n'
' FSeqEnd F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15\n'
' Value F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15 KEY:15 VAL:22\n'
' Scalar F_MAP:1 F_SEQ:2 F_SEQ:14 F_MAP:15\n'
' FMapEnd F_MAP:1 F_SEQ:2 F_SEQ:14\n'
' FSeqEnd F_MAP:1 F_SEQ:2\n'
' FSeqEnd F_MAP:1\n'
' FMapEnd \n')
class IndentationTestCase(RuleTestCase):
rule_id = 'indentation'
def test_disabled(self):
conf = 'indentation: disable'
self.check('---\n'
'object:\n'
' k1: v1\n'
'obj2:\n'
' k2:\n'
' - 8\n'
' k3:\n'
' val\n'
'...\n', conf)
self.check('---\n'
' o:\n'
' k1: v1\n'
' p:\n'
' k3:\n'
' val\n'
'...\n', conf)
self.check('---\n'
' - o:\n'
' k1: v1\n'
' - p: kdjf\n'
' - q:\n'
' k3:\n'
' - val\n'
'...\n', conf)
def test_one_space(self):
conf = 'indentation: {spaces: 1, indent-sequences: false}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
conf = 'indentation: {spaces: 1, indent-sequences: true}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
def test_two_spaces(self):
conf = 'indentation: {spaces: 2, indent-sequences: false}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
' k4:\n'
' -\n'
' k5: v3\n'
'...\n', conf)
conf = 'indentation: {spaces: 2, indent-sequences: true}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
def test_three_spaces(self):
conf = 'indentation: {spaces: 3, indent-sequences: false}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
conf = 'indentation: {spaces: 3, indent-sequences: true}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
def test_consistent_spaces(self):
conf = ('indentation: {spaces: consistent,\n'
' indent-sequences: whatever}\n'
'document-start: disable\n')
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf)
self.check('first is not indented:\n'
' value is indented\n', conf)
self.check('first is not indented:\n'
' value:\n'
' is indented\n', conf)
self.check('- first is already indented:\n'
' value is indented too\n', conf)
self.check('- first is already indented:\n'
' value:\n'
' is indented too\n', conf)
self.check('- first is already indented:\n'
' value:\n'
' is indented too\n', conf, problem=(3, 14))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem=(7, 5))
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf)
def test_consistent_spaces_and_indent_sequences(self):
conf = 'indentation: {spaces: consistent, indent-sequences: true}'
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(3, 1))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 5))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf, problem1=(7, 1))
conf = 'indentation: {spaces: consistent, indent-sequences: false}'
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 5))
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 3))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf, problem1=(3, 3))
conf = ('indentation: {spaces: consistent,\n'
' indent-sequences: consistent}')
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 5))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf, problem1=(7, 1))
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 5))
conf = 'indentation: {spaces: consistent, indent-sequences: whatever}'
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf)
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem1=(7, 5))
def test_indent_sequences_whatever(self):
conf = 'indentation: {spaces: 4, indent-sequences: whatever}'
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem=(3, 3))
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem=(7, 3))
self.check('---\n'
'list:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'- a\n'
'- b\n'
'- c\n', conf, problem=(6, 1, 'syntax'))
def test_indent_sequences_consistent(self):
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list:\n'
' two:\n'
' - a\n'
' - b\n'
' - c\n', conf)
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list:\n'
' two:\n'
' - a\n'
' - b\n'
' - c\n', conf)
self.check('---\n'
'list one:\n'
'- 1\n'
'- 2\n'
'- 3\n'
'list two:\n'
' - a\n'
' - b\n'
' - c\n', conf, problem=(7, 5))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf, problem=(7, 1))
self.check('---\n'
'list one:\n'
' - 1\n'
' - 2\n'
' - 3\n'
'list two:\n'
'- a\n'
'- b\n'
'- c\n', conf, problem1=(3, 2), problem2=(7, 1))
def test_direct_flows(self):
# flow: [ ...
# ]
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'a: {x: 1,\n'
' y,\n'
' z: 1}\n', conf)
self.check('---\n'
'a: {x: 1,\n'
' y,\n'
' z: 1}\n', conf, problem=(3, 4))
self.check('---\n'
'a: {x: 1,\n'
' y,\n'
' z: 1}\n', conf, problem=(3, 6))
self.check('---\n'
'a: {x: 1,\n'
' y, z: 1}\n', conf, problem=(3, 3))
self.check('---\n'
'a: {x: 1,\n'
' y, z: 1\n'
'}\n', conf)
self.check('---\n'
'a: {x: 1,\n'
' y, z: 1\n'
'}\n', conf, problem=(3, 3))
self.check('---\n'
'a: [x,\n'
' y,\n'
' z]\n', conf)
self.check('---\n'
'a: [x,\n'
' y,\n'
' z]\n', conf, problem=(3, 4))
self.check('---\n'
'a: [x,\n'
' y,\n'
' z]\n', conf, problem=(3, 6))
self.check('---\n'
'a: [x,\n'
' y, z]\n', conf, problem=(3, 3))
self.check('---\n'
'a: [x,\n'
' y, z\n'
']\n', conf)
self.check('---\n'
'a: [x,\n'
' y, z\n'
']\n', conf, problem=(3, 3))
def test_broken_flows(self):
# flow: [
# ...
# ]
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'a: {\n'
' x: 1,\n'
' y, z: 1\n'
'}\n', conf)
self.check('---\n'
'a: {\n'
' x: 1,\n'
' y, z: 1}\n', conf)
self.check('---\n'
'a: {\n'
' x: 1,\n'
' y, z: 1\n'
'}\n', conf, problem=(4, 3))
self.check('---\n'
'a: {\n'
' x: 1,\n'
' y, z: 1\n'
' }\n', conf, problem=(5, 3))
self.check('---\n'
'a: [\n'
' x,\n'
' y, z\n'
']\n', conf)
self.check('---\n'
'a: [\n'
' x,\n'
' y, z]\n', conf)
self.check('---\n'
'a: [\n'
' x,\n'
' y, z\n'
']\n', conf, problem=(4, 3))
self.check('---\n'
'a: [\n'
' x,\n'
' y, z\n'
' ]\n', conf, problem=(5, 3))
self.check('---\n'
'obj: {\n'
' a: 1,\n'
' b: 2,\n'
' c: 3\n'
'}\n', conf, problem1=(4, 4), problem2=(5, 2))
self.check('---\n'
'list: [\n'
' 1,\n'
' 2,\n'
' 3\n'
']\n', conf, problem1=(4, 4), problem2=(5, 2))
self.check('---\n'
'top:\n'
' rules: [\n'
' 1, 2,\n'
' ]\n', conf)
self.check('---\n'
'top:\n'
' rules: [\n'
' 1, 2,\n'
']\n'
' rulez: [\n'
' 1, 2,\n'
' ]\n', conf, problem1=(5, 1), problem2=(8, 5))
self.check('---\n'
'top:\n'
' rules:\n'
' here: {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf)
self.check('---\n'
'top:\n'
' rules:\n'
' here: {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n'
' there: {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf, problem1=(7, 7), problem2=(11, 3))
conf = 'indentation: {spaces: 2}'
self.check('---\n'
'a: {\n'
' x: 1,\n'
' y, z: 1\n'
'}\n', conf, problem=(3, 4))
self.check('---\n'
'a: [\n'
' x,\n'
' y, z\n'
']\n', conf, problem=(3, 4))
def test_cleared_flows(self):
# flow:
# [
# ...
# ]
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'top:\n'
' rules:\n'
' {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf)
self.check('---\n'
'top:\n'
' rules:\n'
' {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf, problem=(5, 8))
self.check('---\n'
'top:\n'
' rules:\n'
' {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf, problem=(4, 4))
self.check('---\n'
'top:\n'
' rules:\n'
' {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf, problem=(7, 4))
self.check('---\n'
'top:\n'
' rules:\n'
' {\n'
' foo: 1,\n'
' bar: 2\n'
' }\n', conf, problem=(7, 6))
self.check('---\n'
'top:\n'
' [\n'
' a, b, c\n'
' ]\n', conf)
self.check('---\n'
'top:\n'
' [\n'
' a, b, c\n'
' ]\n', conf, problem=(4, 6))
self.check('---\n'
'top:\n'
' [\n'
' a, b, c\n'
' ]\n', conf, problem=(4, 6))
self.check('---\n'
'top:\n'
' [\n'
' a, b, c\n'
' ]\n', conf, problem=(5, 4))
self.check('---\n'
'top:\n'
' rules: [\n'
' {\n'
' foo: 1\n'
' },\n'
' {\n'
' foo: 2,\n'
' bar: [\n'
' a, b, c\n'
' ],\n'
' },\n'
' ]\n', conf)
self.check('---\n'
'top:\n'
' rules: [\n'
' {\n'
' foo: 1\n'
' },\n'
' {\n'
' foo: 2,\n'
' bar: [\n'
' a, b, c\n'
' ],\n'
' },\n'
']\n', conf, problem1=(5, 6), problem2=(6, 6),
problem3=(9, 9), problem4=(11, 7), problem5=(13, 1))
def test_under_indented(self):
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
self.check('---\n'
'object:\n'
' val: 1\n'
'...\n', conf, problem=(3, 2))
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
'...\n', conf, problem=(4, 4))
self.check('---\n'
'object:\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
'...\n', conf, problem=(5, 6, 'syntax'))
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
self.check('---\n'
'object:\n'
' val: 1\n'
'...\n', conf, problem=(3, 4))
self.check('---\n'
'- el1\n'
'- el2:\n'
' - subel\n'
'...\n', conf, problem=(4, 4))
self.check('---\n'
'object:\n'
' k3:\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf, problem=(5, 10, 'syntax'))
conf = 'indentation: {spaces: 2, indent-sequences: true}'
self.check('---\n'
'a:\n'
'-\n' # empty list
'b: c\n'
'...\n', conf, problem=(3, 1))
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
self.check('---\n'
'a:\n'
' -\n' # empty list
'b:\n'
'-\n'
'c: d\n'
'...\n', conf, problem=(5, 1))
def test_over_indented(self):
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
self.check('---\n'
'object:\n'
' val: 1\n'
'...\n', conf, problem=(3, 4))
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
'...\n', conf, problem=(4, 6))
self.check('---\n'
'object:\n'
' k3:\n'
' - name: Unix\n'
' date: 1969\n'
'...\n', conf, problem=(5, 12, 'syntax'))
conf = 'indentation: {spaces: 4, indent-sequences: consistent}'
self.check('---\n'
'object:\n'
' val: 1\n'
'...\n', conf, problem=(3, 6))
self.check('---\n'
' object:\n'
' val: 1\n'
'...\n', conf, problem=(2, 2))
self.check('---\n'
'- el1\n'
'- el2:\n'
' - subel\n'
'...\n', conf, problem=(4, 6))
self.check('---\n'
'- el1\n'
'- el2:\n'
' - subel\n'
'...\n', conf, problem=(4, 15))
self.check('---\n'
' - el1\n'
' - el2:\n'
' - subel\n'
'...\n', conf,
problem=(2, 3))
self.check('---\n'
'object:\n'
' k3:\n'
' - name: Linux\n'
' date: 1991\n'
'...\n', conf, problem=(5, 16, 'syntax'))
conf = 'indentation: {spaces: 4, indent-sequences: whatever}'
self.check('---\n'
' - el1\n'
' - el2:\n'
' - subel\n'
'...\n', conf,
problem=(2, 3))
conf = 'indentation: {spaces: 2, indent-sequences: false}'
self.check('---\n'
'a:\n'
' -\n' # empty list
'b: c\n'
'...\n', conf, problem=(3, 3))
conf = 'indentation: {spaces: 2, indent-sequences: consistent}'
self.check('---\n'
'a:\n'
'-\n' # empty list
'b:\n'
' -\n'
'c: d\n'
'...\n', conf, problem=(5, 3))
def test_multi_lines(self):
conf = 'indentation: {spaces: consistent, indent-sequences: true}'
self.check('---\n'
'long_string: >\n'
' bla bla blah\n'
' blah bla bla\n'
'...\n', conf)
self.check('---\n'
'- long_string: >\n'
' bla bla blah\n'
' blah bla bla\n'
'...\n', conf)
self.check('---\n'
'obj:\n'
' - long_string: >\n'
' bla bla blah\n'
' blah bla bla\n'
'...\n', conf)
def test_empty_value(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'key1:\n'
'key2: not empty\n'
'key3:\n'
'...\n', conf)
self.check('---\n'
'-\n'
'- item 2\n'
'-\n'
'...\n', conf)
def test_nested_collections(self):
conf = 'indentation: {spaces: 2}'
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf)
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf, problem=(3, 2, 'syntax'))
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf, problem=(3, 4))
conf = 'indentation: {spaces: 4}'
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf)
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf, problem=(3, 6))
self.check('---\n'
'- o:\n'
' k1: v1\n'
'...\n', conf, problem=(3, 8))
self.check('---\n'
'- - - - item\n'
' - elem 1\n'
' - elem 2\n'
' - - - - - very nested: a\n'
' key: value\n'
'...\n', conf)
self.check('---\n'
' - - - - item\n'
' - elem 1\n'
' - elem 2\n'
' - - - - - very nested: a\n'
' key: value\n'
'...\n', conf, problem=(2, 2))
def test_return(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'a:\n'
' b:\n'
' c:\n'
' d:\n'
' e:\n'
' f:\n'
'g:\n'
'...\n', conf)
self.check('---\n'
'a:\n'
' b:\n'
' c:\n'
' d:\n'
'...\n', conf, problem=(5, 4, 'syntax'))
self.check('---\n'
'a:\n'
' b:\n'
' c:\n'
' d:\n'
'...\n', conf, problem=(5, 2, 'syntax'))
def test_first_line(self):
conf = ('indentation: {spaces: consistent}\n'
'document-start: disable\n')
self.check(' a: 1\n', conf, problem=(1, 3))
def test_explicit_block_mappings(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'object:\n'
' ? key\n'
' : value\n', conf)
self.check('---\n'
'object:\n'
' ? key\n'
' :\n'
' value\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' ?\n'
' key\n'
' : value\n', conf)
self.check('---\n'
'object:\n'
' ?\n'
' key\n'
' :\n'
' value\n'
'...\n', conf)
self.check('---\n'
'- ? key\n'
' : value\n', conf)
self.check('---\n'
'- ? key\n'
' :\n'
' value\n'
'...\n', conf)
self.check('---\n'
'- ?\n'
' key\n'
' : value\n', conf)
self.check('---\n'
'- ?\n'
' key\n'
' :\n'
' value\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' ? key\n'
' :\n'
' value\n'
'...\n', conf, problem=(5, 8))
self.check('---\n'
'- - ?\n'
' key\n'
' :\n'
' value\n'
'...\n', conf, problem=(5, 7))
self.check('---\n'
'object:\n'
' ?\n'
' key\n'
' :\n'
' value\n'
'...\n', conf, problem1=(4, 8), problem2=(6, 10))
self.check('---\n'
'object:\n'
' ?\n'
' key\n'
' :\n'
' value\n'
'...\n', conf, problem1=(4, 10), problem2=(6, 8))
def test_clear_sequence_item(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'-\n'
' string\n'
'-\n'
' map: ping\n'
'-\n'
' - sequence\n'
' -\n'
' nested\n'
' -\n'
' >\n'
' multi\n'
' line\n'
'...\n', conf)
self.check('---\n'
'-\n'
' string\n'
'-\n'
' string\n', conf, problem=(5, 4))
self.check('---\n'
'-\n'
' map: ping\n'
'-\n'
' map: ping\n', conf, problem=(5, 4))
self.check('---\n'
'-\n'
' - sequence\n'
'-\n'
' - sequence\n', conf, problem=(5, 4))
self.check('---\n'
'-\n'
' -\n'
' nested\n'
' -\n'
' nested\n', conf, problem1=(4, 4), problem2=(6, 6))
self.check('---\n'
'-\n'
' -\n'
' >\n'
' multi\n'
' line\n'
'...\n', conf, problem=(4, 6))
conf = 'indentation: {spaces: 2}'
self.check('---\n'
'-\n'
' string\n'
'-\n'
' string\n', conf, problem1=(3, 2), problem2=(5, 4))
self.check('---\n'
'-\n'
' map: ping\n'
'-\n'
' map: ping\n', conf, problem1=(3, 2), problem2=(5, 4))
self.check('---\n'
'-\n'
' - sequence\n'
'-\n'
' - sequence\n', conf, problem1=(3, 2), problem2=(5, 4))
self.check('---\n'
'-\n'
' -\n'
' nested\n'
' -\n'
' nested\n', conf, problem1=(4, 4), problem2=(6, 6))
def test_anchors(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'key: &anchor value\n', conf)
self.check('---\n'
'key: &anchor\n'
' value\n', conf)
self.check('---\n'
'- &anchor value\n', conf)
self.check('---\n'
'- &anchor\n'
' value\n', conf)
self.check('---\n'
'key: &anchor [1,\n'
' 2]\n', conf)
self.check('---\n'
'key: &anchor\n'
' [1,\n'
' 2]\n', conf)
self.check('---\n'
'key: &anchor\n'
' - 1\n'
' - 2\n', conf)
self.check('---\n'
'- &anchor [1,\n'
' 2]\n', conf)
self.check('---\n'
'- &anchor\n'
' [1,\n'
' 2]\n', conf)
self.check('---\n'
'- &anchor\n'
' - 1\n'
' - 2\n', conf)
self.check('---\n'
'key:\n'
' &anchor1\n'
' value\n', conf)
self.check('---\n'
'pre:\n'
' &anchor1 0\n'
'&anchor2 key:\n'
' value\n', conf)
self.check('---\n'
'machine0:\n'
' /etc/hosts: &ref-etc-hosts\n'
' content:\n'
' - 127.0.0.1: localhost\n'
' - ::1: localhost\n'
' mode: 0644\n'
'machine1:\n'
' /etc/hosts: *ref-etc-hosts\n', conf)
self.check('---\n'
'list:\n'
' - k: v\n'
' - &a truc\n'
' - &b\n'
' truc\n'
' - k: *a\n', conf)
def test_tags(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'-\n'
' "flow in block"\n'
'- >\n'
' Block scalar\n'
'- !!map # Block collection\n'
' foo: bar\n', conf)
conf = 'indentation: {spaces: consistent, indent-sequences: false}'
self.check('---\n'
'sequence: !!seq\n'
'- entry\n'
'- !!seq\n'
' - nested\n', conf)
self.check('---\n'
'mapping: !!map\n'
' foo: bar\n'
'Block style: !!map\n'
' Clark: Evans\n'
' Ingy: döt Net\n'
' Oren: Ben-Kiki\n', conf)
self.check('---\n'
'Flow style: !!map {Clark: Evans, Ingy: döt Net}\n'
'Block style: !!seq\n'
'- Clark Evans\n'
'- Ingy döt Net\n', conf)
def test_flows_imbrication(self):
conf = 'indentation: {spaces: consistent}'
self.check('---\n'
'[val]: value\n', conf)
self.check('---\n'
'{key}: value\n', conf)
self.check('---\n'
'{key: val}: value\n', conf)
self.check('---\n'
'[[val]]: value\n', conf)
self.check('---\n'
'{{key}}: value\n', conf)
self.check('---\n'
'{{key: val1}: val2}: value\n', conf)
self.check('---\n'
'- [val, {{key: val}: val}]: value\n'
'- {[val,\n'
' {{key: val}: val}]}\n'
'- {[val,\n'
' {{key: val,\n'
' key2}}]}\n'
'- {{{{{moustaches}}}}}\n'
'- {{{{{moustache,\n'
' moustache},\n'
' moustache}},\n'
' moustache}}\n', conf)
self.check('---\n'
'- {[val,\n'
' {{key: val}: val}]}\n',
conf, problem=(3, 6))
self.check('---\n'
'- {[val,\n'
' {{key: val,\n'
' key2}}]}\n',
conf, problem=(4, 6))
self.check('---\n'
'- {{{{{moustache,\n'
' moustache},\n'
' moustache}},\n'
' moustache}}\n',
conf, problem1=(4, 8), problem2=(5, 4))
class ScalarIndentationTestCase(RuleTestCase):
rule_id = 'indentation'
def test_basics_plain(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: false}\n'
'document-start: disable\n')
self.check('multi\n'
'line\n', conf)
self.check('multi\n'
' line\n', conf)
self.check('- multi\n'
' line\n', conf)
self.check('- multi\n'
' line\n', conf)
self.check('a key: multi\n'
' line\n', conf)
self.check('a key: multi\n'
' line\n', conf)
self.check('a key: multi\n'
' line\n', conf)
self.check('a key:\n'
' multi\n'
' line\n', conf)
self.check('- C code: void main() {\n'
' printf("foo");\n'
' }\n', conf)
self.check('- C code:\n'
' void main() {\n'
' printf("foo");\n'
' }\n', conf)
def test_check_multi_line_plain(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('multi\n'
' line\n', conf, problem=(2, 2))
self.check('- multi\n'
' line\n', conf, problem=(2, 4))
self.check('a key: multi\n'
' line\n', conf, problem=(2, 3))
self.check('a key: multi\n'
' line\n', conf, problem=(2, 9))
self.check('a key:\n'
' multi\n'
' line\n', conf, problem=(3, 4))
self.check('- C code: void main() {\n'
' printf("foo");\n'
' }\n', conf, problem=(2, 15))
self.check('- C code:\n'
' void main() {\n'
' printf("foo");\n'
' }\n', conf, problem=(3, 9))
def test_basics_quoted(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: false}\n'
'document-start: disable\n')
self.check('"multi\n'
' line"\n', conf)
self.check('- "multi\n'
' line"\n', conf)
self.check('a key: "multi\n'
' line"\n', conf)
self.check('a key:\n'
' "multi\n'
' line"\n', conf)
self.check('- jinja2: "{% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}"\n', conf)
self.check('- jinja2:\n'
' "{% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}"\n', conf)
self.check('["this is a very long line\n'
' that needs to be split",\n'
' "other line"]\n', conf)
self.check('["multi\n'
' line 1", "multi\n'
' line 2"]\n', conf)
def test_check_multi_line_quoted(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('"multi\n'
'line"\n', conf, problem=(2, 1))
self.check('"multi\n'
' line"\n', conf, problem=(2, 3))
self.check('- "multi\n'
' line"\n', conf, problem=(2, 3))
self.check('- "multi\n'
' line"\n', conf, problem=(2, 5))
self.check('a key: "multi\n'
' line"\n', conf, problem=(2, 3))
self.check('a key: "multi\n'
' line"\n', conf, problem=(2, 8))
self.check('a key: "multi\n'
' line"\n', conf, problem=(2, 10))
self.check('a key:\n'
' "multi\n'
' line"\n', conf, problem=(3, 3))
self.check('a key:\n'
' "multi\n'
' line"\n', conf, problem=(3, 5))
self.check('- jinja2: "{% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}"\n', conf,
problem1=(2, 14), problem2=(4, 14))
self.check('- jinja2:\n'
' "{% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}"\n', conf,
problem1=(3, 8), problem2=(5, 8))
self.check('["this is a very long line\n'
' that needs to be split",\n'
' "other line"]\n', conf)
self.check('["this is a very long line\n'
' that needs to be split",\n'
' "other line"]\n', conf, problem=(2, 2))
self.check('["this is a very long line\n'
' that needs to be split",\n'
' "other line"]\n', conf, problem=(2, 4))
self.check('["multi\n'
' line 1", "multi\n'
' line 2"]\n', conf)
self.check('["multi\n'
' line 1", "multi\n'
' line 2"]\n', conf, problem=(3, 12))
self.check('["multi\n'
' line 1", "multi\n'
' line 2"]\n', conf, problem=(3, 14))
def test_basics_folded_style(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: false}\n'
'document-start: disable\n')
self.check('>\n'
' multi\n'
' line\n', conf)
self.check('- >\n'
' multi\n'
' line\n', conf)
self.check('- key: >\n'
' multi\n'
' line\n', conf)
self.check('- key:\n'
' >\n'
' multi\n'
' line\n', conf)
self.check('- ? >\n'
' multi-line\n'
' key\n'
' : >\n'
' multi-line\n'
' value\n', conf)
self.check('- ?\n'
' >\n'
' multi-line\n'
' key\n'
' :\n'
' >\n'
' multi-line\n'
' value\n', conf)
self.check('- jinja2: >\n'
' {% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}\n', conf)
def test_check_multi_line_folded_style(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('>\n'
' multi\n'
' line\n', conf, problem=(3, 4))
self.check('- >\n'
' multi\n'
' line\n', conf, problem=(3, 6))
self.check('- key: >\n'
' multi\n'
' line\n', conf, problem=(3, 6))
self.check('- key:\n'
' >\n'
' multi\n'
' line\n', conf, problem=(4, 8))
self.check('- ? >\n'
' multi-line\n'
' key\n'
' : >\n'
' multi-line\n'
' value\n', conf,
problem1=(3, 8), problem2=(6, 8))
self.check('- ?\n'
' >\n'
' multi-line\n'
' key\n'
' :\n'
' >\n'
' multi-line\n'
' value\n', conf,
problem1=(4, 8), problem2=(8, 8))
self.check('- jinja2: >\n'
' {% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}\n', conf,
problem1=(3, 7), problem2=(5, 7))
def test_basics_literal_style(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: false}\n'
'document-start: disable\n')
self.check('|\n'
' multi\n'
' line\n', conf)
self.check('- |\n'
' multi\n'
' line\n', conf)
self.check('- key: |\n'
' multi\n'
' line\n', conf)
self.check('- key:\n'
' |\n'
' multi\n'
' line\n', conf)
self.check('- ? |\n'
' multi-line\n'
' key\n'
' : |\n'
' multi-line\n'
' value\n', conf)
self.check('- ?\n'
' |\n'
' multi-line\n'
' key\n'
' :\n'
' |\n'
' multi-line\n'
' value\n', conf)
self.check('- jinja2: |\n'
' {% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}\n', conf)
def test_check_multi_line_literal_style(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('|\n'
' multi\n'
' line\n', conf, problem=(3, 4))
self.check('- |\n'
' multi\n'
' line\n', conf, problem=(3, 6))
self.check('- key: |\n'
' multi\n'
' line\n', conf, problem=(3, 6))
self.check('- key:\n'
' |\n'
' multi\n'
' line\n', conf, problem=(4, 8))
self.check('- ? |\n'
' multi-line\n'
' key\n'
' : |\n'
' multi-line\n'
' value\n', conf,
problem1=(3, 8), problem2=(6, 8))
self.check('- ?\n'
' |\n'
' multi-line\n'
' key\n'
' :\n'
' |\n'
' multi-line\n'
' value\n', conf,
problem1=(4, 8), problem2=(8, 8))
self.check('- jinja2: |\n'
' {% if ansible is defined %}\n'
' {{ ansible }}\n'
' {% else %}\n'
' {{ chef }}\n'
' {% endif %}\n', conf,
problem1=(3, 7), problem2=(5, 7))
# The following "paragraph" examples are inspired from
# http://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
def test_paragraph_plain(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('- long text: very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf)
self.check('- long text: very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf,
problem1=(2, 5), problem2=(4, 5), problem3=(5, 5))
self.check('- long text:\n'
' very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf)
def test_paragraph_double_quoted(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('- long text: "very \\"long\\"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces."\n', conf)
self.check('- long text: "very \\"long\\"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces."\n', conf,
problem1=(2, 5), problem2=(4, 5), problem3=(5, 5))
self.check('- long text: "very \\"long\\"\n'
'\'string\' with\n'
'\n'
'paragraph gap, \\n and\n'
'spaces."\n', conf,
problem1=(2, 1), problem2=(4, 1), problem3=(5, 1))
self.check('- long text:\n'
' "very \\"long\\"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces."\n', conf)
def test_paragraph_single_quoted(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('- long text: \'very "long"\n'
' \'\'string\'\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\'\n', conf)
self.check('- long text: \'very "long"\n'
' \'\'string\'\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\'\n', conf,
problem1=(2, 5), problem2=(4, 5), problem3=(5, 5))
self.check('- long text: \'very "long"\n'
'\'\'string\'\' with\n'
'\n'
'paragraph gap, \\n and\n'
'spaces.\'\n', conf,
problem1=(2, 1), problem2=(4, 1), problem3=(5, 1))
self.check('- long text:\n'
' \'very "long"\n'
' \'\'string\'\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\'\n', conf)
def test_paragraph_folded(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('- long text: >\n'
' very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf)
self.check('- long text: >\n'
' very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf,
problem1=(3, 6), problem2=(5, 7), problem3=(6, 8))
def test_paragraph_literal(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('- long text: |\n'
' very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf)
self.check('- long text: |\n'
' very "long"\n'
' \'string\' with\n'
'\n'
' paragraph gap, \\n and\n'
' spaces.\n', conf,
problem1=(3, 6), problem2=(5, 7), problem3=(6, 8))
def test_consistent(self):
conf = ('indentation: {spaces: consistent,\n'
' check-multi-line-strings: true}\n'
'document-start: disable\n')
self.check('multi\n'
'line\n', conf)
self.check('multi\n'
' line\n', conf, problem=(2, 2))
self.check('- multi\n'
' line\n', conf)
self.check('- multi\n'
' line\n', conf, problem=(2, 4))
self.check('a key: multi\n'
' line\n', conf, problem=(2, 3))
self.check('a key: multi\n'
' line\n', conf, problem=(2, 9))
self.check('a key:\n'
' multi\n'
' line\n', conf, problem=(3, 4))
self.check('- C code: void main() {\n'
' printf("foo");\n'
' }\n', conf, problem=(2, 15))
self.check('- C code:\n'
' void main() {\n'
' printf("foo");\n'
' }\n', conf, problem=(3, 9))
self.check('>\n'
' multi\n'
' line\n', conf)
self.check('>\n'
' multi\n'
' line\n', conf)
self.check('>\n'
' multi\n'
' line\n', conf, problem=(3, 7))
yamllint-1.10.0/tests/rules/test_comments.py 0000644 0002322 0002322 00000014514 13177553503 021540 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class CommentsTestCase(RuleTestCase):
rule_id = 'comments'
def test_disabled(self):
conf = ('comments: disable\n'
'comments-indentation: disable\n')
self.check('---\n'
'#comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello #world\n'
'\n'
'# comment 2\n'
'#comment 3\n'
' #comment 3 bis\n'
' # comment 3 ter\n'
'\n'
'################################\n'
'## comment 4\n'
'##comment 5\n'
'\n'
'string: "Une longue phrase." # this is French\n', conf)
def test_starting_space(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: -1\n'
'comments-indentation: disable\n')
self.check('---\n'
'# comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello # world\n'
'\n'
'# comment 2\n'
'# comment 3\n'
' # comment 3 bis\n'
' # comment 3 ter\n'
'\n'
'################################\n'
'## comment 4\n'
'## comment 5\n', conf)
self.check('---\n'
'#comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello #world\n'
'\n'
'# comment 2\n'
'#comment 3\n'
' #comment 3 bis\n'
' # comment 3 ter\n'
'\n'
'################################\n'
'## comment 4\n'
'##comment 5\n', conf,
problem1=(2, 2), problem2=(6, 13),
problem3=(9, 2), problem4=(10, 4),
problem5=(15, 3))
def test_spaces_from_content(self):
conf = ('comments:\n'
' require-starting-space: false\n'
' min-spaces-from-content: 2\n')
self.check('---\n'
'# comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello #world\n'
'\n'
'string: "Une longue phrase." # this is French\n', conf)
self.check('---\n'
'# comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello #world\n'
'\n'
'string: "Une longue phrase." # this is French\n', conf,
problem1=(4, 7), problem2=(6, 11), problem3=(8, 30))
def test_both(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: 2\n'
'comments-indentation: disable\n')
self.check('---\n'
'#comment\n'
'\n'
'test: # description\n'
' - foo # bar\n'
' - hello #world\n'
'\n'
'# comment 2\n'
'#comment 3\n'
' #comment 3 bis\n'
' # comment 3 ter\n'
'\n'
'################################\n'
'## comment 4\n'
'##comment 5\n'
'\n'
'string: "Une longue phrase." # this is French\n', conf,
problem1=(2, 2),
problem2=(4, 7),
problem3=(6, 11), problem4=(6, 12),
problem5=(9, 2),
problem6=(10, 4),
problem7=(15, 3),
problem8=(17, 30))
def test_empty_comment(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: 2\n')
self.check('---\n'
'# This is paragraph 1.\n'
'#\n'
'# This is paragraph 2.\n', conf)
self.check('---\n'
'inline: comment #\n'
'foo: bar\n', conf)
def test_first_line(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: 2\n')
self.check('# comment\n', conf)
def test_last_line(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: 2\n'
'new-line-at-end-of-file: disable\n')
self.check('# comment with no newline char:\n'
'#', conf)
def test_multi_line_scalar(self):
conf = ('comments:\n'
' require-starting-space: true\n'
' min-spaces-from-content: 2\n'
'trailing-spaces: disable\n')
self.check('---\n'
'string: >\n'
' this is plain text\n'
'\n'
'# comment\n', conf)
self.check('---\n'
'- string: >\n'
' this is plain text\n'
' \n'
' # comment\n', conf)
yamllint-1.10.0/tests/rules/test_braces.py 0000644 0002322 0002322 00000024657 13177553503 021163 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class ColonTestCase(RuleTestCase):
rule_id = 'braces'
def test_disabled(self):
conf = 'braces: disable'
self.check('---\n'
'dict1: {}\n'
'dict2: { }\n'
'dict3: { a: 1, b}\n'
'dict4: {a: 1, b, c: 3 }\n'
'dict5: {a: 1, b, c: 3 }\n'
'dict6: { a: 1, b, c: 3 }\n'
'dict7: { a: 1, b, c: 3 }\n', conf)
def test_min_spaces(self):
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {}\n', conf)
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {}\n', conf, problem=(2, 8))
self.check('---\n'
'dict: { }\n', conf)
self.check('---\n'
'dict: {a: 1, b}\n', conf,
problem1=(2, 8), problem2=(2, 15))
self.check('---\n'
'dict: { a: 1, b }\n', conf)
self.check('---\n'
'dict: {\n'
' a: 1,\n'
' b\n'
'}\n', conf)
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 3\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: { a: 1, b }\n', conf,
problem1=(2, 9), problem2=(2, 17))
self.check('---\n'
'dict: { a: 1, b }\n', conf)
def test_max_spaces(self):
conf = ('braces:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {}\n', conf)
self.check('---\n'
'dict: { }\n', conf, problem=(2, 8))
self.check('---\n'
'dict: {a: 1, b}\n', conf)
self.check('---\n'
'dict: { a: 1, b }\n', conf,
problem1=(2, 8), problem2=(2, 16))
self.check('---\n'
'dict: { a: 1, b }\n', conf,
problem1=(2, 10), problem2=(2, 20))
self.check('---\n'
'dict: {\n'
' a: 1,\n'
' b\n'
'}\n', conf)
conf = ('braces:\n'
' max-spaces-inside: 3\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: { a: 1, b }\n', conf)
self.check('---\n'
'dict: { a: 1, b }\n', conf,
problem1=(2, 11), problem2=(2, 23))
def test_min_and_max_spaces(self):
conf = ('braces:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {}\n', conf)
self.check('---\n'
'dict: { }\n', conf, problem=(2, 8))
self.check('---\n'
'dict: { a: 1, b}\n', conf, problem=(2, 10))
conf = ('braces:\n'
' max-spaces-inside: 1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {a: 1, b, c: 3 }\n', conf, problem=(2, 8))
conf = ('braces:\n'
' max-spaces-inside: 2\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'dict: {a: 1, b, c: 3 }\n', conf)
self.check('---\n'
'dict: { a: 1, b, c: 3 }\n', conf)
self.check('---\n'
'dict: { a: 1, b, c: 3 }\n', conf, problem=(2, 10))
def test_min_spaces_empty(self):
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: 0\n')
self.check('---\n'
'array: {}\n', conf)
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: {}\n', conf, problem=(2, 9))
self.check('---\n'
'array: { }\n', conf)
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: 3\n')
self.check('---\n'
'array: {}\n', conf, problem=(2, 9))
self.check('---\n'
'array: { }\n', conf)
def test_max_spaces_empty(self):
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: {}\n', conf)
self.check('---\n'
'array: { }\n', conf, problem=(2, 9))
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: {}\n', conf)
self.check('---\n'
'array: { }\n', conf)
self.check('---\n'
'array: { }\n', conf, problem=(2, 10))
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 3\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: {}\n', conf)
self.check('---\n'
'array: { }\n', conf)
self.check('---\n'
'array: { }\n', conf, problem=(2, 12))
def test_min_and_max_spaces_empty(self):
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 2\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: {}\n', conf, problem=(2, 9))
self.check('---\n'
'array: { }\n', conf)
self.check('---\n'
'array: { }\n', conf)
self.check('---\n'
'array: { }\n', conf, problem=(2, 11))
def test_mixed_empty_nonempty(self):
conf = ('braces:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: 0\n')
self.check('---\n'
'array: { a: 1, b }\n', conf)
self.check('---\n'
'array: {a: 1, b}\n', conf,
problem1=(2, 9), problem2=(2, 16))
self.check('---\n'
'array: {}\n', conf)
self.check('---\n'
'array: { }\n', conf,
problem1=(2, 9))
conf = ('braces:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: { a: 1, b }\n', conf,
problem1=(2, 9), problem2=(2, 17))
self.check('---\n'
'array: {a: 1, b}\n', conf)
self.check('---\n'
'array: {}\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: { }\n', conf)
conf = ('braces:\n'
' max-spaces-inside: 2\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: { a: 1, b }\n', conf)
self.check('---\n'
'array: {a: 1, b }\n', conf,
problem1=(2, 9), problem2=(2, 18))
self.check('---\n'
'array: {}\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: { }\n', conf)
self.check('---\n'
'array: { }\n', conf,
problem1=(2, 11))
conf = ('braces:\n'
' max-spaces-inside: 1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: { a: 1, b }\n', conf)
self.check('---\n'
'array: {a: 1, b}\n', conf,
problem1=(2, 9), problem2=(2, 16))
self.check('---\n'
'array: {}\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: { }\n', conf)
yamllint-1.10.0/tests/rules/test_brackets.py 0000644 0002322 0002322 00000024566 13177553503 021521 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class ColonTestCase(RuleTestCase):
rule_id = 'brackets'
def test_disabled(self):
conf = 'brackets: disable'
self.check('---\n'
'array1: []\n'
'array2: [ ]\n'
'array3: [ a, b]\n'
'array4: [a, b, c ]\n'
'array5: [a, b, c ]\n'
'array6: [ a, b, c ]\n'
'array7: [ a, b, c ]\n', conf)
def test_min_spaces(self):
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf, problem=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [a, b]\n', conf, problem1=(2, 9), problem2=(2, 13))
self.check('---\n'
'array: [ a, b ]\n', conf)
self.check('---\n'
'array: [\n'
' a,\n'
' b\n'
']\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 3\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: [ a, b ]\n', conf,
problem1=(2, 10), problem2=(2, 15))
self.check('---\n'
'array: [ a, b ]\n', conf)
def test_max_spaces(self):
conf = ('brackets:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 9))
self.check('---\n'
'array: [a, b]\n', conf)
self.check('---\n'
'array: [ a, b ]\n', conf,
problem1=(2, 9), problem2=(2, 14))
self.check('---\n'
'array: [ a, b ]\n', conf,
problem1=(2, 11), problem2=(2, 18))
self.check('---\n'
'array: [\n'
' a,\n'
' b\n'
']\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: 3\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: [ a, b ]\n', conf)
self.check('---\n'
'array: [ a, b ]\n', conf,
problem1=(2, 12), problem2=(2, 21))
def test_min_and_max_spaces(self):
conf = ('brackets:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 9))
self.check('---\n'
'array: [ a, b]\n', conf, problem=(2, 11))
conf = ('brackets:\n'
' max-spaces-inside: 1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: [a, b, c ]\n', conf, problem=(2, 9))
conf = ('brackets:\n'
' max-spaces-inside: 2\n'
' min-spaces-inside: 0\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: [a, b, c ]\n', conf)
self.check('---\n'
'array: [ a, b, c ]\n', conf)
self.check('---\n'
'array: [ a, b, c ]\n', conf, problem=(2, 11))
def test_min_spaces_empty(self):
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: 0\n')
self.check('---\n'
'array: []\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: []\n', conf, problem=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: -1\n'
' min-spaces-inside-empty: 3\n')
self.check('---\n'
'array: []\n', conf, problem=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
def test_max_spaces_empty(self):
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 9))
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 10))
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 3\n'
' min-spaces-inside-empty: -1\n')
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 12))
def test_min_and_max_spaces_empty(self):
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 2\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: []\n', conf, problem=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [ ]\n', conf, problem=(2, 11))
def test_mixed_empty_nonempty(self):
conf = ('brackets:\n'
' max-spaces-inside: -1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 0\n'
' min-spaces-inside-empty: 0\n')
self.check('---\n'
'array: [ a, b ]\n', conf)
self.check('---\n'
'array: [a, b]\n', conf,
problem1=(2, 9), problem2=(2, 13))
self.check('---\n'
'array: []\n', conf)
self.check('---\n'
'array: [ ]\n', conf,
problem1=(2, 9))
conf = ('brackets:\n'
' max-spaces-inside: 0\n'
' min-spaces-inside: -1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: [ a, b ]\n', conf,
problem1=(2, 9), problem2=(2, 14))
self.check('---\n'
'array: [a, b]\n', conf)
self.check('---\n'
'array: []\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
conf = ('brackets:\n'
' max-spaces-inside: 2\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: [ a, b ]\n', conf)
self.check('---\n'
'array: [a, b ]\n', conf,
problem1=(2, 9), problem2=(2, 15))
self.check('---\n'
'array: []\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
self.check('---\n'
'array: [ ]\n', conf,
problem1=(2, 11))
conf = ('brackets:\n'
' max-spaces-inside: 1\n'
' min-spaces-inside: 1\n'
' max-spaces-inside-empty: 1\n'
' min-spaces-inside-empty: 1\n')
self.check('---\n'
'array: [ a, b ]\n', conf)
self.check('---\n'
'array: [a, b]\n', conf,
problem1=(2, 9), problem2=(2, 13))
self.check('---\n'
'array: []\n', conf,
problem1=(2, 9))
self.check('---\n'
'array: [ ]\n', conf)
yamllint-1.10.0/tests/rules/test_line_length.py 0000644 0002322 0002322 00000014571 13177553503 022206 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class LineLengthTestCase(RuleTestCase):
rule_id = 'line-length'
def test_disabled(self):
conf = ('line-length: disable\n'
'empty-lines: disable\n'
'new-line-at-end-of-file: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('---\n', conf)
self.check(81 * 'a', conf)
self.check('---\n' + 81 * 'a' + '\n', conf)
self.check(1000 * 'b', conf)
self.check('---\n' + 1000 * 'b' + '\n', conf)
self.check('content: |\n'
' {% this line is' + 99 * ' really' + ' long %}\n',
conf)
def test_default(self):
conf = ('line-length: {max: 80}\n'
'empty-lines: disable\n'
'new-line-at-end-of-file: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('---\n', conf)
self.check(80 * 'a', conf)
self.check('---\n' + 80 * 'a' + '\n', conf)
self.check(16 * 'aaaa ' + 'z', conf, problem=(1, 81))
self.check('---\n' + 16 * 'aaaa ' + 'z' + '\n', conf, problem=(2, 81))
self.check(1000 * 'word ' + 'end', conf, problem=(1, 81))
self.check('---\n' + 1000 * 'word ' + 'end\n', conf, problem=(2, 81))
def test_max_length_10(self):
conf = ('line-length: {max: 10}\n'
'new-line-at-end-of-file: disable\n')
self.check('---\nABCD EFGHI', conf)
self.check('---\nABCD EFGHIJ', conf, problem=(2, 11))
self.check('---\nABCD EFGHIJ\n', conf, problem=(2, 11))
def test_spaces(self):
conf = ('line-length: {max: 80}\n'
'new-line-at-end-of-file: disable\n'
'trailing-spaces: disable\n')
self.check('---\n' + 81 * ' ', conf, problem=(2, 81))
self.check('---\n' + 81 * ' ' + '\n', conf, problem=(2, 81))
def test_non_breakable_word(self):
conf = 'line-length: {max: 20, allow-non-breakable-words: true}'
self.check('---\n' + 30 * 'A' + '\n', conf)
self.check('---\n'
'this:\n'
' is:\n'
' - a:\n'
' http://localhost/very/long/url\n'
'...\n', conf)
self.check('---\n'
'this:\n'
' is:\n'
' - a:\n'
' # http://localhost/very/long/url\n'
' comment\n'
'...\n', conf)
self.check('---\n'
'this:\n'
'is:\n'
'another:\n'
' - https://localhost/very/very/long/url\n'
'...\n', conf)
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n', conf,
problem=(2, 21))
conf = 'line-length: {max: 20, allow-non-breakable-words: false}'
self.check('---\n' + 30 * 'A' + '\n', conf, problem=(2, 21))
self.check('---\n'
'this:\n'
' is:\n'
' - a:\n'
' http://localhost/very/long/url\n'
'...\n', conf, problem=(5, 21))
self.check('---\n'
'this:\n'
' is:\n'
' - a:\n'
' # http://localhost/very/long/url\n'
' comment\n'
'...\n', conf, problem=(5, 21))
self.check('---\n'
'this:\n'
'is:\n'
'another:\n'
' - https://localhost/very/very/long/url\n'
'...\n', conf, problem=(5, 21))
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n'
'...\n', conf, problem=(2, 21))
conf = ('line-length: {max: 20, allow-non-breakable-words: true}\n'
'trailing-spaces: disable')
self.check('---\n'
'loooooooooong+word+and+some+space+at+the+end \n',
conf, problem=(2, 21))
def test_non_breakable_inline_mappings(self):
conf = 'line-length: {max: 20, ' \
'allow-non-breakable-inline-mappings: true}'
self.check('---\n'
'long_line: http://localhost/very/very/long/url\n'
'long line: http://localhost/very/very/long/url\n', conf)
self.check('---\n'
'- long line: http://localhost/very/very/long/url\n', conf)
self.check('---\n'
'long_line: http://localhost/short/url + word\n'
'long line: http://localhost/short/url + word\n',
conf, problem1=(2, 21), problem2=(3, 21))
conf = ('line-length: {max: 20,'
' allow-non-breakable-inline-mappings: true}\n'
'trailing-spaces: disable')
self.check('---\n'
'long_line: and+some+space+at+the+end \n',
conf, problem=(2, 21))
self.check('---\n'
'long line: and+some+space+at+the+end \n',
conf, problem=(2, 21))
self.check('---\n'
'- long line: and+some+space+at+the+end \n',
conf, problem=(2, 21))
# See https://github.com/adrienverge/yamllint/issues/21
conf = 'line-length: {allow-non-breakable-inline-mappings: true}'
self.check('---\n'
'content: |\n'
' {% this line is' + 99 * ' really' + ' long %}\n',
conf, problem=(3, 81))
yamllint-1.10.0/tests/rules/test_trailing_spaces.py 0000644 0002322 0002322 00000003345 13177553503 023062 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class TrailingSpacesTestCase(RuleTestCase):
rule_id = 'trailing-spaces'
def test_disabled(self):
conf = 'trailing-spaces: disable'
self.check('', conf)
self.check('\n', conf)
self.check(' \n', conf)
self.check('---\n'
'some: text \n', conf)
def test_enabled(self):
conf = 'trailing-spaces: enable'
self.check('', conf)
self.check('\n', conf)
self.check(' \n', conf, problem=(1, 1))
self.check('\t\t\t\n', conf, problem=(1, 1, 'syntax'))
self.check('---\n'
'some: text \n', conf, problem=(2, 11))
self.check('---\n'
'some: text\t\n', conf, problem=(2, 11, 'syntax'))
def test_with_dos_new_lines(self):
conf = ('trailing-spaces: enable\n'
'new-lines: {type: dos}\n')
self.check('---\r\n'
'some: text\r\n', conf)
self.check('---\r\n'
'some: text \r\n', conf, problem=(2, 11))
yamllint-1.10.0/tests/rules/test_new_line_at_end_of_file.py 0000644 0002322 0002322 00000003023 13177553503 024501 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class NewLineAtEndOfFileTestCase(RuleTestCase):
rule_id = 'new-line-at-end-of-file'
def test_disabled(self):
conf = ('new-line-at-end-of-file: disable\n'
'empty-lines: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('word', conf)
self.check('Sentence.\n', conf)
def test_enabled(self):
conf = ('new-line-at-end-of-file: enable\n'
'empty-lines: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('word', conf, problem=(1, 5))
self.check('Sentence.\n', conf)
self.check('---\n'
'yaml: document\n'
'...', conf, problem=(3, 4))
yamllint-1.10.0/tests/rules/test_document_end.py 0000644 0002322 0002322 00000004733 13177553503 022361 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class DocumentEndTestCase(RuleTestCase):
rule_id = 'document-end'
def test_disabled(self):
conf = 'document-end: disable'
self.check('---\n'
'with:\n'
' document: end\n'
'...\n', conf)
self.check('---\n'
'without:\n'
' document: end\n', conf)
def test_required(self):
conf = 'document-end: {present: true}'
self.check('', conf)
self.check('\n', conf)
self.check('---\n'
'with:\n'
' document: end\n'
'...\n', conf)
self.check('---\n'
'without:\n'
' document: end\n', conf, problem=(3, 1))
def test_forbidden(self):
conf = 'document-end: {present: false}'
self.check('---\n'
'with:\n'
' document: end\n'
'...\n', conf, problem=(4, 1))
self.check('---\n'
'without:\n'
' document: end\n', conf)
def test_multiple_documents(self):
conf = ('document-end: {present: true}\n'
'document-start: disable\n')
self.check('---\n'
'first: document\n'
'...\n'
'---\n'
'second: document\n'
'...\n'
'---\n'
'third: document\n'
'...\n', conf)
self.check('---\n'
'first: document\n'
'...\n'
'---\n'
'second: document\n'
'---\n'
'third: document\n'
'...\n', conf, problem=(6, 1))
yamllint-1.10.0/tests/rules/__init__.py 0000644 0002322 0002322 00000000000 13177553503 020374 0 ustar debalance debalance yamllint-1.10.0/tests/rules/test_empty_values.py 0000644 0002322 0002322 00000023570 13177553503 022432 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2017 Greg Dubicki
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class EmptyValuesTestCase(RuleTestCase):
rule_id = 'empty-values'
def test_disabled(self):
conf = ('empty-values: disable\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'foo:\n', conf)
self.check('---\n'
'foo:\n'
' bar:\n', conf)
self.check('---\n'
'{a:}\n', conf)
self.check('---\n'
'foo: {a:}\n', conf)
self.check('---\n'
'- {a:}\n'
'- {a:, b: 2}\n'
'- {a: 1, b:}\n'
'- {a: 1, b: , }\n', conf)
self.check('---\n'
'{a: {b: , c: {d: 4, e:}}, f:}\n', conf)
def test_in_block_mappings_disabled(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n', conf)
self.check('---\n'
'foo:\n'
'bar: aaa\n', conf)
def test_in_block_mappings_single_line(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'implicitly-null:\n', conf, problem1=(2, 17))
self.check('---\n'
'implicitly-null:with-colons:in-key:\n', conf,
problem1=(2, 36))
self.check('---\n'
'implicitly-null:with-colons:in-key2:\n', conf,
problem1=(2, 37))
def test_in_block_mappings_all_lines(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
'bar:\n'
'foobar:\n', conf, problem1=(2, 5),
problem2=(3, 5), problem3=(4, 8))
def test_in_block_mappings_explicit_end_of_document(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
'...\n', conf, problem1=(2, 5))
def test_in_block_mappings_not_end_of_document(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
'bar:\n'
' aaa\n', conf, problem1=(2, 5))
def test_in_block_mappings_different_level(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
' bar:\n'
'aaa: bbb\n', conf, problem1=(3, 6))
def test_in_block_mappings_empty_flow_mapping(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'foo: {a:}\n', conf)
self.check('---\n'
'- {a:, b: 2}\n'
'- {a: 1, b:}\n'
'- {a: 1, b: , }\n', conf)
def test_in_block_mappings_empty_block_sequence(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
' -\n', conf)
def test_in_block_mappings_not_empty_or_explicit_null(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'foo:\n'
' bar:\n'
' aaa\n', conf)
self.check('---\n'
'explicitly-null: null\n', conf)
self.check('---\n'
'explicitly-null:with-colons:in-key: null\n', conf)
self.check('---\n'
'false-null: nulL\n', conf)
self.check('---\n'
'empty-string: \'\'\n', conf)
self.check('---\n'
'nullable-boolean: false\n', conf)
self.check('---\n'
'nullable-int: 0\n', conf)
self.check('---\n'
'First occurrence: &anchor Foo\n'
'Second occurrence: *anchor\n', conf)
def test_in_block_mappings_various_explicit_null(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n')
self.check('---\n'
'null-alias: ~\n', conf)
self.check('---\n'
'null-key1: {?: val}\n', conf)
self.check('---\n'
'null-key2: {? !!null "": val}\n', conf)
def test_in_block_mappings_comments(self):
conf = ('empty-values: {forbid-in-block-mappings: true,\n'
' forbid-in-flow-mappings: false}\n'
'comments: disable\n')
self.check('---\n'
'empty: # comment\n'
'foo:\n'
' bar: # comment\n', conf,
problem1=(2, 7),
problem2=(4, 7))
def test_in_flow_mappings_disabled(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: false}\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'{a:}\n', conf)
self.check('---\n'
'foo: {a:}\n', conf)
self.check('---\n'
'- {a:}\n'
'- {a:, b: 2}\n'
'- {a: 1, b:}\n'
'- {a: 1, b: , }\n', conf)
self.check('---\n'
'{a: {b: , c: {d: 4, e:}}, f:}\n', conf)
def test_in_flow_mappings_single_line(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: true}\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'{a:}\n', conf,
problem=(2, 4))
self.check('---\n'
'foo: {a:}\n', conf,
problem=(2, 9))
self.check('---\n'
'- {a:}\n'
'- {a:, b: 2}\n'
'- {a: 1, b:}\n'
'- {a: 1, b: , }\n', conf,
problem1=(2, 6),
problem2=(3, 6),
problem3=(4, 12),
problem4=(5, 12))
self.check('---\n'
'{a: {b: , c: {d: 4, e:}}, f:}\n', conf,
problem1=(2, 8),
problem2=(2, 23),
problem3=(2, 29))
def test_in_flow_mappings_multi_line(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: true}\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'foo: {\n'
' a:\n'
'}\n', conf,
problem=(3, 5))
self.check('---\n'
'{\n'
' a: {\n'
' b: ,\n'
' c: {\n'
' d: 4,\n'
' e:\n'
' }\n'
' },\n'
' f:\n'
'}\n', conf,
problem1=(4, 7),
problem2=(7, 9),
problem3=(10, 5))
def test_in_flow_mappings_various_explicit_null(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: true}\n'
'braces: disable\n'
'commas: disable\n')
self.check('---\n'
'{explicit-null: null}\n', conf)
self.check('---\n'
'{null-alias: ~}\n', conf)
self.check('---\n'
'null-key1: {?: val}\n', conf)
self.check('---\n'
'null-key2: {? !!null "": val}\n', conf)
def test_in_flow_mappings_comments(self):
conf = ('empty-values: {forbid-in-block-mappings: false,\n'
' forbid-in-flow-mappings: true}\n'
'braces: disable\n'
'commas: disable\n'
'comments: disable\n')
self.check('---\n'
'{\n'
' a: {\n'
' b: , # comment\n'
' c: {\n'
' d: 4, # comment\n'
' e: # comment\n'
' }\n'
' },\n'
' f: # comment\n'
'}\n', conf,
problem1=(4, 7),
problem2=(7, 9),
problem3=(10, 5))
yamllint-1.10.0/tests/rules/test_hyphens.py 0000644 0002322 0002322 00000007247 13177553503 021376 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class HyphenTestCase(RuleTestCase):
rule_id = 'hyphens'
def test_disabled(self):
conf = 'hyphens: disable'
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'object:\n'
' - elem1\n'
' - elem2\n', conf)
self.check('---\n'
'object:\n'
' - elem1\n'
' - elem2\n', conf)
self.check('---\n'
'object:\n'
' subobject:\n'
' - elem1\n'
' - elem2\n', conf)
self.check('---\n'
'object:\n'
' subobject:\n'
' - elem1\n'
' - elem2\n', conf)
def test_enabled(self):
conf = 'hyphens: {max-spaces-after: 1}'
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'- elem1\n'
'- elem2\n', conf, problem=(3, 3))
self.check('---\n'
'- elem1\n'
'- elem2\n', conf, problem1=(2, 3), problem2=(3, 3))
self.check('---\n'
'- elem1\n'
'- elem2\n', conf, problem=(2, 3))
self.check('---\n'
'object:\n'
' - elem1\n'
' - elem2\n', conf, problem=(4, 5))
self.check('---\n'
'object:\n'
' - elem1\n'
' - elem2\n', conf, problem1=(3, 5), problem2=(4, 5))
self.check('---\n'
'object:\n'
' subobject:\n'
' - elem1\n'
' - elem2\n', conf, problem=(5, 7))
self.check('---\n'
'object:\n'
' subobject:\n'
' - elem1\n'
' - elem2\n', conf, problem1=(4, 7), problem2=(5, 7))
def test_max_3(self):
conf = 'hyphens: {max-spaces-after: 3}'
self.check('---\n'
'- elem1\n'
'- elem2\n', conf)
self.check('---\n'
'- elem1\n'
'- elem2\n', conf, problem=(2, 5))
self.check('---\n'
'a:\n'
' b:\n'
' - elem1\n'
' - elem2\n', conf)
self.check('---\n'
'a:\n'
' b:\n'
' - elem1\n'
' - elem2\n', conf, problem1=(4, 9), problem2=(5, 9))
yamllint-1.10.0/tests/rules/test_truthy.py 0000644 0002322 0002322 00000004666 13177553503 021261 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Peter Ericson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class TruthyTestCase(RuleTestCase):
rule_id = 'truthy'
def test_disabled(self):
conf = 'truthy: disable'
self.check('---\n'
'1: True\n', conf)
self.check('---\n'
'True: 1\n', conf)
def test_enabled(self):
conf = 'truthy: enable\n'
self.check('---\n'
'1: True\n'
'True: 1\n',
conf, problem1=(2, 4), problem2=(3, 1))
self.check('---\n'
'1: "True"\n'
'"True": 1\n', conf)
self.check('---\n'
'[\n'
' true, false,\n'
' "false", "FALSE",\n'
' "true", "True",\n'
' True, FALSE,\n'
' on, OFF,\n'
' NO, Yes\n'
']\n', conf,
problem1=(6, 3), problem2=(6, 9),
problem3=(7, 3), problem4=(7, 7),
problem5=(8, 3), problem6=(8, 7))
def test_explicit_types(self):
conf = 'truthy: enable\n'
self.check('---\n'
'string1: !!str True\n'
'string2: !!str yes\n'
'string3: !!str off\n'
'encoded: !!binary |\n'
' True\n'
' OFF\n'
' pad==\n' # this decodes as 'N\xbb\x9e8Qii'
'boolean1: !!bool true\n'
'boolean2: !!bool "false"\n'
'boolean3: !!bool FALSE\n'
'boolean4: !!bool True\n'
'boolean5: !!bool off\n'
'boolean6: !!bool NO\n',
conf)
yamllint-1.10.0/tests/rules/test_commas.py 0000644 0002322 0002322 00000023517 13177553503 021175 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class CommaTestCase(RuleTestCase):
rule_id = 'commas'
def test_disabled(self):
conf = 'commas: disable'
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e , f: [g, h]}\n'
'array: [\n'
' elem ,\n'
' key: val ,\n'
']\n'
'map: {\n'
' key1: val1 ,\n'
' key2: val2,\n'
'}\n'
'...\n', conf)
self.check('---\n'
'- [one, two , three,four]\n'
'- {five,six , seven, eight}\n'
'- [\n'
' nine, ten\n'
' , eleven\n'
' ,twelve\n'
']\n'
'- {\n'
' thirteen: 13, fourteen\n'
' , fifteen: 15\n'
' ,sixteen: 16\n'
'}\n', conf)
def test_before_max(self):
conf = ('commas:\n'
' max-spaces-before: 0\n'
' min-spaces-after: 0\n'
' max-spaces-after: -1\n')
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf)
self.check('---\n'
'array: [1, 2 , 3, 4]\n'
'...\n', conf, problem=(2, 13))
self.check('---\n'
'array: [1 , 2, 3 , 4]\n'
'...\n', conf, problem1=(2, 10), problem2=(2, 23))
self.check('---\n'
'dict: {a: b, c: "1 2 3", d: e, f: [g, h]}\n'
'...\n', conf)
self.check('---\n'
'dict: {a: b, c: "1 2 3" , d: e, f: [g, h]}\n'
'...\n', conf, problem=(2, 24))
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e, f: [g , h]}\n'
'...\n', conf, problem1=(2, 12), problem2=(2, 42))
self.check('---\n'
'array: [\n'
' elem,\n'
' key: val,\n'
']\n', conf)
self.check('---\n'
'array: [\n'
' elem ,\n'
' key: val,\n'
']\n', conf, problem=(3, 7))
self.check('---\n'
'map: {\n'
' key1: val1,\n'
' key2: val2,\n'
'}\n', conf)
self.check('---\n'
'map: {\n'
' key1: val1,\n'
' key2: val2 ,\n'
'}\n', conf, problem=(4, 13))
def test_before_max_with_comma_on_new_line(self):
conf = ('commas:\n'
' max-spaces-before: 0\n'
' min-spaces-after: 0\n'
' max-spaces-after: -1\n')
self.check('---\n'
'flow-seq: [1, 2, 3\n'
' , 4, 5, 6]\n'
'...\n', conf, problem=(3, 11))
self.check('---\n'
'flow-map: {a: 1, b: 2\n'
' , c: 3}\n'
'...\n', conf, problem=(3, 11))
conf = ('commas:\n'
' max-spaces-before: 0\n'
' min-spaces-after: 0\n'
' max-spaces-after: -1\n'
'indentation: disable\n')
self.check('---\n'
'flow-seq: [1, 2, 3\n'
' , 4, 5, 6]\n'
'...\n', conf, problem=(3, 9))
self.check('---\n'
'flow-map: {a: 1, b: 2\n'
' , c: 3}\n'
'...\n', conf, problem=(3, 9))
self.check('---\n'
'[\n'
'1,\n'
'2\n'
', 3\n'
']\n', conf, problem=(5, 1))
self.check('---\n'
'{\n'
'a: 1,\n'
'b: 2\n'
', c: 3\n'
'}\n', conf, problem=(5, 1))
def test_before_max_3(self):
conf = ('commas:\n'
' max-spaces-before: 3\n'
' min-spaces-after: 0\n'
' max-spaces-after: -1\n')
self.check('---\n'
'array: [1 , 2, 3 , 4]\n'
'...\n', conf)
self.check('---\n'
'array: [1 , 2, 3 , 4]\n'
'...\n', conf, problem=(2, 20))
self.check('---\n'
'array: [\n'
' elem1 ,\n'
' elem2 ,\n'
' key: val,\n'
']\n', conf, problem=(4, 11))
def test_after_min(self):
conf = ('commas:\n'
' max-spaces-before: -1\n'
' min-spaces-after: 1\n'
' max-spaces-after: -1\n')
self.check('---\n'
'- [one, two , three,four]\n'
'- {five,six , seven, eight}\n'
'- [\n'
' nine, ten\n'
' , eleven\n'
' ,twelve\n'
']\n'
'- {\n'
' thirteen: 13, fourteen\n'
' , fifteen: 15\n'
' ,sixteen: 16\n'
'}\n', conf,
problem1=(2, 21), problem2=(3, 9),
problem3=(7, 4), problem4=(12, 4))
def test_after_max(self):
conf = ('commas:\n'
' max-spaces-before: -1\n'
' min-spaces-after: 0\n'
' max-spaces-after: 1\n')
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf)
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf, problem=(2, 15))
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf, problem1=(2, 12), problem2=(2, 22))
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n'
'...\n', conf)
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n'
'...\n', conf, problem=(2, 27))
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n'
'...\n', conf, problem1=(2, 15), problem2=(2, 44))
self.check('---\n'
'array: [\n'
' elem,\n'
' key: val,\n'
']\n', conf)
self.check('---\n'
'array: [\n'
' elem, key: val,\n'
']\n', conf, problem=(3, 9))
self.check('---\n'
'map: {\n'
' key1: val1, key2: [val2, val3]\n'
'}\n', conf, problem1=(3, 16), problem2=(3, 30))
def test_after_max_3(self):
conf = ('commas:\n'
' max-spaces-before: -1\n'
' min-spaces-after: 1\n'
' max-spaces-after: 3\n')
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf)
self.check('---\n'
'array: [1, 2, 3, 4]\n'
'...\n', conf, problem=(2, 21))
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e, f: [g, h]}\n'
'...\n', conf, problem1=(2, 31), problem2=(2, 49))
def test_both_before_and_after(self):
conf = ('commas:\n'
' max-spaces-before: 0\n'
' min-spaces-after: 1\n'
' max-spaces-after: 1\n')
self.check('---\n'
'dict: {a: b , c: "1 2 3", d: e , f: [g, h]}\n'
'array: [\n'
' elem ,\n'
' key: val ,\n'
']\n'
'map: {\n'
' key1: val1 ,\n'
' key2: val2,\n'
'}\n'
'...\n', conf,
problem1=(2, 12), problem2=(2, 16), problem3=(2, 31),
problem4=(2, 36), problem5=(2, 50), problem6=(4, 8),
problem7=(5, 11), problem8=(8, 13))
conf = ('commas:\n'
' max-spaces-before: 0\n'
' min-spaces-after: 1\n'
' max-spaces-after: 1\n'
'indentation: disable\n')
self.check('---\n'
'- [one, two , three,four]\n'
'- {five,six , seven, eight}\n'
'- [\n'
' nine, ten\n'
' , eleven\n'
' ,twelve\n'
']\n'
'- {\n'
' thirteen: 13, fourteen\n'
' , fifteen: 15\n'
' ,sixteen: 16\n'
'}\n', conf,
problem1=(2, 12), problem2=(2, 21), problem3=(3, 9),
problem4=(3, 12), problem5=(5, 9), problem6=(6, 2),
problem7=(7, 2), problem8=(7, 4), problem9=(10, 17),
problem10=(11, 2), problem11=(12, 2), problem12=(12, 4))
yamllint-1.10.0/tests/rules/test_key_duplicates.py 0000644 0002322 0002322 00000013263 13177553503 022720 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class KeyDuplicatesTestCase(RuleTestCase):
rule_id = 'key-duplicates'
def test_disabled(self):
conf = 'key-duplicates: disable'
self.check('---\n'
'block mapping:\n'
' key: a\n'
' otherkey: b\n'
' key: c\n', conf)
self.check('---\n'
'flow mapping:\n'
' {key: a, otherkey: b, key: c}\n', conf)
self.check('---\n'
'duplicated twice:\n'
' - k: a\n'
' ok: b\n'
' k: c\n'
' k: d\n', conf)
self.check('---\n'
'duplicated twice:\n'
' - {k: a, ok: b, k: c, k: d}\n', conf)
self.check('---\n'
'multiple duplicates:\n'
' a: 1\n'
' b: 2\n'
' c: 3\n'
' d: 4\n'
' d: 5\n'
' b: 6\n', conf)
self.check('---\n'
'multiple duplicates:\n'
' {a: 1, b: 2, c: 3, d: 4, d: 5, b: 6}\n', conf)
self.check('---\n'
'at: root\n'
'multiple: times\n'
'at: root\n', conf)
self.check('---\n'
'nested but OK:\n'
' a: {a: {a: 1}}\n'
' b:\n'
' b: 2\n'
' c: 3\n', conf)
self.check('---\n'
'nested duplicates:\n'
' a: {a: 1, a: 1}\n'
' b:\n'
' c: 3\n'
' d: 4\n'
' d: 4\n'
' b: 2\n', conf)
self.check('---\n'
'duplicates with many styles: 1\n'
'"duplicates with many styles": 1\n'
'\'duplicates with many styles\': 1\n'
'? duplicates with many styles\n'
': 1\n'
'? >-\n'
' duplicates with\n'
' many styles\n'
': 1\n', conf)
def test_enabled(self):
conf = 'key-duplicates: enable'
self.check('---\n'
'block mapping:\n'
' key: a\n'
' otherkey: b\n'
' key: c\n', conf,
problem=(5, 3))
self.check('---\n'
'flow mapping:\n'
' {key: a, otherkey: b, key: c}\n', conf,
problem=(3, 25))
self.check('---\n'
'duplicated twice:\n'
' - k: a\n'
' ok: b\n'
' k: c\n'
' k: d\n', conf,
problem1=(5, 5), problem2=(6, 5))
self.check('---\n'
'duplicated twice:\n'
' - {k: a, ok: b, k: c, k: d}\n', conf,
problem1=(3, 19), problem2=(3, 25))
self.check('---\n'
'multiple duplicates:\n'
' a: 1\n'
' b: 2\n'
' c: 3\n'
' d: 4\n'
' d: 5\n'
' b: 6\n', conf,
problem1=(7, 3), problem2=(8, 3))
self.check('---\n'
'multiple duplicates:\n'
' {a: 1, b: 2, c: 3, d: 4, d: 5, b: 6}\n', conf,
problem1=(3, 28), problem2=(3, 34))
self.check('---\n'
'at: root\n'
'multiple: times\n'
'at: root\n', conf,
problem=(4, 1))
self.check('---\n'
'nested but OK:\n'
' a: {a: {a: 1}}\n'
' b:\n'
' b: 2\n'
' c: 3\n', conf)
self.check('---\n'
'nested duplicates:\n'
' a: {a: 1, a: 1}\n'
' b:\n'
' c: 3\n'
' d: 4\n'
' d: 4\n'
' b: 2\n', conf,
problem1=(3, 13), problem2=(7, 5), problem3=(8, 3))
self.check('---\n'
'duplicates with many styles: 1\n'
'"duplicates with many styles": 1\n'
'\'duplicates with many styles\': 1\n'
'? duplicates with many styles\n'
': 1\n'
'? >-\n'
' duplicates with\n'
' many styles\n'
': 1\n', conf,
problem1=(3, 1), problem2=(4, 1), problem3=(5, 3),
problem4=(7, 3))
def test_key_tokens_in_flow_sequences(self):
conf = 'key-duplicates: enable'
self.check('---\n'
'[\n'
' flow: sequence, with, key: value, mappings\n'
']\n', conf)
yamllint-1.10.0/tests/rules/test_document_start.py 0000644 0002322 0002322 00000006722 13177553503 022750 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class DocumentStartTestCase(RuleTestCase):
rule_id = 'document-start'
def test_disabled(self):
conf = 'document-start: disable'
self.check('', conf)
self.check('key: val\n', conf)
self.check('---\n'
'key: val\n', conf)
def test_required(self):
conf = ('document-start: {present: true}\n'
'empty-lines: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('key: val\n', conf, problem=(1, 1))
self.check('\n'
'\n'
'key: val\n', conf, problem=(3, 1))
self.check('---\n'
'key: val\n', conf)
self.check('\n'
'\n'
'---\n'
'key: val\n', conf)
def test_forbidden(self):
conf = ('document-start: {present: false}\n'
'empty-lines: disable\n')
self.check('', conf)
self.check('key: val\n', conf)
self.check('\n'
'\n'
'key: val\n', conf)
self.check('---\n'
'key: val\n', conf, problem=(1, 1))
self.check('\n'
'\n'
'---\n'
'key: val\n', conf, problem=(3, 1))
self.check('first: document\n'
'---\n'
'key: val\n', conf, problem=(2, 1))
def test_multiple_documents(self):
conf = 'document-start: {present: true}'
self.check('---\n'
'first: document\n'
'...\n'
'---\n'
'second: document\n'
'...\n'
'---\n'
'third: document\n', conf)
self.check('---\n'
'first: document\n'
'---\n'
'second: document\n'
'---\n'
'third: document\n', conf)
self.check('---\n'
'first: document\n'
'...\n'
'second: document\n'
'---\n'
'third: document\n', conf, problem=(4, 1, 'syntax'))
def test_directives(self):
conf = 'document-start: {present: true}'
self.check('%YAML 1.2\n'
'---\n'
'doc: ument\n'
'...\n', conf)
self.check('%YAML 1.2\n'
'%TAG ! tag:clarkevans.com,2002:\n'
'---\n'
'doc: ument\n'
'...\n', conf)
self.check('---\n'
'doc: 1\n'
'...\n'
'%YAML 1.2\n'
'---\n'
'doc: 2\n'
'...\n', conf)
yamllint-1.10.0/tests/rules/test_key_ordering.py 0000644 0002322 0002322 00000007553 13177553503 022401 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2017 Johannes F. Knauf
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class KeyOrderingTestCase(RuleTestCase):
rule_id = 'key-ordering'
def test_disabled(self):
conf = 'key-ordering: disable'
self.check('---\n'
'block mapping:\n'
' secondkey: a\n'
' firstkey: b\n', conf)
self.check('---\n'
'flow mapping:\n'
' {secondkey: a, firstkey: b}\n', conf)
self.check('---\n'
'second: before_first\n'
'at: root\n', conf)
self.check('---\n'
'nested but OK:\n'
' second: {first: 1}\n'
' third:\n'
' second: 2\n', conf)
def test_enabled(self):
conf = 'key-ordering: enable'
self.check('---\n'
'block mapping:\n'
' secondkey: a\n'
' firstkey: b\n', conf,
problem=(4, 3))
self.check('---\n'
'flow mapping:\n'
' {secondkey: a, firstkey: b}\n', conf,
problem=(3, 18))
self.check('---\n'
'second: before_first\n'
'at: root\n', conf,
problem=(3, 1))
self.check('---\n'
'nested but OK:\n'
' second: {first: 1}\n'
' third:\n'
' second: 2\n', conf)
def test_word_length(self):
conf = 'key-ordering: enable'
self.check('---\n'
'a: 1\n'
'ab: 1\n'
'abc: 1\n', conf)
self.check('---\n'
'a: 1\n'
'abc: 1\n'
'ab: 1\n', conf,
problem=(4, 1))
def test_key_duplicates(self):
conf = ('key-duplicates: disable\n'
'key-ordering: enable')
self.check('---\n'
'key: 1\n'
'key: 2\n', conf)
def test_case(self):
conf = 'key-ordering: enable'
self.check('---\n'
'T-shirt: 1\n'
'T-shirts: 2\n'
't-shirt: 3\n'
't-shirts: 4\n', conf)
self.check('---\n'
'T-shirt: 1\n'
't-shirt: 2\n'
'T-shirts: 3\n'
't-shirts: 4\n', conf,
problem=(4, 1))
def test_accents(self):
conf = 'key-ordering: enable'
self.check('---\n'
'hair: true\n'
'hais: true\n'
'haïr: true\n'
'haïssable: true\n', conf)
self.check('---\n'
'haïr: true\n'
'hais: true\n', conf,
problem=(3, 1))
self.check('---\n'
'haïr: true\n'
'hais: true\n', conf,
problem=(3, 1))
def test_key_tokens_in_flow_sequences(self):
conf = 'key-ordering: enable'
self.check('---\n'
'[\n'
' key: value, mappings, in, flow: sequence\n'
']\n', conf)
yamllint-1.10.0/tests/rules/test_new_lines.py 0000644 0002322 0002322 00000003235 13177553503 021674 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class NewLinesTestCase(RuleTestCase):
rule_id = 'new-lines'
def test_disabled(self):
conf = ('new-line-at-end-of-file: disable\n'
'new-lines: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('\r', conf)
self.check('\r\n', conf)
self.check('---\ntext\n', conf)
self.check('---\r\ntext\r\n', conf)
def test_unix_type(self):
conf = 'new-lines: {type: unix}'
self.check('', conf)
self.check('\n', conf)
self.check('\r\n', conf, problem=(1, 1))
self.check('---\ntext\n', conf)
self.check('---\r\ntext\r\n', conf, problem=(1, 4))
def test_dos_type(self):
conf = 'new-lines: {type: dos}\n'
self.check('', conf)
self.check('\n', conf, problem=(1, 1))
self.check('\r\n', conf)
self.check('---\ntext\n', conf, problem=(1, 4))
self.check('---\r\ntext\r\n', conf)
yamllint-1.10.0/tests/rules/test_empty_lines.py 0000644 0002322 0002322 00000006463 13177553503 022247 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class EmptyLinesTestCase(RuleTestCase):
rule_id = 'empty-lines'
def test_disabled(self):
conf = ('empty-lines: disable\n'
'new-line-at-end-of-file: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
self.check('\n\n', conf)
self.check('\n\n\n\n\n\n\n\n\n', conf)
self.check('some text\n\n\n\n\n\n\n\n\n', conf)
self.check('\n\n\n\n\n\n\n\n\nsome text', conf)
self.check('\n\n\nsome text\n\n\n', conf)
def test_empty_document(self):
conf = ('empty-lines: {max: 0, max-start: 0, max-end: 0}\n'
'new-line-at-end-of-file: disable\n'
'document-start: disable\n')
self.check('', conf)
self.check('\n', conf)
def test_0_empty_lines(self):
conf = ('empty-lines: {max: 0, max-start: 0, max-end: 0}\n'
'new-line-at-end-of-file: disable\n')
self.check('---\n', conf)
self.check('---\ntext\n\ntext', conf, problem=(3, 1))
self.check('---\ntext\n\ntext\n', conf, problem=(3, 1))
def test_10_empty_lines(self):
conf = 'empty-lines: {max: 10, max-start: 0, max-end: 0}'
self.check('---\nintro\n\n\n\n\n\n\n\n\n\n\nconclusion\n', conf)
self.check('---\nintro\n\n\n\n\n\n\n\n\n\n\n\nconclusion\n', conf,
problem=(13, 1))
def test_spaces(self):
conf = ('empty-lines: {max: 1, max-start: 0, max-end: 0}\n'
'trailing-spaces: disable\n')
self.check('---\nintro\n\n \n\nconclusion\n', conf)
self.check('---\nintro\n\n \n\n\nconclusion\n', conf, problem=(6, 1))
def test_empty_lines_at_start(self):
conf = ('empty-lines: {max: 2, max-start: 4, max-end: 0}\n'
'document-start: disable\n')
self.check('\n\n\n\nnon empty\n', conf)
self.check('\n\n\n\n\nnon empty\n', conf, problem=(5, 1))
conf = ('empty-lines: {max: 2, max-start: 0, max-end: 0}\n'
'document-start: disable\n')
self.check('non empty\n', conf)
self.check('\nnon empty\n', conf, problem=(1, 1))
def test_empty_lines_at_end(self):
conf = ('empty-lines: {max: 2, max-start: 0, max-end: 4}\n'
'document-start: disable\n')
self.check('non empty\n\n\n\n\n', conf)
self.check('non empty\n\n\n\n\n\n', conf, problem=(6, 1))
conf = ('empty-lines: {max: 2, max-start: 0, max-end: 0}\n'
'document-start: disable\n')
self.check('non empty\n', conf)
self.check('non empty\n\n', conf, problem=(2, 1))
yamllint-1.10.0/tests/rules/test_common.py 0000644 0002322 0002322 00000003155 13177553503 021202 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import unittest
import yaml
from yamllint.rules.common import get_line_indent
class CommonTestCase(unittest.TestCase):
def test_get_line_indent(self):
tokens = list(yaml.scan('a: 1\n'
'b:\n'
' - c: [2, 3, {d: 4}]\n'))
self.assertEqual(tokens[3].value, 'a')
self.assertEqual(tokens[5].value, '1')
self.assertEqual(tokens[7].value, 'b')
self.assertEqual(tokens[13].value, 'c')
self.assertEqual(tokens[16].value, '2')
self.assertEqual(tokens[18].value, '3')
self.assertEqual(tokens[22].value, 'd')
self.assertEqual(tokens[24].value, '4')
for i in (3, 5):
self.assertEqual(get_line_indent(tokens[i]), 0)
for i in (7,):
self.assertEqual(get_line_indent(tokens[i]), 0)
for i in (13, 16, 18, 22, 24):
self.assertEqual(get_line_indent(tokens[i]), 2)
yamllint-1.10.0/tests/rules/test_colons.py 0000644 0002322 0002322 00000022102 13177553503 021200 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class ColonTestCase(RuleTestCase):
rule_id = 'colons'
def test_disabled(self):
conf = 'colons: disable'
self.check('---\n'
'object:\n'
' k1 : v1\n'
'obj2:\n'
' k2 :\n'
' - 8\n'
' k3:\n'
' val\n'
' property : value\n'
' prop2 : val2\n'
' propriété : [valeur]\n'
' o:\n'
' k1: [v1, v2]\n'
' p:\n'
' - k3: >\n'
' val\n'
' - o: {k1: v1}\n'
' - p: kdjf\n'
' - q: val0\n'
' - q2:\n'
' - val1\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' k1: v1\n'
'obj2:\n'
' k2:\n'
' - 8\n'
' k3:\n'
' val\n'
' property: value\n'
' prop2: val2\n'
' propriété: [valeur]\n'
' o:\n'
' k1: [v1, v2]\n', conf)
self.check('---\n'
'obj:\n'
' p:\n'
' - k1: >\n'
' val\n'
' - k3: >\n'
' val\n'
' - o: {k1: v1}\n'
' - o: {k1: v1}\n'
' - q2:\n'
' - val1\n'
'...\n', conf)
self.check('---\n'
'a: {b: {c: d, e : f}}\n', conf)
def test_before_enabled(self):
conf = 'colons: {max-spaces-before: 0, max-spaces-after: -1}'
self.check('---\n'
'object:\n'
' k1:\n'
' - a\n'
' - b\n'
' k2: v2\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' k1 :\n'
' - a\n'
' - b\n'
' k2: v2\n'
'...\n', conf, problem=(3, 5))
self.check('---\n'
'lib :\n'
' - var\n'
'...\n', conf, problem=(2, 4))
self.check('---\n'
'- lib :\n'
' - var\n'
'...\n', conf, problem=(2, 6))
self.check('---\n'
'a: {b: {c : d, e : f}}\n', conf,
problem1=(2, 10), problem2=(2, 17))
def test_before_max(self):
conf = 'colons: {max-spaces-before: 3, max-spaces-after: -1}'
self.check('---\n'
'object :\n'
' k1 :\n'
' - a\n'
' - b\n'
' k2 : v2\n'
'...\n', conf)
self.check('---\n'
'object :\n'
' k1 :\n'
' - a\n'
' - b\n'
' k2 : v2\n'
'...\n', conf, problem=(3, 8))
def test_before_with_explicit_block_mappings(self):
conf = 'colons: {max-spaces-before: 0, max-spaces-after: 1}'
self.check('---\n'
'object:\n'
' ? key\n'
' : value\n'
'...\n', conf)
self.check('---\n'
'object :\n'
' ? key\n'
' : value\n'
'...\n', conf, problem=(2, 7))
self.check('---\n'
'? >\n'
' multi-line\n'
' key\n'
': >\n'
' multi-line\n'
' value\n'
'...\n', conf)
self.check('---\n'
'- ? >\n'
' multi-line\n'
' key\n'
' : >\n'
' multi-line\n'
' value\n'
'...\n', conf)
self.check('---\n'
'- ? >\n'
' multi-line\n'
' key\n'
' : >\n'
' multi-line\n'
' value\n'
'...\n', conf, problem=(5, 5))
def test_after_enabled(self):
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}'
self.check('---\n'
'key: value\n', conf)
self.check('---\n'
'key: value\n', conf, problem=(2, 6))
self.check('---\n'
'object:\n'
' k1: [a, b]\n'
' k2: string\n', conf, problem=(3, 7))
self.check('---\n'
'object:\n'
' k1: [a, b]\n'
' k2: string\n', conf, problem=(4, 7))
self.check('---\n'
'object:\n'
' other: {key: value}\n'
'...\n', conf, problem=(3, 16))
self.check('---\n'
'a: {b: {c: d, e : f}}\n', conf,
problem1=(2, 12), problem2=(2, 20))
def test_after_enabled_question_mark(self):
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}'
self.check('---\n'
'? key\n'
': value\n', conf)
self.check('---\n'
'? key\n'
': value\n', conf, problem=(2, 3))
self.check('---\n'
'? key\n'
': value\n', conf, problem1=(2, 3), problem2=(3, 3))
self.check('---\n'
'- ? key\n'
' : value\n', conf, problem1=(2, 5), problem2=(3, 5))
def test_after_max(self):
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 3}'
self.check('---\n'
'object:\n'
' k1: [a, b]\n', conf)
self.check('---\n'
'object:\n'
' k1: [a, b]\n', conf, problem=(3, 9))
self.check('---\n'
'object:\n'
' k2: string\n', conf)
self.check('---\n'
'object:\n'
' k2: string\n', conf, problem=(3, 9))
self.check('---\n'
'object:\n'
' other: {key: value}\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' other: {key: value}\n'
'...\n', conf, problem=(3, 18))
def test_after_with_explicit_block_mappings(self):
conf = 'colons: {max-spaces-before: -1, max-spaces-after: 1}'
self.check('---\n'
'object:\n'
' ? key\n'
' : value\n'
'...\n', conf)
self.check('---\n'
'object:\n'
' ? key\n'
' : value\n'
'...\n', conf, problem=(4, 5))
def test_after_do_not_confound_with_trailing_space(self):
conf = ('colons: {max-spaces-before: 1, max-spaces-after: 1}\n'
'trailing-spaces: disable\n')
self.check('---\n'
'trailing: \n'
' - spaces\n', conf)
def test_both_before_and_after(self):
conf = 'colons: {max-spaces-before: 0, max-spaces-after: 1}'
self.check('---\n'
'obj:\n'
' string: text\n'
' k:\n'
' - 8\n'
' k3:\n'
' val\n'
' property: [value]\n', conf)
self.check('---\n'
'object:\n'
' k1 : v1\n', conf, problem1=(3, 5), problem2=(3, 8))
self.check('---\n'
'obj:\n'
' string: text\n'
' k :\n'
' - 8\n'
' k3:\n'
' val\n'
' property: {a: 1, b: 2, c : 3}\n', conf,
problem1=(3, 11), problem2=(4, 4),
problem3=(8, 23), problem4=(8, 28))
yamllint-1.10.0/tests/rules/test_comments_indentation.py 0000644 0002322 0002322 00000012374 13177553503 024136 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
from tests.common import RuleTestCase
class CommentsIndentationTestCase(RuleTestCase):
rule_id = 'comments-indentation'
def test_disable(self):
conf = 'comments-indentation: disable'
self.check('---\n'
' # line 1\n'
'# line 2\n'
' # line 3\n'
' # line 4\n'
'\n'
'obj:\n'
' # these\n'
' # are\n'
' # [good]\n'
'# bad\n'
' # comments\n'
' a: b\n'
'\n'
'obj1:\n'
' a: 1\n'
' # comments\n'
'\n'
'obj2:\n'
' b: 2\n'
'\n'
'# empty\n'
'#\n'
'# comment\n'
'...\n', conf)
def test_enabled(self):
conf = 'comments-indentation: enable'
self.check('---\n'
'# line 1\n'
'# line 2\n', conf)
self.check('---\n'
' # line 1\n'
'# line 2\n', conf, problem=(2, 2))
self.check('---\n'
' # line 1\n'
' # line 2\n', conf, problem1=(2, 3))
self.check('---\n'
'obj:\n'
' # normal\n'
' a: b\n', conf)
self.check('---\n'
'obj:\n'
' # bad\n'
' a: b\n', conf, problem=(3, 2))
self.check('---\n'
'obj:\n'
'# bad\n'
' a: b\n', conf, problem=(3, 1))
self.check('---\n'
'obj:\n'
' # bad\n'
' a: b\n', conf, problem=(3, 4))
self.check('---\n'
'obj:\n'
' # these\n'
' # are\n'
' # [good]\n'
'# bad\n'
' # comments\n'
' a: b\n', conf,
problem1=(3, 2), problem2=(4, 4),
problem3=(6, 1), problem4=(7, 7))
self.check('---\n'
'obj1:\n'
' a: 1\n'
' # the following line is disabled\n'
' # b: 2\n', conf)
self.check('---\n'
'obj1:\n'
' a: 1\n'
' # b: 2\n'
'\n'
'obj2:\n'
' b: 2\n', conf)
self.check('---\n'
'obj1:\n'
' a: 1\n'
' # b: 2\n'
'# this object is useless\n'
'obj2: "no"\n', conf)
self.check('---\n'
'obj1:\n'
' a: 1\n'
'# this object is useless\n'
' # b: 2\n'
'obj2: "no"\n', conf, problem=(5, 3))
self.check('---\n'
'obj1:\n'
' a: 1\n'
' # comments\n'
' b: 2\n', conf)
self.check('---\n'
'my list for today:\n'
' - todo 1\n'
' - todo 2\n'
' # commented for now\n'
' # - todo 3\n'
'...\n', conf)
def test_first_line(self):
conf = 'comments-indentation: enable'
self.check('# comment\n', conf)
self.check(' # comment\n', conf, problem=(1, 3))
def test_no_newline_at_end(self):
conf = ('comments-indentation: enable\n'
'new-line-at-end-of-file: disable\n')
self.check('# comment', conf)
self.check(' # comment', conf, problem=(1, 3))
def test_empty_comment(self):
conf = 'comments-indentation: enable'
self.check('---\n'
'# hey\n'
'# normal\n'
'#\n', conf)
self.check('---\n'
'# hey\n'
'# normal\n'
' #\n', conf, problem=(4, 2))
def test_inline_comment(self):
conf = 'comments-indentation: enable'
self.check('---\n'
'- a # inline\n'
'# ok\n', conf)
self.check('---\n'
'- a # inline\n'
' # not ok\n', conf, problem=(3, 2))
self.check('---\n'
' # not ok\n'
'- a # inline\n', conf, problem=(2, 2))
yamllint-1.10.0/tests/test_config.py 0000644 0002322 0002322 00000040277 13177553503 020033 0 ustar debalance debalance # -*- coding: utf-8 -*-
# Copyright (C) 2016 Adrien Vergé
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import os
import shutil
import sys
try:
assert sys.version_info >= (2, 7)
import unittest
except AssertionError:
import unittest2 as unittest
from yamllint import cli
from yamllint import config
from tests.common import build_temp_workspace
class SimpleConfigTestCase(unittest.TestCase):
def test_parse_config(self):
new = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n')
self.assertEqual(list(new.rules.keys()), ['colons'])
self.assertEqual(new.rules['colons']['max-spaces-before'], 0)
self.assertEqual(new.rules['colons']['max-spaces-after'], 1)
self.assertEqual(len(new.enabled_rules(None)), 1)
def test_invalid_conf(self):
with self.assertRaises(config.YamlLintConfigError):
config.YamlLintConfig('not: valid: yaml')
def test_unknown_rule(self):
with self.assertRaisesRegexp(
config.YamlLintConfigError,
'invalid config: no such rule: "this-one-does-not-exist"'):
config.YamlLintConfig('rules:\n'
' this-one-does-not-exist: enable\n')
def test_missing_option(self):
with self.assertRaisesRegexp(
config.YamlLintConfigError,
'invalid config: missing option "max-spaces-before" '
'for rule "colons"'):
config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-after: 1\n')
def test_unknown_option(self):
with self.assertRaisesRegexp(
config.YamlLintConfigError,
'invalid config: unknown option "abcdef" for rule "colons"'):
config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n'
' abcdef: yes\n')
def test_yes_no_for_booleans(self):
c = config.YamlLintConfig('rules:\n'
' indentation:\n'
' spaces: 2\n'
' indent-sequences: true\n'
' check-multi-line-strings: false\n')
self.assertEqual(c.rules['indentation']['indent-sequences'], True)
self.assertEqual(c.rules['indentation']['check-multi-line-strings'],
False)
c = config.YamlLintConfig('rules:\n'
' indentation:\n'
' spaces: 2\n'
' indent-sequences: yes\n'
' check-multi-line-strings: false\n')
self.assertEqual(c.rules['indentation']['indent-sequences'], True)
self.assertEqual(c.rules['indentation']['check-multi-line-strings'],
False)
c = config.YamlLintConfig('rules:\n'
' indentation:\n'
' spaces: 2\n'
' indent-sequences: whatever\n'
' check-multi-line-strings: false\n')
self.assertEqual(c.rules['indentation']['indent-sequences'],
'whatever')
self.assertEqual(c.rules['indentation']['check-multi-line-strings'],
False)
with self.assertRaisesRegexp(
config.YamlLintConfigError,
'invalid config: option "indent-sequences" of "indentation" '
'should be in '):
c = config.YamlLintConfig('rules:\n'
' indentation:\n'
' spaces: 2\n'
' indent-sequences: YES!\n'
' check-multi-line-strings: false\n')
def test_validate_rule_conf(self):
class Rule(object):
ID = 'fake'
self.assertEqual(config.validate_rule_conf(Rule, False), False)
self.assertEqual(config.validate_rule_conf(Rule, 'disable'), False)
self.assertEqual(config.validate_rule_conf(Rule, {}),
{'level': 'error'})
self.assertEqual(config.validate_rule_conf(Rule, 'enable'),
{'level': 'error'})
config.validate_rule_conf(Rule, {'level': 'error'})
config.validate_rule_conf(Rule, {'level': 'warning'})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'level': 'warn'})
Rule.CONF = {'length': int}
config.validate_rule_conf(Rule, {'length': 8})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'height': 8})
Rule.CONF = {'a': bool, 'b': int}
config.validate_rule_conf(Rule, {'a': True, 'b': 0})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'a': True})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'b': 0})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'a': 1, 'b': 0})
Rule.CONF = {'choice': (True, 88, 'str')}
config.validate_rule_conf(Rule, {'choice': True})
config.validate_rule_conf(Rule, {'choice': 88})
config.validate_rule_conf(Rule, {'choice': 'str'})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'choice': False})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'choice': 99})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'choice': 'abc'})
Rule.CONF = {'choice': (int, 'hardcoded')}
config.validate_rule_conf(Rule, {'choice': 42})
config.validate_rule_conf(Rule, {'choice': 'hardcoded'})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'choice': False})
self.assertRaises(config.YamlLintConfigError,
config.validate_rule_conf, Rule, {'choice': 'abc'})
class ExtendedConfigTestCase(unittest.TestCase):
def test_extend_add_rule(self):
old = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n')
new = config.YamlLintConfig('rules:\n'
' hyphens:\n'
' max-spaces-after: 2\n')
new.extend(old)
self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens'])
self.assertEqual(new.rules['colons']['max-spaces-before'], 0)
self.assertEqual(new.rules['colons']['max-spaces-after'], 1)
self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2)
self.assertEqual(len(new.enabled_rules(None)), 2)
def test_extend_remove_rule(self):
old = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n'
' hyphens:\n'
' max-spaces-after: 2\n')
new = config.YamlLintConfig('rules:\n'
' colons: disable\n')
new.extend(old)
self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens'])
self.assertEqual(new.rules['colons'], False)
self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2)
self.assertEqual(len(new.enabled_rules(None)), 1)
def test_extend_edit_rule(self):
old = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n'
' hyphens:\n'
' max-spaces-after: 2\n')
new = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 3\n'
' max-spaces-after: 4\n')
new.extend(old)
self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens'])
self.assertEqual(new.rules['colons']['max-spaces-before'], 3)
self.assertEqual(new.rules['colons']['max-spaces-after'], 4)
self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2)
self.assertEqual(len(new.enabled_rules(None)), 2)
def test_extend_reenable_rule(self):
old = config.YamlLintConfig('rules:\n'
' colons:\n'
' max-spaces-before: 0\n'
' max-spaces-after: 1\n'
' hyphens: disable\n')
new = config.YamlLintConfig('rules:\n'
' hyphens:\n'
' max-spaces-after: 2\n')
new.extend(old)
self.assertEqual(sorted(new.rules.keys()), ['colons', 'hyphens'])
self.assertEqual(new.rules['colons']['max-spaces-before'], 0)
self.assertEqual(new.rules['colons']['max-spaces-after'], 1)
self.assertEqual(new.rules['hyphens']['max-spaces-after'], 2)
self.assertEqual(len(new.enabled_rules(None)), 2)
class ExtendedLibraryConfigTestCase(unittest.TestCase):
def test_extend_config_disable_rule(self):
old = config.YamlLintConfig('extends: default')
new = config.YamlLintConfig('extends: default\n'
'rules:\n'
' trailing-spaces: disable\n')
old.rules['trailing-spaces'] = False
self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys()))
for rule in new.rules:
self.assertEqual(new.rules[rule], old.rules[rule])
def test_extend_config_override_whole_rule(self):
old = config.YamlLintConfig('extends: default')
new = config.YamlLintConfig('extends: default\n'
'rules:\n'
' empty-lines:\n'
' max: 42\n'
' max-start: 43\n'
' max-end: 44\n')
old.rules['empty-lines']['max'] = 42
old.rules['empty-lines']['max-start'] = 43
old.rules['empty-lines']['max-end'] = 44
self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys()))
for rule in new.rules:
self.assertEqual(new.rules[rule], old.rules[rule])
def test_extend_config_override_rule_partly(self):
old = config.YamlLintConfig('extends: default')
new = config.YamlLintConfig('extends: default\n'
'rules:\n'
' empty-lines:\n'
' max-start: 42\n')
old.rules['empty-lines']['max-start'] = 42
self.assertEqual(sorted(new.rules.keys()), sorted(old.rules.keys()))
for rule in new.rules:
self.assertEqual(new.rules[rule], old.rules[rule])
class IgnorePathConfigTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(IgnorePathConfigTestCase, cls).setUpClass()
bad_yaml = ('---\n'
'- key: val1\n'
' key: val2\n'
'- trailing space \n'
'- lonely hyphen\n')
cls.wd = build_temp_workspace({
'bin/file.lint-me-anyway.yaml': bad_yaml,
'bin/file.yaml': bad_yaml,
'file-at-root.yaml': bad_yaml,
'file.dont-lint-me.yaml': bad_yaml,
'ign-dup/file.yaml': bad_yaml,
'ign-dup/sub/dir/file.yaml': bad_yaml,
'ign-trail/file.yaml': bad_yaml,
'include/ign-dup/sub/dir/file.yaml': bad_yaml,
's/s/ign-trail/file.yaml': bad_yaml,
's/s/ign-trail/s/s/file.yaml': bad_yaml,
's/s/ign-trail/s/s/file2.lint-me-anyway.yaml': bad_yaml,
'.yamllint': 'ignore: |\n'
' *.dont-lint-me.yaml\n'
' /bin/\n'
' !/bin/*.lint-me-anyway.yaml\n'
'\n'
'extends: default\n'
'\n'
'rules:\n'
' key-duplicates:\n'
' ignore: |\n'
' /ign-dup\n'
' trailing-spaces:\n'
' ignore: |\n'
' ign-trail\n'
' !*.lint-me-anyway.yaml\n',
})
cls.backup_wd = os.getcwd()
os.chdir(cls.wd)
@classmethod
def tearDownClass(cls):
super(IgnorePathConfigTestCase, cls).tearDownClass()
os.chdir(cls.backup_wd)
shutil.rmtree(cls.wd)
@unittest.skipIf(sys.version_info < (2, 7), 'Python 2.6 not supported')
def test_run_with_ignored_path(self):
sys.stdout = StringIO()
with self.assertRaises(SystemExit):
cli.run(('-f', 'parsable', '.'))
out = sys.stdout.getvalue()
out = '\n'.join(sorted(out.splitlines()))
keydup = '[error] duplication of key "key" in mapping (key-duplicates)'
trailing = '[error] trailing spaces (trailing-spaces)'
hyphen = '[error] too many spaces after hyphen (hyphens)'
self.assertEqual(out, '\n'.join((
'./bin/file.lint-me-anyway.yaml:3:3: ' + keydup,
'./bin/file.lint-me-anyway.yaml:4:17: ' + trailing,
'./bin/file.lint-me-anyway.yaml:5:5: ' + hyphen,
'./file-at-root.yaml:3:3: ' + keydup,
'./file-at-root.yaml:4:17: ' + trailing,
'./file-at-root.yaml:5:5: ' + hyphen,
'./ign-dup/file.yaml:4:17: ' + trailing,
'./ign-dup/file.yaml:5:5: ' + hyphen,
'./ign-dup/sub/dir/file.yaml:4:17: ' + trailing,
'./ign-dup/sub/dir/file.yaml:5:5: ' + hyphen,
'./ign-trail/file.yaml:3:3: ' + keydup,
'./ign-trail/file.yaml:5:5: ' + hyphen,
'./include/ign-dup/sub/dir/file.yaml:3:3: ' + keydup,
'./include/ign-dup/sub/dir/file.yaml:4:17: ' + trailing,
'./include/ign-dup/sub/dir/file.yaml:5:5: ' + hyphen,
'./s/s/ign-trail/file.yaml:3:3: ' + keydup,
'./s/s/ign-trail/file.yaml:5:5: ' + hyphen,
'./s/s/ign-trail/s/s/file.yaml:3:3: ' + keydup,
'./s/s/ign-trail/s/s/file.yaml:5:5: ' + hyphen,
'./s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:3:3: ' + keydup,
'./s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:4:17: ' + trailing,
'./s/s/ign-trail/s/s/file2.lint-me-anyway.yaml:5:5: ' + hyphen,
)))
yamllint-1.10.0/docs/ 0000755 0002322 0002322 00000000000 13177553503 014731 5 ustar debalance debalance yamllint-1.10.0/docs/rules.rst 0000644 0002322 0002322 00000003316 13177553503 016620 0 ustar debalance debalance Rules
=====
When linting a document with yamllint, a series of rules (such as
``line-length``, ``trailing-spaces``, etc.) are checked against.
A :doc:`configuration file ` can be used to enable or disable
these rules, to set their level (*error* or *warning*), but also to tweak their
options.
This page describes the rules and their options.
.. contents:: List of rules
:local:
:depth: 1
braces
------
.. automodule:: yamllint.rules.braces
brackets
--------
.. automodule:: yamllint.rules.brackets
colons
------
.. automodule:: yamllint.rules.colons
commas
------
.. automodule:: yamllint.rules.commas
comments
--------
.. automodule:: yamllint.rules.comments
comments-indentation
--------------------
.. automodule:: yamllint.rules.comments_indentation
document-end
------------
.. automodule:: yamllint.rules.document_end
document-start
--------------
.. automodule:: yamllint.rules.document_start
empty-lines
-----------
.. automodule:: yamllint.rules.empty_lines
empty-values
------------
.. automodule:: yamllint.rules.empty_values
hyphens
-------
.. automodule:: yamllint.rules.hyphens
indentation
-----------
.. automodule:: yamllint.rules.indentation
key-duplicates
--------------
.. automodule:: yamllint.rules.key_duplicates
key-ordering
--------------
.. automodule:: yamllint.rules.key_ordering
line-length
-----------
.. automodule:: yamllint.rules.line_length
new-line-at-end-of-file
-----------------------
.. automodule:: yamllint.rules.new_line_at_end_of_file
new-lines
---------
.. automodule:: yamllint.rules.new_lines
trailing-spaces
---------------
.. automodule:: yamllint.rules.trailing_spaces
truthy
---------------
.. automodule:: yamllint.rules.truthy
yamllint-1.10.0/docs/index.rst 0000644 0002322 0002322 00000000712 13177553503 016572 0 ustar debalance debalance yamllint documentation
======================
.. automodule:: yamllint
Screenshot
----------
.. image:: screenshot.png
:alt: yamllint screenshot
.. note::
The default output format is inspired by `eslint `_, a
great linting tool for Javascript.
Table of contents
-----------------
.. toctree::
:maxdepth: 2
quickstart
configuration
rules
disable_with_comments
development
text_editors
integration
yamllint-1.10.0/docs/text_editors.rst 0000644 0002322 0002322 00000002306 13177553503 020201 0 ustar debalance debalance Integration with text editors
=============================
Most text editors support syntax checking and highlighting, to visually report
syntax errors and warnings to the user. yamllint can be used to syntax-check
YAML source, but a bit of configuration is required depending on your favorite
text editor.
Vim
---
Assuming that the `ALE `_ plugin is
installed, yamllint is supported by default. It is automatically enabled when
editing YAML files.
If you instead use the `syntastic `_
plugin, add this to your ``.vimrc``:
::
let g:syntastic_yaml_checkers = ['yamllint']
Neovim
------
Assuming that the `neomake `_ plugin is
installed, yamllint is supported by default. It is automatically enabled when
editing YAML files.
Emacs
-----
If you are `flycheck `_ user, you can use
`flycheck-yamllint `_ integration.
Other text editors
------------------
.. rubric:: Help wanted!
Your favorite text editor is not listed here? Help us improve by adding a
section (by opening a pull-request or issue on GitHub).
yamllint-1.10.0/docs/screenshot.png 0000644 0002322 0002322 00000121401 13177553503 017613 0 ustar debalance debalance PNG
IHDR uh tIME&4k- IDATx{XW8 \7DQ"uFh(M,*DM&J;A֘YDc$Hh." DPX⊀Bff{yz`NWשStwun# aaaڥaaa8qfaaNaagaaęaaa8qfnCDUG:= vOçʽ46zaac~FFF֑6pYYFKKNӟԧ'^=m00]8!sK=Ow&=}Mt
'}3qW'0}~w@u-ؼHwdOAAfϞ-(ӧeAAA8vQ]]
J/++555شi<vفikP]],ڪcO?2V|[[-444]g}hjjByy9y(lmmZTWWu/O`a!'&FFbAݒ:ijї?V} ʔJ%mܸQPva9s&ѠA(!!Z/9sFN+bt#"*(( oooR(4dJKKL?Rt[GLF~w'K."$BA'Oz'$%ߥĐhxb!{{{JNNFwXXXXXzǙ'wdݓXLО-C׃@f @WJsXXXXPMM