summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-02-20 23:19:35 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-02-20 23:33:43 +0000
commit66d104b70b08ae109bc73e98c3dfc3609c5d89a9 (patch)
treeb338ab9c40dc0f9ee23e06b82e412d56ea48bbb7
parentd69a494aae0288a5a3419c8c14a5adf092cbb15c (diff)
downloadpylint-git-66d104b70b08ae109bc73e98c3dfc3609c5d89a9.tar.gz
Pass the proper objects to the validation functions from config.py
The problem was that the same validation functions were used both manually, with a custom option dictionary, as well as used for optparse.TYPE_CHECKER configuration, where they were expected to receive an optparse.Option object instead. A common function was created instead, which expects already the choices. Close #821
-rw-r--r--pylint/config.py27
-rw-r--r--pylint/test/test_self.py5
2 files changed, 20 insertions, 12 deletions
diff --git a/pylint/config.py b/pylint/config.py
index ba4e86559..d0728af81 100644
--- a/pylint/config.py
+++ b/pylint/config.py
@@ -134,15 +134,7 @@ class UnsupportedAction(Exception):
"""raised by set_option when it doesn't know what to do for an action"""
-def _choice_validator(optdict, name, value):
- if value not in optdict['choices']:
- msg = "option %s: invalid value: %r, should be in %s"
- raise optparse.OptionValueError(msg % (name, value, optdict['choices']))
- return value
-
-
-def _multiple_choice_validator(optdict, name, value):
- choices = optdict['choices']
+def _multiple_choice_validator(choices, name, value):
values = utils._check_csv(value)
for value in values:
if value not in choices:
@@ -151,6 +143,12 @@ def _multiple_choice_validator(optdict, name, value):
return values
+def _choice_validator(choices, name, value):
+ if value not in choices:
+ msg = "option %s: invalid value: %r, should be in %s"
+ raise optparse.OptionValueError(msg % (name, value, choices))
+ return value
+
# pylint: disable=unused-argument
def _csv_validator(_, name, value):
return utils._check_csv(value)
@@ -180,8 +178,9 @@ VALIDATORS = {
'regexp': re.compile,
'csv': _csv_validator,
'yn': _yn_validator,
- 'choice': _choice_validator,
- 'multiple_choice': _multiple_choice_validator,
+ 'choice': lambda opt, name, value: _choice_validator(opt['choices'], name, value),
+ 'multiple_choice': lambda opt, name, value: _multiple_choice_validator(opt['choices'],
+ name, value),
}
def _call_validator(opttype, optdict, option, value):
@@ -249,6 +248,10 @@ def _patch_optparse():
optparse.HelpFormatter.expand_default = orig_default
+def _multiple_choices_validating_option(opt, name, value):
+ return _multiple_choice_validator(opt.choices, name, value)
+
+
class Option(optparse.Option):
TYPES = optparse.Option.TYPES + ('regexp', 'csv', 'yn', 'multiple_choice')
ATTRS = optparse.Option.ATTRS + ['hide', 'level']
@@ -256,7 +259,7 @@ class Option(optparse.Option):
TYPE_CHECKER['regexp'] = _regexp_validator
TYPE_CHECKER['csv'] = _csv_validator
TYPE_CHECKER['yn'] = _yn_validator
- TYPE_CHECKER['multiple_choice'] = _multiple_choice_validator
+ TYPE_CHECKER['multiple_choice'] = _multiple_choices_validating_option
def __init__(self, *opts, **attrs):
optparse.Option.__init__(self, *opts, **attrs)
diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py
index 5776a062f..9a23cc039 100644
--- a/pylint/test/test_self.py
+++ b/pylint/test/test_self.py
@@ -341,6 +341,11 @@ class RunTC(unittest.TestCase):
self.assertEqual(message[key], value)
self.assertTrue(message['message'].startswith("No module named"))
+ def test_confidence_levels(self):
+ expected = 'No config file found, using default configuration'
+ path = join(HERE, 'regrtest_data', 'meta.py')
+ self._test_output([path, "--confidence=HIGH,INFERENCE"],
+ expected_output=expected)
if __name__ == '__main__':