mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 07:44:16 +00:00
Add failing test for OptionManager.parse_args
This commit is contained in:
parent
36cc254542
commit
ad0200e792
2 changed files with 21 additions and 4 deletions
|
|
@ -149,12 +149,12 @@ class OptionManager(object):
|
||||||
def parse_args(self, args=None, values=None):
|
def parse_args(self, args=None, values=None):
|
||||||
"""Simple proxy to calling the OptionParser's parse_args method."""
|
"""Simple proxy to calling the OptionParser's parse_args method."""
|
||||||
options, xargs = self.parser.parse_args(args, values)
|
options, xargs = self.parser.parse_args(args, values)
|
||||||
for config_name, option in self.config_options_dict.items():
|
for option in self.options:
|
||||||
dest = option.dest or config_name
|
dest = option.dest
|
||||||
if self.normalize_paths:
|
if option.normalize_paths:
|
||||||
old_value = getattr(options, dest)
|
old_value = getattr(options, dest)
|
||||||
setattr(options, dest, utils.normalize_paths(old_value))
|
setattr(options, dest, utils.normalize_paths(old_value))
|
||||||
elif self.comma_separated_list:
|
elif option.comma_separated_list:
|
||||||
old_value = getattr(options, dest)
|
old_value = getattr(options, dest)
|
||||||
setattr(options, dest,
|
setattr(options, dest,
|
||||||
utils.parse_comma_separated_list(old_value))
|
utils.parse_comma_separated_list(old_value))
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
"""Unit tests for flake.options.manager.OptionManager."""
|
"""Unit tests for flake.options.manager.OptionManager."""
|
||||||
import optparse
|
import optparse
|
||||||
|
import os
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
@ -57,3 +58,19 @@ def test_add_option_with_custom_args(optmanager):
|
||||||
attrs = ['parse_from_config', 'comma_separated_list', 'normalize_paths']
|
attrs = ['parse_from_config', 'comma_separated_list', 'normalize_paths']
|
||||||
for option, attr in zip(optmanager.options, attrs):
|
for option, attr in zip(optmanager.options, attrs):
|
||||||
assert getattr(option, attr) is True
|
assert getattr(option, attr) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_args(optmanager):
|
||||||
|
assert optmanager.options == []
|
||||||
|
assert optmanager.config_options_dict == {}
|
||||||
|
|
||||||
|
optmanager.add_option('-v', '--verbose', action='count')
|
||||||
|
optmanager.add_option('--config', normalize_paths=True)
|
||||||
|
optmanager.add_option('--exclude', default='E123,W234',
|
||||||
|
comma_separated_list=True)
|
||||||
|
|
||||||
|
options, args = optmanager.parse_args(
|
||||||
|
['-v', '-v', '-v', '--config', '../config.ini']
|
||||||
|
)
|
||||||
|
assert options.verbose == 3
|
||||||
|
assert options.config == os.path.abspath('../config.ini')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue