|
| 1 | +"""Tests related to our logging/verbosity setup.""" |
| 2 | + |
| 3 | +import os |
| 4 | +from typing import List, Tuple |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +from ansiblelint.testing import run_ansible_lint |
| 9 | + |
| 10 | + |
| 11 | +# substrs is a list of tuples, where: |
| 12 | +# component 1 is the substring in question |
| 13 | +# component 2 is whether or not to invert ("NOT") the match |
| 14 | +@pytest.mark.parametrize( |
| 15 | + ('verbosity', 'substrs'), |
| 16 | + ( |
| 17 | + ( |
| 18 | + '', |
| 19 | + [ |
| 20 | + ('WARNING Loading custom .yamllint config file,', False), |
| 21 | + ('WARNING Listing 1 violation(s) that are fatal', False), |
| 22 | + ('DEBUG ', True), |
| 23 | + ('INFO ', True), |
| 24 | + ], |
| 25 | + ), |
| 26 | + ( |
| 27 | + '-q', |
| 28 | + [ |
| 29 | + ('WARNING ', True), |
| 30 | + ('DEBUG ', True), |
| 31 | + ('INFO ', True), |
| 32 | + ], |
| 33 | + ), |
| 34 | + ( |
| 35 | + '-qq', |
| 36 | + [ |
| 37 | + ('WARNING ', True), |
| 38 | + ('DEBUG ', True), |
| 39 | + ('INFO ', True), |
| 40 | + ], |
| 41 | + ), |
| 42 | + ( |
| 43 | + '-v', |
| 44 | + [ |
| 45 | + ('WARNING Loading custom .yamllint config file,', False), |
| 46 | + ('WARNING Listing 1 violation(s) that are fatal', False), |
| 47 | + ('INFO Added ANSIBLE_LIBRARY=', False), |
| 48 | + ('DEBUG ', True), |
| 49 | + ], |
| 50 | + ), |
| 51 | + ( |
| 52 | + '-vv', |
| 53 | + [ |
| 54 | + ('WARNING Loading custom .yamllint config file,', False), |
| 55 | + ('WARNING Listing 1 violation(s) that are fatal', False), |
| 56 | + ('INFO Added ANSIBLE_LIBRARY=', False), |
| 57 | + ('DEBUG Effective yamllint rules used', False), |
| 58 | + ], |
| 59 | + ), |
| 60 | + ( |
| 61 | + '-vvvvvvvvvvvvvvvvvvvvvvvvv', |
| 62 | + [ |
| 63 | + ('WARNING Loading custom .yamllint config file,', False), |
| 64 | + ('WARNING Listing 1 violation(s) that are fatal', False), |
| 65 | + ('INFO Added ANSIBLE_LIBRARY=', False), |
| 66 | + ('DEBUG Effective yamllint rules used', False), |
| 67 | + ], |
| 68 | + ), |
| 69 | + ), |
| 70 | + ids=( |
| 71 | + 'default verbosity', |
| 72 | + 'quiet', |
| 73 | + 'really quiet', |
| 74 | + 'loquacious', |
| 75 | + 'really loquacious', |
| 76 | + 'really loquacious but with more "v"s -- same as -vv', |
| 77 | + ), |
| 78 | +) |
| 79 | +def test_default_verbosity(verbosity: str, substrs: List[Tuple[str, bool]]) -> None: |
| 80 | + """Checks that our default verbosity displays (only) warnings.""" |
| 81 | + # Piggyback off the .yamllint in the root of the repo, just for testing. |
| 82 | + # We'll "override" it with the one in the fixture, to produce a warning. |
| 83 | + cwd = os.path.realpath( |
| 84 | + os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") |
| 85 | + ) |
| 86 | + |
| 87 | + fakerole = os.path.join('test', 'fixtures', 'verbosity-tests') |
| 88 | + |
| 89 | + if verbosity: |
| 90 | + result = run_ansible_lint(verbosity, fakerole, cwd=cwd) |
| 91 | + else: |
| 92 | + result = run_ansible_lint(fakerole, cwd=cwd) |
| 93 | + |
| 94 | + for (substr, invert) in substrs: |
| 95 | + if invert: |
| 96 | + assert substr not in result.stderr, result.stderr |
| 97 | + else: |
| 98 | + assert substr in result.stderr, result.stderr |
0 commit comments