diff options
author | Joshua Storck <joshua.storck@twosigma.com> | 2019-06-03 10:50:30 -0400 |
---|---|---|
committer | Joshua Storck <joshua.storck@twosigma.com> | 2019-06-03 10:50:30 -0400 |
commit | c296d4415efbbf1e6e7095ea3295462ae962cde4 (patch) | |
tree | fa48f9e3910c9c94b99341c943453badf5bfe7eb | |
parent | b24a3c69353791ade7bded61c76b0c31bdee12ea (diff) | |
download | click-c296d4415efbbf1e6e7095ea3295462ae962cde4.tar.gz |
Changing ParameterSource.validate unit test to take a descriptive bad value. Changing Context._sources_by_paramname to Context._source_by_paramname. Renaming ParameterSource.validate clz arg to cls and removing doc for that argument in the docstring
-rw-r--r-- | click/core.py | 13 | ||||
-rw-r--r-- | tests/test_context.py | 2 |
2 files changed, 7 insertions, 8 deletions
diff --git a/click/core.py b/click/core.py index 196f5a7..b0bfccd 100644 --- a/click/core.py +++ b/click/core.py @@ -146,18 +146,17 @@ class ParameterSource(object): VALUES = {COMMANDLINE, ENVIRONMENT, DEFAULT, DEFAULT_MAP} @classmethod - def validate(clz, value): + def validate(cls, value): """Validate that the specified value is a valid enum. This method will raise a ValueError if the value is not a valid enum. - :param clz: ParameterSource.class :param value: the string value to verify """ - if value not in clz.VALUES: + if value not in cls.VALUES: raise ValueError("Invalid ParameterSource value: '{}'. Valid " - "values are: {}".format(value, ",".join(clz.VALUES))) + "values are: {}".format(value, ",".join(cls.VALUES))) class Context(object): @@ -369,7 +368,7 @@ class Context(object): self._close_callbacks = [] self._depth = 0 - self._sources_by_paramname = {} + self._source_by_paramname = {} def __enter__(self): self._depth += 1 @@ -614,7 +613,7 @@ class Context(object): should be a valid ParameterSource value """ ParameterSource.validate(source) - self._sources_by_paramname[name] = source + self._source_by_paramname[name] = source def get_parameter_source(self, name): """Get the source of a parameter. @@ -630,7 +629,7 @@ class Context(object): :returns: the source :rtype: ParameterSource """ - return self._sources_by_paramname[name] + return self._source_by_paramname[name] class BaseCommand(object): diff --git a/tests/test_context.py b/tests/test_context.py index 972cd45..3570749 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -314,4 +314,4 @@ def test_parameter_source_environment_variable_specified(runner): def test_validate_parameter_source(): with pytest.raises(ValueError): - click.ParameterSource.validate("DEFAUL") + click.ParameterSource.validate("NOT_A_VALID_PARAMETER_SOURCE") |