|
| 1 | +"""Tests related to our logging/verbosity setup.""" |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from ansiblelint.testing import run_ansible_lint |
| 8 | + |
| 9 | + |
| 10 | +def test_list_rules_includes_opt_in_rules() -> None: |
| 11 | + """Checks that listing rules also includes the opt-in rules.""" |
| 12 | + # Piggyback off the .yamllint in the root of the repo, just for testing. |
| 13 | + # We'll "override" it with the one in the fixture. |
| 14 | + cwd = os.path.realpath( |
| 15 | + os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") |
| 16 | + ) |
| 17 | + fakerole = os.path.join("test", "fixtures", "list-rules-tests") |
| 18 | + |
| 19 | + result_list_rules = run_ansible_lint("-L", fakerole, cwd=cwd) |
| 20 | + |
| 21 | + assert ("opt-in" in result_list_rules.stdout) is True |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + ("result", "returncode", "format_string"), |
| 26 | + ( |
| 27 | + (False, 0, "plain"), |
| 28 | + (False, 0, "rich"), |
| 29 | + (False, 0, "rst"), |
| 30 | + (True, 2, "json"), |
| 31 | + (True, 2, "codeclimate"), |
| 32 | + (True, 2, "quiet"), |
| 33 | + (True, 2, "pep8"), |
| 34 | + (True, 2, "foo"), |
| 35 | + ), |
| 36 | + ids=( |
| 37 | + "plain", |
| 38 | + "rich", |
| 39 | + "rst", |
| 40 | + "json", |
| 41 | + "codeclimate", |
| 42 | + "quiet", |
| 43 | + "pep8", |
| 44 | + "foo", |
| 45 | + ), |
| 46 | +) |
| 47 | +def test_list_rules_with_format_option( |
| 48 | + result: bool, returncode: int, format_string: str |
| 49 | +) -> None: |
| 50 | + """Checks that listing rules with format options works.""" |
| 51 | + # Piggyback off the .yamllint in the root of the repo, just for testing. |
| 52 | + # We'll "override" it with the one in the fixture. |
| 53 | + cwd = os.path.realpath( |
| 54 | + os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") |
| 55 | + ) |
| 56 | + fakerole = os.path.join("test", "fixtures", "list-rules-tests") |
| 57 | + |
| 58 | + result_list_rules = run_ansible_lint("-f", format_string, "-L", fakerole, cwd=cwd) |
| 59 | + print(result_list_rules.stdout) |
| 60 | + |
| 61 | + assert (f"invalid choice: '{format_string}'" in result_list_rules.stderr) is result |
| 62 | + assert ("syntax-check" in result_list_rules.stdout) is not result |
| 63 | + assert result_list_rules.returncode is returncode |
| 64 | + |
| 65 | + |
| 66 | +def test_list_tags_includes_opt_in_rules() -> None: |
| 67 | + """Checks that listing tags also includes the opt-in rules.""" |
| 68 | + # Piggyback off the .yamllint in the root of the repo, just for testing. |
| 69 | + # We'll "override" it with the one in the fixture. |
| 70 | + cwd = os.path.realpath( |
| 71 | + os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") |
| 72 | + ) |
| 73 | + fakerole = os.path.join("test", "fixtures", "list-rules-tests") |
| 74 | + |
| 75 | + result_list_tags = run_ansible_lint("-L", fakerole, cwd=cwd) |
| 76 | + |
| 77 | + assert ("opt-in" in result_list_tags.stdout) is True |
0 commit comments