mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
Merge branch 'config-finder-extra-files-optional' into 'master'
config: Make ConfigFileFinder 'extra_config_files' parameter optional See merge request pycqa/flake8!402
This commit is contained in:
commit
b56c88fe65
6 changed files with 17 additions and 22 deletions
|
|
@ -19,11 +19,11 @@ class ConfigFileFinder(object):
|
|||
def __init__(
|
||||
self,
|
||||
program_name,
|
||||
extra_config_files,
|
||||
extra_config_files=None,
|
||||
config_file=None,
|
||||
ignore_config_files=False,
|
||||
):
|
||||
# type: (str, List[str], Optional[str], bool) -> None
|
||||
# type: (str, Optional[List[str]], Optional[str], bool) -> None
|
||||
"""Initialize object to find config files.
|
||||
|
||||
:param str program_name:
|
||||
|
|
@ -36,7 +36,8 @@ class ConfigFileFinder(object):
|
|||
Determine whether to ignore configuration files or not.
|
||||
"""
|
||||
# The values of --append-config from the CLI
|
||||
extra_config_files = extra_config_files or []
|
||||
if extra_config_files is None:
|
||||
extra_config_files = []
|
||||
self.extra_config_files = utils.normalize_paths(extra_config_files)
|
||||
|
||||
# The value of --config from the CLI.
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ def test_aggregate_options_with_config(optmanager):
|
|||
'E11,E34,E402,W,F', '--exclude', 'tests/*']
|
||||
config_finder = config.ConfigFileFinder(
|
||||
'flake8',
|
||||
[],
|
||||
config_file=CLI_SPECIFIED_CONFIG)
|
||||
options, args = aggregator.aggregate_options(
|
||||
optmanager, config_finder, arguments)
|
||||
|
|
@ -47,7 +46,7 @@ def test_aggregate_options_when_isolated(optmanager):
|
|||
arguments = ['flake8', '--select', 'E11,E34,E402,W,F',
|
||||
'--exclude', 'tests/*']
|
||||
config_finder = config.ConfigFileFinder(
|
||||
'flake8', [], ignore_config_files=True)
|
||||
'flake8', ignore_config_files=True)
|
||||
optmanager.extend_default_ignore(['E8'])
|
||||
options, args = aggregator.aggregate_options(
|
||||
optmanager, config_finder, arguments)
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ BROKEN_CONFIG_PATH = 'tests/fixtures/config_files/broken.ini'
|
|||
def test_windows_detection(platform, is_windows):
|
||||
"""Verify we detect Windows to the best of our knowledge."""
|
||||
with mock.patch.object(sys, 'platform', platform):
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
assert finder.is_windows is is_windows
|
||||
|
||||
|
||||
def test_cli_config():
|
||||
"""Verify opening and reading the file specified via the cli."""
|
||||
cli_filepath = CLI_SPECIFIED_FILEPATH
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
parsed_config = finder.cli_config(cli_filepath)
|
||||
assert parsed_config.has_section('flake8')
|
||||
|
|
@ -36,7 +36,7 @@ def test_cli_config():
|
|||
|
||||
def test_cli_config_double_read():
|
||||
"""Second request for CLI config is cached."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
parsed_config = finder.cli_config(CLI_SPECIFIED_FILEPATH)
|
||||
boom = Exception("second request for CLI config not cached")
|
||||
|
|
@ -61,7 +61,7 @@ def test_cli_config_double_read():
|
|||
])
|
||||
def test_generate_possible_local_files(cwd, expected):
|
||||
"""Verify generation of all possible config paths."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
with mock.patch.object(os, 'getcwd', return_value=cwd):
|
||||
config_files = list(finder.generate_possible_local_files())
|
||||
|
|
@ -91,14 +91,14 @@ def test_local_config_files(extra_config_files, expected):
|
|||
|
||||
def test_local_configs():
|
||||
"""Verify we return a ConfigParser."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
assert isinstance(finder.local_configs(), configparser.RawConfigParser)
|
||||
|
||||
|
||||
def test_local_configs_double_read():
|
||||
"""Second request for local configs is cached."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
first_read = finder.local_configs()
|
||||
boom = Exception("second request for local configs not cached")
|
||||
|
|
@ -129,24 +129,20 @@ def test_read_config_catches_decoding_errors(tmpdir):
|
|||
|
||||
def test_config_file_default_value():
|
||||
"""Verify the default 'config_file' attribute value."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
assert finder.config_file is None
|
||||
|
||||
|
||||
def test_setting_config_file_value():
|
||||
"""Verify the 'config_file' attribute matches constructed value."""
|
||||
config_file_value = 'flake8.ini'
|
||||
finder = config.ConfigFileFinder(
|
||||
'flake8',
|
||||
[],
|
||||
config_file=config_file_value,
|
||||
)
|
||||
finder = config.ConfigFileFinder('flake8', config_file=config_file_value)
|
||||
assert finder.config_file == config_file_value
|
||||
|
||||
|
||||
def test_ignore_config_files_default_value():
|
||||
"""Verify the default 'ignore_config_files' attribute value."""
|
||||
finder = config.ConfigFileFinder('flake8', [])
|
||||
finder = config.ConfigFileFinder('flake8')
|
||||
assert finder.ignore_config_files is False
|
||||
|
||||
|
||||
|
|
@ -158,7 +154,6 @@ def test_setting_ignore_config_files_value(ignore_config_files_arg):
|
|||
"""Verify the 'ignore_config_files' attribute matches constructed value."""
|
||||
finder = config.ConfigFileFinder(
|
||||
'flake8',
|
||||
[],
|
||||
ignore_config_files=ignore_config_files_arg
|
||||
)
|
||||
assert finder.ignore_config_files is ignore_config_files_arg
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ def test_get_local_plugins_uses_cli_config():
|
|||
def test_get_local_plugins():
|
||||
"""Verify get_local_plugins returns expected plugins."""
|
||||
config_fixture_path = 'tests/fixtures/config_files/local-plugin.ini'
|
||||
config_finder = config.ConfigFileFinder('flake8', [])
|
||||
config_finder = config.ConfigFileFinder('flake8')
|
||||
|
||||
with mock.patch.object(config_finder, 'local_config_files') as localcfs:
|
||||
localcfs.return_value = [config_fixture_path]
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def test_get_style_guide():
|
|||
mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
|
||||
mockedapp.program = 'flake8'
|
||||
with mock.patch('flake8.api.legacy.config.ConfigFileFinder') as mock_config_finder: # noqa: E501
|
||||
config_finder = ConfigFileFinder(mockedapp.program, [])
|
||||
config_finder = ConfigFileFinder(mockedapp.program)
|
||||
mock_config_finder.return_value = config_finder
|
||||
|
||||
with mock.patch('flake8.main.application.Application') as application:
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ def optmanager():
|
|||
@pytest.fixture
|
||||
def config_finder():
|
||||
"""Generate a simple ConfigFileFinder."""
|
||||
return config.ConfigFileFinder('flake8', [])
|
||||
return config.ConfigFileFinder('flake8')
|
||||
|
||||
|
||||
def test_parse_cli_config(optmanager, config_finder):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue