Beispiel #1
0
    def test__check_inputs_ok_int_type_alternative(self):
        # GIVEN
        props = {'int_prop': dict(argtype=int, default=1, alternatives=[(str, lambda i: int(i))])}
        inputs = {'int_prop': '5'}

        # WHEN
        wrapper = DecWrapper('test', inputs, props)

        # THEN
        self.assertEqual(wrapper.p('int_prop'), 5)
Beispiel #2
0
    def test__check_inputs_ok_tuple_list_type(self):
        # GIVEN
        props = {'tuple_list_prop': dict(argtype=[(int, str)], default=list())}
        inputs = {'tuple_list_prop': [(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')]}

        # WHEN
        wrapper = DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(wrapper.p('tuple_list_prop'), [(1, '1'), (2, '2'), (3, '3'), (4, '4'), (5, '5')])
Beispiel #3
0
    def test__check_inputs_ok_int_type(self):
        # GIVEN
        props = {'int_prop': dict(argtype=int, default=1)}
        inputs = {'int_prop': 5}

        # WHEN
        wrapper = DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(wrapper.p('int_prop'), 5)
Beispiel #4
0
    def test__check_inputs_set_defaults(self):
        # GIVEN
        props = {'int_prop': dict(argtype=[int], default=1)}
        inputs = {}

        # WHEN
        wrapper = DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(wrapper.p('int_prop'), 1)
Beispiel #5
0
    def test__check_inputs_ok_dict_using_alternative(self):
        # GIVEN
        props = {
            'dict_prop': dict(
                argtype=dict,
                alternatives=[
                    ([(int, int)], lambda v: dict(i for i in v))
                ],
                default=dict()
            )
        }
        inputs = {'dict_prop': [(10, 15), (20, 30)]}

        # WHEN
        wrapper = DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(wrapper.p('dict_prop'), {10: 15, 20: 30})
Beispiel #6
0
    def test__check_inputs_mandatory_arg_missing(self):
        # GIVEN
        props = dict(str_prop=dict(argtype=[str], mandatory=True))
        inputs = dict(other_prop='value')

        # WHEN
        with self.assertRaises(SyntaxError) as cm:
            DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(
            str(cm.exception),
            "[Test] : Mandatory option 'str_prop' is missing."
        )
Beispiel #7
0
    def test__check_inputs_bad_int_type(self):
        # GIVEN
        props = {'int_prop': dict(argtype=int, default=1)}
        inputs = {'int_prop': 'toto'}

        # WHEN
        with self.assertRaises(TypeError) as cm:
            DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(
            str(cm.exception),
            "[Test] : Option 'int_prop' bad type. Expected 'int'. Got 'str' instead."
        )
Beispiel #8
0
    def test__check_inputs_prop_undefined(self):
        # GIVEN
        props = {'int_prop': dict(argtype=[int], default=1)}
        inputs = {'undefined_prop': 'toto'}

        # WHEN
        with self.assertRaises(SyntaxError) as cm:
            DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(
            str(cm.exception),
            "[Test] : Option 'undefined_prop' doesn't not exist."
        )
Beispiel #9
0
    def test__check_inputs_bad_dict_using_alternative(self):
        # GIVEN
        props = {
            'dict_prop': dict(argtype=dict, alternatives=[([(int, int)], lambda x: x)], default=dict())
        }
        inputs = {
            'dict_prop': [
                ('10', '15'),
                ('20', '30'),
            ]
        }

        # WHEN
        with self.assertRaises(TypeError) as cm:
            DecWrapper('Test', inputs, props)

        # THEN
        self.assertEqual(
            str(cm.exception),
            "[Test] : Option 'dict_prop' bad type. Expected 'dict'. Got 'list' instead."
        )