From 8dccc75f35b03249ed8398b00b260b07d4e794eb Mon Sep 17 00:00:00 2001 From: Thilo Uttendorfer Date: Wed, 12 May 2021 18:34:51 +0200 Subject: [PATCH] Fix get_yaml_files to return all configured files The issue was introduced with #1473 and only affects setups without a git repo and when custom kinds are used. --- src/ansiblelint/file_utils.py | 1 - test/TestUtils.py | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/ansiblelint/file_utils.py b/src/ansiblelint/file_utils.py index b192eb173a..178423d8d0 100644 --- a/src/ansiblelint/file_utils.py +++ b/src/ansiblelint/file_utils.py @@ -227,7 +227,6 @@ def get_yaml_files(options: Namespace) -> Dict[str, Any]: os.path.join(root, name) for root, dirs, files in os.walk('.') for name in files - if name.endswith('.yaml') or name.endswith('.yml') ] return OrderedDict.fromkeys(sorted(out)) diff --git a/test/TestUtils.py b/test/TestUtils.py index 252bc37a43..ed29603aba 100644 --- a/test/TestUtils.py +++ b/test/TestUtils.py @@ -234,12 +234,17 @@ def test_get_yaml_files_git_verbose(reset_env_var, message_prefix, monkeypatch, assert any(m.startswith(message_prefix) for m in caplog.messages) +@pytest.mark.parametrize( + 'with_custom_kinds', + (True, False), + ids=('with custom kinds', 'without custom kinds'), +) @pytest.mark.parametrize( 'is_in_git', (True, False), ids=('in Git', 'outside Git'), ) -def test_get_yaml_files_silent(is_in_git, monkeypatch, capsys): +def test_get_yaml_files_silent(with_custom_kinds, is_in_git, monkeypatch, capsys): """Verify that no stderr output is displayed while discovering yaml files. (when the verbosity is off, regardless of the Git or Git-repo presence) @@ -248,13 +253,18 @@ def test_get_yaml_files_silent(is_in_git, monkeypatch, capsys): """ options = cli.get_config([]) test_dir = Path(__file__).resolve().parent - lint_path = test_dir / '..' / 'examples' / 'roles' / 'test-role' + if with_custom_kinds: + lint_path = test_dir / '..' / 'examples' / 'other' + else: + lint_path = test_dir / '..' / 'examples' / 'roles' / 'test-role' if not is_in_git: monkeypatch.setenv('GIT_DIR', '') - yaml_count = len(list(lint_path.glob('**/*.yml'))) + len( - list(lint_path.glob('**/*.yaml')) - ) + # **/*.yaml-too is configured in .ansible-lint + yaml_count = \ + len(list(lint_path.glob('**/*.yml'))) + \ + len(list(lint_path.glob('**/*.yaml'))) + \ + len(list(lint_path.glob('**/*.yaml-too'))) monkeypatch.chdir(str(lint_path)) files = file_utils.get_yaml_files(options)