diff --git a/flake8/options/config.py b/flake8/options/config.py index 666f9d9..e82cb62 100644 --- a/flake8/options/config.py +++ b/flake8/options/config.py @@ -43,7 +43,7 @@ class ConfigFileFinder(object): # List of filenames to find in the local/project directory self.project_filenames = ('setup.cfg', 'tox.ini', self.program_config) - self.local_directory = os.curdir + self.local_directory = os.path.abspath(os.curdir) if not args: args = ['.'] @@ -66,11 +66,14 @@ class ConfigFileFinder(object): """Find and generate all local config files.""" tail = self.tail parent = self.parent + local_dir = self.local_directory while tail: for project_filename in self.project_filenames: filename = os.path.abspath(os.path.join(parent, project_filename)) yield filename + if parent == local_dir: + break (parent, tail) = os.path.split(parent) def local_config_files(self): diff --git a/tests/unit/test_config_file_finder.py b/tests/unit/test_config_file_finder.py index 8ed940d..8904316 100644 --- a/tests/unit/test_config_file_finder.py +++ b/tests/unit/test_config_file_finder.py @@ -3,6 +3,7 @@ import os import sys import mock +import pytest from flake8.options import config @@ -21,8 +22,30 @@ def test_windows_detection(): def test_cli_config(): + """Verify opening and reading the file specified via the cli.""" cli_filepath = 'tests/fixtures/config_files/cli-specified.ini' finder = config.ConfigFileFinder('flake8', None, []) parsed_config = finder.cli_config(cli_filepath) assert parsed_config.has_section('flake8') + + +@pytest.mark.parametrize('args,expected', [ + ([], # No arguments + [os.path.abspath('setup.cfg'), + os.path.abspath('tox.ini'), + os.path.abspath('.flake8')]), + (['flake8/options', 'flake8/'], # Common prefix of "flake8/" + [os.path.abspath('flake8/setup.cfg'), + os.path.abspath('flake8/tox.ini'), + os.path.abspath('flake8/.flake8'), + os.path.abspath('setup.cfg'), + os.path.abspath('tox.ini'), + os.path.abspath('.flake8')]), +]) +def test_generate_possible_local_config_files(args, expected): + """Verify generation of all possible config paths.""" + finder = config.ConfigFileFinder('flake8', args, []) + + assert (list(finder.generate_possible_local_config_files()) == + expected)