Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 3
0
 def ioprocessor(self, **kwargs):
     kwargs.update({
         'coercion_functions': {
             YesCoercionType: custom_coercion_function
         }
     })
     return IOProcessor(**kwargs)
Exemplo n.º 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)
Exemplo n.º 6
0
 def test_no_iospec_passes(self):
     IOProcessor().verify(iovalue=object())
Exemplo n.º 7
0
    def preservation_test(self, parameter_name, initial, expected, iospec):
        result = IOProcessor(**{
            parameter_name: iospec
        }).coerce(iovalue=initial)

        assert result == expected
Exemplo n.º 8
0
 def anytype_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(iomanager.AnyType)
     }).verify(iovalue=self.wrap_iovalue(object()))
Exemplo n.º 9
0
 def correct_type_subclass_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(CustomType)
     }).verify(iovalue=self.wrap_iovalue(CustomSubclassType()))
Exemplo n.º 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))
Exemplo n.º 11
0
 def parameter_test(self, parameter_name, iovalue):
     IOProcessor(**{
         parameter_name: self.make_iospec(1)
     }).verify(iovalue=iovalue)
Exemplo n.º 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())
Exemplo n.º 13
0
 def unlimited_ignored_test(self, parameter_name):
     with pytest.raises(VerificationFailureError):
         IOProcessor(unlimited=True, **{
             parameter_name: CustomType
         }).verify(iovalue=object())
Exemplo n.º 14
0
 def none_value_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(object)
     }).verify(iovalue=self.wrap_iovalue(None))
Exemplo n.º 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()))
Exemplo n.º 16
0
 def test_no_iospec_passes(self):
     IOProcessor().coerce(iovalue=object())
Exemplo n.º 17
0
 def correct_type_passes_test(self, parameter_name):
     IOProcessor(**{
         parameter_name: self.wrap_iospec(object)
     }).verify(iovalue=self.wrap_iovalue(object()))
Exemplo n.º 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))
Exemplo n.º 19
0
 def unlimited_test(self, parameter_name):
     IOProcessor(unlimited=True, **{
         parameter_name: self.make_iospec(0)
     }).verify(iovalue=self.make_iovalue(1))
Exemplo n.º 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()))