From 33736c677631a1a091b0d4a17a76e000fdd988d2 Mon Sep 17 00:00:00 2001 From: Prodesire Date: Sun, 19 Nov 2017 11:41:42 +0800 Subject: [PATCH] add func_* for test_inspect --- tests/test_inspect.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/test_inspect.py b/tests/test_inspect.py index fcd6336..ce59969 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -1,4 +1,4 @@ -from pydu.inspect import (get_func_full_args, func_accepts_var_args, +from pydu.inspect import (get_func_args, get_func_full_args, func_accepts_var_args, func_accepts_kwargs) @@ -19,25 +19,57 @@ class Person: return kwargs +def func_no_arguments(): + pass + + +def func_one_argument(something): + pass + + +def func_just_args(*args): + pass + + +def func_just_kwargs(**kwargs): + pass + + +def func_all_kinds(name, address='home', age=25, *args, **kwargs): + pass + + +def test_get_func_args(): + arguments = ['name', 'address', 'age'] + assert get_func_args(Person.all_kinds) == arguments + + def test_get_func_full_args(): # no arguments assert get_func_full_args(Person.no_arguments) == [] + assert get_func_full_args(func_no_arguments) == [] # one argument assert get_func_full_args(Person.one_argument) == [('something',)] + assert get_func_full_args(func_one_argument) == [('something',)] # all_arguments arguments = [('name',), ('address', 'home'), ('age', 25), ('*args',), ('**kwargs',)] assert get_func_full_args(Person.all_kinds) == arguments + assert get_func_full_args(func_all_kinds) == arguments def test_func_accepts_var_args(): # has args assert func_accepts_var_args(Person.just_args) + assert func_accepts_var_args(func_just_args) # no args assert not func_accepts_var_args(Person.one_argument) + assert not func_accepts_var_args(func_one_argument) def test_func_accepts_kwargs(): # has kwargs assert func_accepts_kwargs(Person.just_kwargs) + assert func_accepts_kwargs(func_just_kwargs) # no kwargs assert not func_accepts_kwargs(Person.one_argument) + assert not func_accepts_kwargs(func_one_argument)