summaryrefslogtreecommitdiffstats
path: root/test/test_main.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_main.py')
-rw-r--r--test/test_main.py53
1 files changed, 50 insertions, 3 deletions
diff --git a/test/test_main.py b/test/test_main.py
index 870926f..e7258ee 100644
--- a/test/test_main.py
+++ b/test/test_main.py
@@ -1,4 +1,5 @@
"""Tests related to ansiblelint.__main__ module."""
+
import os
import shutil
import subprocess
@@ -10,6 +11,7 @@ import pytest
from pytest_mock import MockerFixture
from ansiblelint.config import get_version_warning
+from ansiblelint.constants import RC
@pytest.mark.parametrize(
@@ -52,9 +54,9 @@ def test_call_from_outside_venv(expected_warning: bool) -> None:
@pytest.mark.parametrize(
("ver_diff", "found", "check", "outlen"),
(
- ("v1.2.2", True, "pre-release", 1),
- ("v1.2.3", False, "", 1),
- ("v1.2.4", True, "new release", 2),
+ pytest.param("v1.2.2", True, "pre-release", 1, id="0"),
+ pytest.param("v1.2.3", False, "", 1, id="1"),
+ pytest.param("v1.2.4", True, "new release", 2, id="2"),
),
)
def test_get_version_warning(
@@ -82,3 +84,48 @@ def test_get_version_warning(
else:
assert check in msg
assert len(msg.split("\n")) == outlen
+
+
+def test_get_version_warning_no_pip(mocker: MockerFixture) -> None:
+ """Test that we do not display any message if install method is not pip."""
+ mocker.patch("ansiblelint.config.guess_install_method", return_value="")
+ assert get_version_warning() == ""
+
+
+@pytest.mark.parametrize(
+ ("lintable"),
+ (
+ pytest.param("examples/playbooks/nodeps.yml", id="1"),
+ pytest.param("examples/playbooks/nodeps2.yml", id="2"),
+ ),
+)
+def test_nodeps(lintable: str) -> None:
+ """Asserts ability to be called w/ or w/o venv activation."""
+ env = os.environ.copy()
+ env["ANSIBLE_LINT_NODEPS"] = "1"
+ py_path = Path(sys.executable).parent
+ proc = subprocess.run(
+ [str(py_path / "ansible-lint"), lintable],
+ check=False,
+ capture_output=True,
+ text=True,
+ env=env,
+ )
+ assert proc.returncode == 0, proc
+
+
+def test_broken_ansible_cfg() -> None:
+ """Asserts behavior when encountering broken ansible.cfg files."""
+ py_path = Path(sys.executable).parent
+ proc = subprocess.run(
+ [str(py_path / "ansible-lint"), "--version"],
+ check=False,
+ capture_output=True,
+ text=True,
+ cwd="test/fixtures/broken-ansible.cfg",
+ )
+ assert proc.returncode == RC.INVALID_CONFIG, proc
+ assert (
+ "Invalid type for configuration option setting: CACHE_PLUGIN_TIMEOUT"
+ in proc.stderr
+ )