diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d289084..450507b0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -73,6 +73,9 @@ def setUpClass(cls): # file in dir 'sub/ok.yaml': '---\n' 'key: value\n', + # directory that looks like a yaml file + 'sub/directory.yaml/not-yaml.txt': '', + 'sub/directory.yaml/empty.yml': '', # file in very nested dir 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml': '---\n' 'key: value\n' @@ -108,6 +111,7 @@ def test_find_files_recursively(self): os.path.join(self.wd, 'dos.yml'), os.path.join(self.wd, 'empty.yml'), os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), + os.path.join(self.wd, 'sub/directory.yaml/empty.yml'), os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.yaml')], ) @@ -132,6 +136,7 @@ def test_find_files_recursively(self): self.assertEqual( sorted(cli.find_files_recursively(items, conf)), [os.path.join(self.wd, '/etc/another/file'), + os.path.join(self.wd, 'sub/directory.yaml/empty.yml'), os.path.join(self.wd, 'sub/ok.yaml')], ) @@ -152,7 +157,8 @@ def test_find_files_recursively(self): self.assertEqual( sorted(cli.find_files_recursively([self.wd], conf)), [os.path.join(self.wd, 'dos.yml'), - os.path.join(self.wd, 'empty.yml')] + os.path.join(self.wd, 'empty.yml'), + os.path.join(self.wd, 'sub/directory.yaml/empty.yml')] ) conf = config.YamlLintConfig('extends: default\n' @@ -174,6 +180,8 @@ def test_find_files_recursively(self): os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'), os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), + os.path.join(self.wd, 'sub/directory.yaml/empty.yml'), + os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'), os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.yaml')] ) @@ -191,6 +199,8 @@ def test_find_files_recursively(self): os.path.join(self.wd, 'no-yaml.json'), os.path.join(self.wd, 'non-ascii/éçäγλνπ¥/utf-8'), os.path.join(self.wd, 's/s/s/s/s/s/s/s/s/s/s/s/s/s/s/file.yaml'), + os.path.join(self.wd, 'sub/directory.yaml/empty.yml'), + os.path.join(self.wd, 'sub/directory.yaml/not-yaml.txt'), os.path.join(self.wd, 'sub/ok.yaml'), os.path.join(self.wd, 'warn.yaml')] ) diff --git a/yamllint/config.py b/yamllint/config.py index a955d8e6..0abb242d 100644 --- a/yamllint/config.py +++ b/yamllint/config.py @@ -46,7 +46,7 @@ def is_file_ignored(self, filepath): return self.ignore and self.ignore.match_file(filepath) def is_yaml_file(self, filepath): - return self.yaml_files.match_file(filepath) + return self.yaml_files.match_file(os.path.basename(filepath)) def enabled_rules(self, filepath): return [yamllint.rules.get(id) for id, val in self.rules.items()