コード例 #1
0
    def define_setting(
        cls,
        name,
        description,
        default,
        options=None,
        deprecation=None,
        validator=None,
        show_default=True,
    ):
        """Add a new setting.

        - name is the name of the property that will be used to access the
          setting. This must be a valid python identifier.
        - description will appear in the property's docstring
        - default is the default value. This may be a zero argument
          function in which case it is evaluated and its result is stored
          the first time it is accessed on any given settings object.

        """
        if settings.__definitions_are_locked:
            from hypothesis.errors import InvalidState
            raise InvalidState(
                'settings have been locked and may no longer be defined.')
        if options is not None:
            options = tuple(options)
            assert default in options

        all_settings[name] = Setting(name, description.strip(), default,
                                     options, validator)
        setattr(settings, name, settingsProperty(name, show_default))
コード例 #2
0
ファイル: functions.py プロジェクト: wlof-2/Poetry_analysis
 def inner(*args, **kwargs):
     if data.frozen:
         raise InvalidState(
             "This generated %s function can only be called within the "
             "scope of the @given that created it." %
             (nicerepr(self.like), ))
     val = data.draw(self.returns)
     note("Called function: %s(%s) -> %r" % (nicerepr(
         self.like), arg_string(self.like, args, kwargs), val))
     return val
コード例 #3
0
 def inner(*args, **kwargs):
     if data.frozen:
         raise InvalidState(
             "This generated %s function can only be called within the "
             "scope of the @given that created it." %
             (nicerepr(self.like), ))
     if self.pure:
         args, kwargs = convert_positional_arguments(
             self.like, args, kwargs)
         key = (inner, args, frozenset(kwargs.items()))
         val = data.draw(SharedStrategy(base=self.returns, key=key))
     else:
         val = data.draw(self.returns)
     note("Called function: %s(%s) -> %r" % (nicerepr(
         self.like), arg_string(self.like, args, kwargs), val))
     return val
コード例 #4
0
    def _define_setting(
        cls,
        name,
        description,
        default,
        options=None,
        validator=None,
        show_default=True,
        future_default=not_set,
        deprecation_message=None,
        deprecated_since=None,
        hide_repr=not_set,
    ):
        """Add a new setting.

        - name is the name of the property that will be used to access the
          setting. This must be a valid python identifier.
        - description will appear in the property's docstring
        - default is the default value. This may be a zero argument
          function in which case it is evaluated and its result is stored
          the first time it is accessed on any given settings object.
        """
        if settings.__definitions_are_locked:
            raise InvalidState(
                "settings have been locked and may no longer be defined.")
        if options is not None:
            options = tuple(options)
            assert default in options

        if future_default is not_set:
            future_default = default

        if hide_repr is not_set:
            hide_repr = bool(deprecation_message)

        all_settings[name] = Setting(
            name=name,
            description=description.strip(),
            default=default,
            options=options,
            validator=validator,
            future_default=future_default,
            deprecation_message=deprecation_message,
            deprecated_since=deprecated_since,
            hide_repr=hide_repr,
        )
        setattr(settings, name, settingsProperty(name, show_default))
コード例 #5
0
    def _define_setting(
        cls,
        name,
        description,
        default,
        options=None,
        validator=None,
        show_default=True,
    ):
        """Add a new setting.

        - name is the name of the property that will be used to access the
          setting. This must be a valid python identifier.
        - description will appear in the property's docstring
        - default is the default value. This may be a zero argument
          function in which case it is evaluated and its result is stored
          the first time it is accessed on any given settings object.
        """
        if settings.__definitions_are_locked:
            raise InvalidState(
                "settings have been locked and may no longer be defined."
            )
        if options is not None:
            options = tuple(options)
            assert default in options

            def validator(value):
                if value not in options:
                    msg = f"Invalid {name}, {value!r}. Valid options: {options!r}"
                    raise InvalidArgument(msg)
                return value

        else:
            assert validator is not None

        all_settings[name] = Setting(
            name=name,
            description=description.strip(),
            default=default,
            validator=validator,
        )
        setattr(settings, name, settingsProperty(name, show_default))
コード例 #6
0
ファイル: functions.py プロジェクト: jjpal/hypothesis
 def inner(*args, **kwargs):
     if data.frozen:
         raise InvalidState(
             f"This generated {nicerepr(self.like)} function can only "
             "be called within the scope of the @given that created it."
         )
     if self.pure:
         args, kwargs = convert_positional_arguments(
             self.like, args, kwargs)
         key = (args, frozenset(kwargs.items()))
         cache = self._cache.setdefault(inner, {})
         if key not in cache:
             cache[key] = data.draw(self.returns)
             rep = repr_call(self.like, args, kwargs, reorder=False)
             note(f"Called function: {rep} -> {cache[key]!r}")
         return cache[key]
     else:
         val = data.draw(self.returns)
         rep = repr_call(self.like, args, kwargs, reorder=False)
         note(f"Called function: {rep} -> {val!r}")
         return val
コード例 #7
0
 def __check_changed(self):
     if self.__generation != self.__lstar.generation:
         raise InvalidState(
             "The underlying L* model has changed, so this DFA is no longer valid. "
             "If you want to preserve a previously learned DFA for posterity, call "
             "canonicalise() on it first.")