mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
config: Switch code paths to use 'ConfigFileFinder.config_file'
Now that the `ConfigFileFinder` has the `.config_file` attribute, switch the relevant code paths to utilize this public attribute. Tests have been updated to either construct `ConfigFileFinder` or mock the object appropriately.
This commit is contained in:
parent
153032f778
commit
77b2506071
4 changed files with 19 additions and 12 deletions
|
|
@ -317,14 +317,14 @@ class MergedConfigParser(object):
|
||||||
)
|
)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if cli_config:
|
if self.config_finder.config_file:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
"Ignoring user and locally found configuration files. "
|
"Ignoring user and locally found configuration files. "
|
||||||
'Reading only configuration from "%s" specified via '
|
'Reading only configuration from "%s" specified via '
|
||||||
"--config by the user",
|
"--config by the user",
|
||||||
cli_config,
|
self.config_finder.config_file,
|
||||||
)
|
)
|
||||||
return self.parse_cli_config(cli_config)
|
return self.parse_cli_config(self.config_finder.config_file)
|
||||||
|
|
||||||
return self.merge_user_and_local_config()
|
return self.merge_user_and_local_config()
|
||||||
|
|
||||||
|
|
@ -351,14 +351,14 @@ def get_local_plugins(config_finder, cli_config=None):
|
||||||
)
|
)
|
||||||
return local_plugins
|
return local_plugins
|
||||||
|
|
||||||
if cli_config:
|
if config_finder.config_file:
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
'Reading local plugins only from "%s" specified via '
|
'Reading local plugins only from "%s" specified via '
|
||||||
"--config by the user",
|
"--config by the user",
|
||||||
cli_config,
|
config_finder.config_file,
|
||||||
)
|
)
|
||||||
config = config_finder.cli_config(cli_config)
|
config = config_finder.cli_config(config_finder.config_file)
|
||||||
config_files = [cli_config]
|
config_files = [config_finder.config_file]
|
||||||
else:
|
else:
|
||||||
config, config_files = config_finder.local_configs_with_files()
|
config, config_files = config_finder.local_configs_with_files()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,10 @@ def test_aggregate_options_with_config(optmanager):
|
||||||
"""Verify we aggregate options and config values appropriately."""
|
"""Verify we aggregate options and config values appropriately."""
|
||||||
arguments = ['flake8', '--select',
|
arguments = ['flake8', '--select',
|
||||||
'E11,E34,E402,W,F', '--exclude', 'tests/*']
|
'E11,E34,E402,W,F', '--exclude', 'tests/*']
|
||||||
config_finder = config.ConfigFileFinder('flake8', [])
|
config_finder = config.ConfigFileFinder(
|
||||||
|
'flake8',
|
||||||
|
[],
|
||||||
|
config_file=CLI_SPECIFIED_CONFIG)
|
||||||
options, args = aggregator.aggregate_options(
|
options, args = aggregator.aggregate_options(
|
||||||
optmanager, config_finder, CLI_SPECIFIED_CONFIG, arguments)
|
optmanager, config_finder, CLI_SPECIFIED_CONFIG, arguments)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,12 @@ def test_get_local_plugins_uses_cli_config():
|
||||||
config_finder.cli_config.return_value = config_obj
|
config_finder.cli_config.return_value = config_obj
|
||||||
config_finder.ignore_config_files = False
|
config_finder.ignore_config_files = False
|
||||||
config_obj.get.return_value = ''
|
config_obj.get.return_value = ''
|
||||||
|
config_file_value = 'foo.ini'
|
||||||
|
config_finder.config_file = config_file_value
|
||||||
|
|
||||||
config.get_local_plugins(config_finder, cli_config='foo.ini')
|
config.get_local_plugins(config_finder, cli_config=config_file_value)
|
||||||
|
|
||||||
config_finder.cli_config.assert_called_once_with('foo.ini')
|
config_finder.cli_config.assert_called_once_with(config_file_value)
|
||||||
|
|
||||||
|
|
||||||
def test_get_local_plugins():
|
def test_get_local_plugins():
|
||||||
|
|
|
||||||
|
|
@ -155,12 +155,14 @@ def test_parse_isolates_config(optmanager):
|
||||||
|
|
||||||
def test_parse_uses_cli_config(optmanager):
|
def test_parse_uses_cli_config(optmanager):
|
||||||
"""Verify behaviour of the parse method with a specified config."""
|
"""Verify behaviour of the parse method with a specified config."""
|
||||||
|
config_file_value = 'foo.ini'
|
||||||
config_finder = mock.MagicMock()
|
config_finder = mock.MagicMock()
|
||||||
|
config_finder.config_file = config_file_value
|
||||||
config_finder.ignore_config_files = False
|
config_finder.ignore_config_files = False
|
||||||
parser = config.MergedConfigParser(optmanager, config_finder)
|
parser = config.MergedConfigParser(optmanager, config_finder)
|
||||||
|
|
||||||
parser.parse(cli_config='foo.ini')
|
parser.parse(cli_config=config_file_value)
|
||||||
config_finder.cli_config.assert_called_once_with('foo.ini')
|
config_finder.cli_config.assert_called_once_with(config_file_value)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('config_fixture_path', [
|
@pytest.mark.parametrize('config_fixture_path', [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue