Пример #1
0
 def custom_function_test(self, value, custom_function):
     """ Confirm type checking behavior when custom type-checking functions
         are in use. """
     ioprocessor = IOProcessor(
         typecheck_functions={CustomType: custom_function},
         required=self.wrap_iospec(CustomType),
     )
     ioprocessor.verify(iovalue=self.wrap_iovalue(value))
Пример #2
0
    def test_error(self):
        expected_value = object()

        def success_error_coercion_function(value, expected_type):
            raise CoercionSuccessError(expected_value)

        processor = IOProcessor(required=YesCoercionType,
                                coercion_functions={
                                    YesCoercionType:
                                    success_error_coercion_function,
                                })

        result = processor.coerce(iovalue=YesCoercionType())

        assert result is expected_value
Пример #3
0
 def ioprocessor(self, **kwargs):
     kwargs.update({
         'coercion_functions': {
             YesCoercionType: custom_coercion_function
         }
     })
     return IOProcessor(**kwargs)
Пример #4
0
 def unlimited_extra_nested_item_raises_test(self, parameter_name):
     """ When 'unlimited' is True, only top-level keyword arguments are
         unlimited. 'dict'-type iovalues should still be checked for unknown
         keys. """
     with pytest.raises(VerificationFailureError):
         IOProcessor(unlimited=True,
                     **{
                         parameter_name: self.make_iospec(1)
                     }).verify(iovalue=self.make_iovalue(2))
    def test_result(self):
        result = iospecs_from_callable(self.callable)

        # Construct dummy iovals. For each key in 'required', 'optional', set
        # that key value to 'None' in the dummy ioval.
        iovals = {}
        for item in result.values():
            for ikey in item:
                iovals.setdefault(ikey, None)

        IOProcessor(**result).verify(iovals)
Пример #6
0
 def test_no_iospec_passes(self):
     IOProcessor().verify(iovalue=object())
Пример #7
0
    def preservation_test(self, parameter_name, initial, expected, iospec):
        result = IOProcessor(**{
            parameter_name: iospec
        }).coerce(iovalue=initial)

        assert result == expected
Пример #8
0
 def anytype_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(iomanager.AnyType)
     }).verify(iovalue=self.wrap_iovalue(object()))
Пример #9
0
 def correct_type_subclass_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(CustomType)
     }).verify(iovalue=self.wrap_iovalue(CustomSubclassType()))
Пример #10
0
 def test_required_overrides_optional(self):
     with pytest.raises(VerificationFailureError):
         IOProcessor(
             required=self.make_iospec(1),
             optional=self.make_iospec(1),
         ).verify(iovalue=self.make_iovalue(0))
Пример #11
0
 def parameter_test(self, parameter_name, iovalue):
     IOProcessor(**{
         parameter_name: self.make_iospec(1)
     }).verify(iovalue=iovalue)
Пример #12
0
 def test_unlimited_ignored_no_iospec(self):
     """ When no 'iospec' is provided, verification and 'unlimited' is ignored
         ('True' and 'False' both pass).
         
         Similar to the situation with non-container IOSpecs."""
     IOProcessor(unlimited=True, ).verify(iovalue=object())
Пример #13
0
 def unlimited_ignored_test(self, parameter_name):
     with pytest.raises(VerificationFailureError):
         IOProcessor(unlimited=True, **{
             parameter_name: CustomType
         }).verify(iovalue=object())
Пример #14
0
 def none_value_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(object)
     }).verify(iovalue=self.wrap_iovalue(None))
Пример #15
0
 def test_required_overrides_optional(self):
     IOProcessor(
         required=self.wrap_iospec(object),
         optional=self.wrap_iospec(CustomType),
     ).verify(iovalue=self.wrap_iovalue(object()))
Пример #16
0
 def test_no_iospec_passes(self):
     IOProcessor().coerce(iovalue=object())
Пример #17
0
 def correct_type_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(object)
     }).verify(iovalue=self.wrap_iovalue(object()))
Пример #18
0
 def test_optional_extends_required(self):
     IOProcessor(
         required=self.make_iospec(1),
         optional=self.make_iospec(2),
     ).verify(iovalue=self.make_iovalue(2))
Пример #19
0
 def unlimited_test(self, parameter_name):
     IOProcessor(unlimited=True, **{
         parameter_name: self.make_iospec(0)
     }).verify(iovalue=self.make_iovalue(1))
Пример #20
0
 def wrong_type_raises_test(self, parameter_name):
     with pytest.raises(VerificationFailureError):
         IOProcessor(**{
             parameter_name: self.wrap_iospec(CustomType)
         }).verify(iovalue=self.wrap_iovalue(object()))