Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Joshua Storck · committed by Joshua Storck · parent b24a3c6 · Browse files · 2 files+7 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−8 removed

  • tests:+1 added−1 removed
  • other:+6 added−7 removed

2 files+7 added−8 removed

modified:click/core.py+6 added-7 removed
144 unmodified lines
145 146 VALUES = {COMMANDLINE, ENVIRONMENT, DEFAULT, DEFAULT_MAP}147 148 @classmethod149 def validate(clz, value):149 def validate(cls, value):150 """Validate that the specified value is a valid enum.151152 This method will raise a ValueError if the value is153 not a valid enum.154155 :param clz: ParameterSource.class155 :param value: the string value to verify156 """158 if value not in clz.VALUES:157 if value not in cls.VALUES:158 raise ValueError("Invalid ParameterSource value: '{}'. Valid "160 "values are: {}".format(value, ",".join(clz.VALUES)))159 "values are: {}".format(value, ",".join(cls.VALUES)))160161162class Context(object):163 """The context is a special internal object that holds state relevant
203 unmodified lines
367 self.color = color368369 self._close_callbacks = []370 self._depth = 0372 self._sources_by_paramname = {}371 self._source_by_paramname = {}372 373 def __enter__(self):374 self._depth += 1375 push_context(self)
236 unmodified lines
612 :param source: the source of the command line parameter, which613 should be a valid ParameterSource value614 """615 ParameterSource.validate(source)617 self._sources_by_paramname[name] = source616 self._source_by_paramname[name] = source617618 def get_parameter_source(self, name):619 """Get the source of a parameter.620
7 unmodified lines
628 :param name: the name of the command line parameter629 :returns: the source630 :rtype: ParameterSource631 """633 return self._sources_by_paramname[name]632 return self._source_by_paramname[name]633634635class BaseCommand(object):636 """The base command implements the minimal API contract of commands.
1291 unmodified lines
modified:tests/test_context.py+1 added-1 removed
312 unmodified lines
313314315def test_validate_parameter_source():316 with pytest.raises(ValueError):317 click.ParameterSource.validate("DEFAUL")317 click.ParameterSource.validate("NOT_A_VALID_PARAMETER_SOURCE")