summaryrefslogtreecommitdiffstats
path: root/tests/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_config.py')
-rw-r--r--tests/test_config.py73
1 files changed, 66 insertions, 7 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index 8e90246..fb570c6 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -13,18 +13,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from io import StringIO
import os
import shutil
import sys
import tempfile
import unittest
+from io import StringIO
-from tests.common import build_temp_workspace
+from tests.common import build_temp_workspace, RunContext
+from yamllint import cli, config
from yamllint.config import YamlLintConfigError
-from yamllint import cli
-from yamllint import config
class SimpleConfigTestCase(unittest.TestCase):
@@ -212,6 +211,14 @@ class SimpleConfigTestCase(unittest.TestCase):
' colons:\n'
' ignore: yes\n')
+ def test_invalid_rule_ignore_from_file(self):
+ self.assertRaises(
+ config.YamlLintConfigError,
+ config.YamlLintConfig,
+ 'rules:\n'
+ ' colons:\n'
+ ' ignore-from-file: 1337\n')
+
def test_invalid_locale(self):
with self.assertRaisesRegex(
config.YamlLintConfigError,
@@ -660,12 +667,19 @@ class IgnoreConfigTestCase(unittest.TestCase):
def test_run_with_ignore_from_file(self):
with open(os.path.join(self.wd, '.yamllint'), 'w') as f:
f.write('extends: default\n'
- 'ignore-from-file: .gitignore\n')
+ 'ignore-from-file: .gitignore\n'
+ 'rules:\n'
+ ' key-duplicates:\n'
+ ' ignore-from-file: .ignore-key-duplicates\n')
+
with open(os.path.join(self.wd, '.gitignore'), 'w') as f:
f.write('*.dont-lint-me.yaml\n'
'/bin/\n'
'!/bin/*.lint-me-anyway.yaml\n')
+ with open(os.path.join(self.wd, '.ignore-key-duplicates'), 'w') as f:
+ f.write('/ign-dup\n')
+
sys.stdout = StringIO()
with self.assertRaises(SystemExit):
cli.run(('-f', 'parsable', '.'))
@@ -686,10 +700,8 @@ class IgnoreConfigTestCase(unittest.TestCase):
'./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:3:3: ' + keydup,
'./ign-dup/file.yaml:4:17: ' + trailing,
'./ign-dup/file.yaml:5:5: ' + hyphen,
- './ign-dup/sub/dir/file.yaml:3:3: ' + keydup,
'./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,
@@ -761,3 +773,50 @@ class IgnoreConfigTestCase(unittest.TestCase):
'./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,
)))
+
+ def test_run_with_ignore_with_broken_symlink(self):
+ wd = build_temp_workspace({
+ 'file-without-yaml-extension': '42\n',
+ 'link.yaml': 'symlink://file-without-yaml-extension',
+ 'link-404.yaml': 'symlink://file-that-does-not-exist',
+ })
+ backup_wd = os.getcwd()
+ os.chdir(wd)
+
+ with RunContext(self) as ctx:
+ cli.run(('-f', 'parsable', '.'))
+ self.assertNotEqual(ctx.returncode, 0)
+
+ with open(os.path.join(wd, '.yamllint'), 'w') as f:
+ f.write('extends: default\n'
+ 'ignore: |\n'
+ ' *404.yaml\n')
+ with RunContext(self) as ctx:
+ cli.run(('-f', 'parsable', '.'))
+ self.assertEqual(ctx.returncode, 0)
+ docstart = '[warning] missing document start "---" (document-start)'
+ out = '\n'.join(sorted(ctx.stdout.splitlines()))
+ self.assertEqual(out, '\n'.join((
+ './.yamllint:1:1: ' + docstart,
+ './link.yaml:1:1: ' + docstart,
+ )))
+
+ os.chdir(backup_wd)
+ shutil.rmtree(wd)
+
+ def test_run_with_ignore_on_ignored_file(self):
+ with open(os.path.join(self.wd, '.yamllint'), 'w') as f:
+ f.write('ignore: file.dont-lint-me.yaml\n'
+ 'rules:\n'
+ ' trailing-spaces: enable\n'
+ ' key-duplicates:\n'
+ ' ignore: file-at-root.yaml\n')
+
+ sys.stdout = StringIO()
+ with self.assertRaises(SystemExit):
+ cli.run(('-f', 'parsable', 'file.dont-lint-me.yaml',
+ 'file-at-root.yaml'))
+ self.assertEqual(
+ sys.stdout.getvalue().strip(),
+ 'file-at-root.yaml:4:17: [error] trailing spaces (trailing-spaces)'
+ )