summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pylint/config.py27
-rw-r--r--pylint/test/test_self.py8
2 files changed, 22 insertions, 13 deletions
diff --git a/pylint/config.py b/pylint/config.py
index b7e55b805..048d46769 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)
@@ -191,8 +189,9 @@ VALIDATORS = {
'regexp_csv': _regexp_csv_validator,
'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),
'non_empty_string': _non_empty_string_validator,
}
@@ -261,6 +260,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', 'regexp_csv', 'csv', 'yn',
'multiple_choice',
@@ -271,7 +274,7 @@ class Option(optparse.Option):
TYPE_CHECKER['regexp_csv'] = _regexp_csv_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
TYPE_CHECKER['non_empty_string'] = _non_empty_string_validator
def __init__(self, *opts, **attrs):
diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py
index 3f25f97ca..b32284858 100644
--- a/pylint/test/test_self.py
+++ b/pylint/test/test_self.py
@@ -359,7 +359,13 @@ class RunTC(unittest.TestCase):
def test_evaluation_score_shown_by_default(self):
expected_output = 'Your code has been rated at -60.00/10'
module = join(HERE, 'regrtest_data', 'application_crash.py')
- self._test_output([module], expected_output=expected_output)
+ self._test_output([module], expected_output=expected_output)
+
+ 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__':