-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure root logger instead of package logger (#1773)
* Configure root logger instead of package logger Change: - This was discussed internally; the goal is to make it so that rules which set up their own logger are still subject to the global rules of ansible-lint particularly with regard to our verbosity/quietness flags. - To accomodate for using the root logger, the logging levels of -q and -qq had to change slightly. This is because the default log level of the root logger is WARNING, and we want to avoid setting it to NOTSET which would allow everything by default. To work around this, we now make our default be WARNING as well. -q becomes ERROR, and -qq becomes CRITICAL which we previously didn't have. Test Plan: - New integration tests with various levels of -v and -q. Signed-off-by: Rick Elrod <rick@elrod.me> * lint Signed-off-by: Rick Elrod <rick@elrod.me> * Eliminate some false matches (deprecation warnings) Signed-off-by: Rick Elrod <rick@elrod.me>
- Loading branch information
Showing
3 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"""Tests related to our logging/verbosity setup.""" | ||
|
||
import os | ||
from typing import List, Tuple | ||
|
||
import pytest | ||
|
||
from ansiblelint.testing import run_ansible_lint | ||
|
||
|
||
# substrs is a list of tuples, where: | ||
# component 1 is the substring in question | ||
# component 2 is whether or not to invert ("NOT") the match | ||
@pytest.mark.parametrize( | ||
('verbosity', 'substrs'), | ||
( | ||
( | ||
'', | ||
[ | ||
('WARNING Loading custom .yamllint config file,', False), | ||
('WARNING Listing 1 violation(s) that are fatal', False), | ||
('DEBUG ', True), | ||
('INFO ', True), | ||
], | ||
), | ||
( | ||
'-q', | ||
[ | ||
('WARNING ', True), | ||
('DEBUG ', True), | ||
('INFO ', True), | ||
], | ||
), | ||
( | ||
'-qq', | ||
[ | ||
('WARNING ', True), | ||
('DEBUG ', True), | ||
('INFO ', True), | ||
], | ||
), | ||
( | ||
'-v', | ||
[ | ||
('WARNING Loading custom .yamllint config file,', False), | ||
('WARNING Listing 1 violation(s) that are fatal', False), | ||
('INFO Added ANSIBLE_LIBRARY=', False), | ||
('DEBUG ', True), | ||
], | ||
), | ||
( | ||
'-vv', | ||
[ | ||
('WARNING Loading custom .yamllint config file,', False), | ||
('WARNING Listing 1 violation(s) that are fatal', False), | ||
('INFO Added ANSIBLE_LIBRARY=', False), | ||
('DEBUG Effective yamllint rules used', False), | ||
], | ||
), | ||
( | ||
'-vvvvvvvvvvvvvvvvvvvvvvvvv', | ||
[ | ||
('WARNING Loading custom .yamllint config file,', False), | ||
('WARNING Listing 1 violation(s) that are fatal', False), | ||
('INFO Added ANSIBLE_LIBRARY=', False), | ||
('DEBUG Effective yamllint rules used', False), | ||
], | ||
), | ||
), | ||
ids=( | ||
'default verbosity', | ||
'quiet', | ||
'really quiet', | ||
'loquacious', | ||
'really loquacious', | ||
'really loquacious but with more "v"s -- same as -vv', | ||
), | ||
) | ||
def test_default_verbosity(verbosity: str, substrs: List[Tuple[str, bool]]) -> None: | ||
"""Checks that our default verbosity displays (only) warnings.""" | ||
# Piggyback off the .yamllint in the root of the repo, just for testing. | ||
# We'll "override" it with the one in the fixture, to produce a warning. | ||
cwd = os.path.realpath( | ||
os.path.join(os.path.dirname(os.path.realpath(__file__)), "..") | ||
) | ||
|
||
fakerole = os.path.join('test', 'fixtures', 'verbosity-tests') | ||
|
||
if verbosity: | ||
result = run_ansible_lint(verbosity, fakerole, cwd=cwd) | ||
else: | ||
result = run_ansible_lint(fakerole, cwd=cwd) | ||
|
||
for (substr, invert) in substrs: | ||
if invert: | ||
assert substr not in result.stderr, result.stderr | ||
else: | ||
assert substr in result.stderr, result.stderr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |