Beispiel #1
0
    def test_check_args_2(self):
        def test_func(a: int, b: str, c=5, e=3, d=1):
            pass

        parser = Parser(test_func)

        self.my_assert(parser.check_args(*[1, '2'], **{'e': 8}), True)
Beispiel #2
0
    def test_required_args_3(self):
        def test_func(a, b, c, d, e, *args, **kwargs):
            pass

        parser = Parser(test_func)
        self.my_assert(tuple(parser.required_args()),
                       ('a', 'b', 'c', 'd', 'e'))
Beispiel #3
0
    def test_get_arguments_4(self):
        def test_func(a, b, c=4, *args, d, e, **kwargs):
            pass

        parser = Parser(test_func)
        self.my_assert(tuple(parser.get_arguments()),
                       (('a', 'b', 'c'), ('d', 'e'), ('args', ), ('kwargs', )))
Beispiel #4
0
    def test_check_return_5(self):
        def test_func() -> tuple:
            pass

        parser = Parser(test_func)

        parser.check_return(tuple([1, 2, 3]))
Beispiel #5
0
    def test_get_arguments_2(self):
        def test_func(a, b, c, d, *args):
            pass

        parser = Parser(test_func)
        self.my_assert(tuple(parser.get_arguments()),
                       (('a', 'b', 'c', 'd'), (), ('args', ), ()))
Beispiel #6
0
    def test_check_return_3(self):
        def test_func() -> int:
            pass

        parser = Parser(test_func)

        with self.assertRaises(ReturnAnnotationTypeError):
            parser.check_return(None)
Beispiel #7
0
    def test_check_args_6(self):
        def test_func(a: int):
            pass

        parser = Parser(test_func)

        with self.assertRaises(AnnotationTypeError):
            parser.check_args('a')
Beispiel #8
0
    def test_check_return_7(self):
        def test_func():
            pass

        parser = Parser(test_func)

        parser.check_return(True)
        parser.check_return(False)
        parser.check_return(1)
        parser.check_return('1')
Beispiel #9
0
    def test_check_return_4(self):
        def test_func() -> int:
            pass

        parser = Parser(test_func)

        parser.check_return(True)
        parser.check_return(False)
        parser.check_return(1)
Beispiel #10
0
    def test_check_return_6(self):
        def test_func() -> (tuple, list):
            pass

        parser = Parser(test_func)

        parser.check_return(tuple([1, 2, 3]))
        parser.check_return([1, 2, 3])
Beispiel #11
0
 def wrapper(*args, **kwargs):
     parser = Parser(f)
     parser.check_args(*args, **kwargs)
     result = f(*args, **kwargs)
     parser.check_return(result)
     return result
Beispiel #12
0
    def test_check_args_1(self):
        def test_func(a: int, b: str, c: int = 5, d=1):
            pass

        parser = Parser(test_func)
        self.my_assert(parser.check_args(1, '2'), True)
Beispiel #13
0
    def test_required_args_1(self):
        def test_func(a, b, c=5, d=1):
            pass

        parser = Parser(test_func)
        self.my_assert(tuple(parser.required_args()), ('a', 'b'))