diff --git a/flake8/options/config.py b/flake8/options/config.py index d4f64d8..558ec93 100644 --- a/flake8/options/config.py +++ b/flake8/options/config.py @@ -128,8 +128,12 @@ class MergedConfigParser(object): dictionaries with the parsed values. """ - GETINT_METHODS = set(['int', 'count']) - GETBOOL_METHODS = set(['store_true', 'store_false']) + #: Set of types that should use the + #: :meth:`~configparser.RawConfigParser.getint` method. + GETINT_TYPES = set(['int', 'count']) + #: Set of actions that should use the + #: :meth:`~configparser.RawConfigParser.getbool` method. + GETBOOL_ACTIONS = set(['store_true', 'store_false']) def __init__(self, option_manager, extra_config_files=None, args=None): """Initialize the MergedConfigParser instance. @@ -141,18 +145,20 @@ class MergedConfigParser(object): :params list args: The extra parsed arguments from the command-line. """ - # Our instance of flake8.options.manager.OptionManager + #: Our instance of flake8.options.manager.OptionManager self.option_manager = option_manager - # The prog value for the cli parser + #: The prog value for the cli parser self.program_name = option_manager.program_name - # Parsed extra arguments + #: Parsed extra arguments self.args = args - # Our instance of our ConfigFileFinder - self.config_finder = ConfigFileFinder(self.program_name, self.args) - # Mapping of configuration option names to - # flake8.options.manager.Option instances + #: Mapping of configuration option names to + #: :class:`~flake8.options.manager.Option` instances self.config_options = option_manager.config_options_dict + #: List of extra config files self.extra_config_files = extra_config_files or [] + #: Our instance of our :class:`~ConfigFileFinder` + self.config_finder = ConfigFileFinder(self.program_name, self.args, + self.extra_config_files) @staticmethod def _normalize_value(option, value): @@ -172,9 +178,9 @@ class MergedConfigParser(object): # Use the appropriate method to parse the config value method = config_parser.get - if option.type in self.GETINT_METHODS: + if option.type in self.GETINT_TYPES: method = config_parser.getint - elif option.action in self.GETBOOL_METHODS: + elif option.action in self.GETBOOL_ACTIONS: method = config_parser.getboolean value = method(self.program_name, option_name) diff --git a/tests/unit/test_merged_config_parser.py b/tests/unit/test_merged_config_parser.py new file mode 100644 index 0000000..2e79b4a --- /dev/null +++ b/tests/unit/test_merged_config_parser.py @@ -0,0 +1,41 @@ +"""Unit tests for flake8.options.config.MergedConfigParser.""" +import mock +import pytest + +from flake8.options import config +from flake8.options import manager + + +@pytest.fixture +def optmanager(): + return manager.OptionManager(prog='flake8', version='3.0.0a1') + + +@pytest.mark.parametrize('args,extra_config_files', [ + (None, None), + (None, []), + (None, ['foo.ini']), + ('flake8/', []), + ('flake8/', ['foo.ini']), +]) +def test_creates_its_own_config_file_finder(args, extra_config_files, + optmanager): + """Verify we create a ConfigFileFinder correctly.""" + class_path = 'flake8.options.config.ConfigFileFinder' + with mock.patch(class_path) as ConfigFileFinder: + parser = config.MergedConfigParser( + option_manager=optmanager, + extra_config_files=extra_config_files, + args=args, + ) + + assert parser.program_name == 'flake8' + ConfigFileFinder.assert_called_once_with( + 'flake8', + args, + extra_config_files or [], + ) + + +def test_parse_cli_config(optmanager): + pass