mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-16 17:19:52 +00:00
Start testing MergedConfigParser
Rename the GETINT/GETBOOL sets on the MergedConfigParser to use better names.
This commit is contained in:
parent
8b85e93e21
commit
66da9160b4
2 changed files with 58 additions and 11 deletions
|
|
@ -128,8 +128,12 @@ class MergedConfigParser(object):
|
||||||
dictionaries with the parsed values.
|
dictionaries with the parsed values.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
GETINT_METHODS = set(['int', 'count'])
|
#: Set of types that should use the
|
||||||
GETBOOL_METHODS = set(['store_true', 'store_false'])
|
#: :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):
|
def __init__(self, option_manager, extra_config_files=None, args=None):
|
||||||
"""Initialize the MergedConfigParser instance.
|
"""Initialize the MergedConfigParser instance.
|
||||||
|
|
@ -141,18 +145,20 @@ class MergedConfigParser(object):
|
||||||
:params list args:
|
:params list args:
|
||||||
The extra parsed arguments from the command-line.
|
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
|
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
|
self.program_name = option_manager.program_name
|
||||||
# Parsed extra arguments
|
#: Parsed extra arguments
|
||||||
self.args = args
|
self.args = args
|
||||||
# Our instance of our ConfigFileFinder
|
#: Mapping of configuration option names to
|
||||||
self.config_finder = ConfigFileFinder(self.program_name, self.args)
|
#: :class:`~flake8.options.manager.Option` instances
|
||||||
# Mapping of configuration option names to
|
|
||||||
# flake8.options.manager.Option instances
|
|
||||||
self.config_options = option_manager.config_options_dict
|
self.config_options = option_manager.config_options_dict
|
||||||
|
#: List of extra config files
|
||||||
self.extra_config_files = extra_config_files or []
|
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
|
@staticmethod
|
||||||
def _normalize_value(option, value):
|
def _normalize_value(option, value):
|
||||||
|
|
@ -172,9 +178,9 @@ class MergedConfigParser(object):
|
||||||
|
|
||||||
# Use the appropriate method to parse the config value
|
# Use the appropriate method to parse the config value
|
||||||
method = config_parser.get
|
method = config_parser.get
|
||||||
if option.type in self.GETINT_METHODS:
|
if option.type in self.GETINT_TYPES:
|
||||||
method = config_parser.getint
|
method = config_parser.getint
|
||||||
elif option.action in self.GETBOOL_METHODS:
|
elif option.action in self.GETBOOL_ACTIONS:
|
||||||
method = config_parser.getboolean
|
method = config_parser.getboolean
|
||||||
|
|
||||||
value = method(self.program_name, option_name)
|
value = method(self.program_name, option_name)
|
||||||
|
|
|
||||||
41
tests/unit/test_merged_config_parser.py
Normal file
41
tests/unit/test_merged_config_parser.py
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue