summaryrefslogtreecommitdiffstats
path: root/test/test_runner.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/test_runner.py72
1 files changed, 67 insertions, 5 deletions
diff --git a/test/test_runner.py b/test/test_runner.py
index e89cee1..aa76b65 100644
--- a/test/test_runner.py
+++ b/test/test_runner.py
@@ -1,4 +1,5 @@
"""Tests for runner submodule."""
+
# Copyright (c) 2013-2014 Will Thames <will@thames.id.au>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -48,7 +49,7 @@ LOTS_OF_WARNINGS_PLAYBOOK = Path("examples/playbooks/lots_of_warnings.yml").reso
pytest.param(
LOTS_OF_WARNINGS_PLAYBOOK,
[LOTS_OF_WARNINGS_PLAYBOOK],
- 992,
+ 993,
id="lots_of_warnings",
),
pytest.param(Path("examples/playbooks/become.yml"), [], 0, id="become"),
@@ -86,21 +87,23 @@ def test_runner_exclude_paths(default_rules_collection: RulesCollection) -> None
assert len(matches) == 0
-@pytest.mark.parametrize(("exclude_path"), ("**/playbooks/*.yml",))
+@pytest.mark.parametrize(
+ ("exclude_path"),
+ (pytest.param("**/playbooks_globs/*b.yml", id="1"),),
+)
def test_runner_exclude_globs(
default_rules_collection: RulesCollection,
exclude_path: str,
) -> None:
"""Test that globs work."""
runner = Runner(
- "examples/playbooks",
+ "examples/playbooks_globs",
rules=default_rules_collection,
exclude_paths=[exclude_path],
)
matches = runner.run()
- # we expect to find one match from the very few .yaml file we have there (most of them have .yml extension)
- assert len(matches) == 1
+ assert len(matches) == 0
@pytest.mark.parametrize(
@@ -175,6 +178,52 @@ def test_files_not_scanned_twice(default_rules_collection: RulesCollection) -> N
assert len(run2) == 0
+@pytest.mark.parametrize(
+ ("filename", "failures", "checked_files_no"),
+ (
+ pytest.param(
+ "examples/playbooks/common-include-wrong-syntax.yml",
+ 1,
+ 1,
+ id="1",
+ ),
+ pytest.param(
+ "examples/playbooks/common-include-wrong-syntax2.yml",
+ 1,
+ 1,
+ id="2",
+ ),
+ pytest.param(
+ "examples/playbooks/common-include-wrong-syntax3.yml",
+ 0,
+ 2,
+ id="3",
+ ),
+ ),
+)
+def test_include_wrong_syntax(
+ filename: str,
+ failures: int,
+ checked_files_no: int,
+ default_rules_collection: RulesCollection,
+) -> None:
+ """Ensure that lintables aren't double-checked."""
+ checked_files: set[Lintable] = set()
+
+ path = Path(filename).resolve()
+ runner = Runner(
+ path,
+ rules=default_rules_collection,
+ verbosity=0,
+ checked_files=checked_files,
+ )
+ result = runner.run()
+ assert len(runner.checked_files) == checked_files_no
+ assert len(result) == failures, result
+ for item in result:
+ assert item.tag == "syntax-check[no-file]"
+
+
def test_runner_not_found(default_rules_collection: RulesCollection) -> None:
"""Ensure that lintables aren't double-checked."""
checked_files: set[Lintable] = set()
@@ -208,3 +257,16 @@ def test_runner_tmp_file(
result = runner.run()
assert len(result) == 1
assert result[0].tag == "syntax-check[empty-playbook]"
+
+
+def test_with_full_path(default_rules_collection: RulesCollection) -> None:
+ """Ensure that lintables include file path starting from home directory."""
+ filename = Path("examples/playbooks/deep").absolute()
+ runner = Runner(
+ filename,
+ rules=default_rules_collection,
+ verbosity=0,
+ )
+ result = runner.run()
+ assert len(result) == 1
+ assert result[0].tag == "name[casing]"