Skip to content

Commit

Permalink
Fix get_yaml_files to return all configured files
Browse files Browse the repository at this point in the history
The issue was introduced with ansible#1473 and only affects setups without a
git repo and when custom kinds are used.
  • Loading branch information
sengaya committed May 12, 2021
1 parent 58f57e3 commit 8dccc75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/ansiblelint/file_utils.py
Expand Up @@ -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))
Expand Down
20 changes: 15 additions & 5 deletions test/TestUtils.py
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8dccc75

Please sign in to comment.