From a8576aff1239c3eb3e4d3e3ab28e82d045665e8e Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sun, 10 Jan 2016 13:22:18 -0600 Subject: [PATCH] Fix bugs found while writing parse_cli_config test --- flake8/options/config.py | 4 +++- flake8/options/manager.py | 3 ++- tests/unit/test_merged_config_parser.py | 21 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/flake8/options/config.py b/flake8/options/config.py index 558ec93..7acddd5 100644 --- a/flake8/options/config.py +++ b/flake8/options/config.py @@ -186,9 +186,11 @@ class MergedConfigParser(object): value = method(self.program_name, option_name) LOG.debug('Option "%s" returned value: %r', option_name, value) - final_value = self._normalize_value(value) + final_value = self._normalize_value(option, value) config_dict[option_name] = final_value + return config_dict + def is_configured_by(self, config): """Check if the specified config parser has an appropriate section.""" return config.has_section(self.program_name) diff --git a/flake8/options/manager.py b/flake8/options/manager.py index fafc1e9..c4da8e0 100644 --- a/flake8/options/manager.py +++ b/flake8/options/manager.py @@ -104,7 +104,8 @@ class Option(object): 'dest={dest}, type={type}, callback={callback}, help={help},' ' callback={callback}, callback_args={callback_args}, ' 'callback_kwargs={callback_kwargs}, metavar={metavar})' - ).format(*self.option_args, **self.option_kwargs) + ).format(self.short_option_name, self.long_option_name, + **self.option_kwargs) def _make_dest(self, dest): if dest: diff --git a/tests/unit/test_merged_config_parser.py b/tests/unit/test_merged_config_parser.py index 2e79b4a..028ad18 100644 --- a/tests/unit/test_merged_config_parser.py +++ b/tests/unit/test_merged_config_parser.py @@ -1,4 +1,6 @@ """Unit tests for flake8.options.config.MergedConfigParser.""" +import os + import mock import pytest @@ -38,4 +40,21 @@ def test_creates_its_own_config_file_finder(args, extra_config_files, def test_parse_cli_config(optmanager): - pass + optmanager.add_option('--exclude', parse_from_config=True, + comma_separated_list=True, + normalize_paths=True) + optmanager.add_option('--ignore', parse_from_config=True, + comma_separated_list=True) + parser = config.MergedConfigParser(optmanager) + + parsed_config = parser.parse_cli_config( + 'tests/fixtures/config_files/cli-specified.ini' + ) + assert parsed_config == { + 'ignore': ['E123', 'W234', 'E111'], + 'exclude': [ + os.path.abspath('foo/'), + os.path.abspath('bar/'), + os.path.abspath('bogus/'), + ] + }