add func_* for test_inspect

This commit is contained in:
Prodesire 2017-11-19 11:41:42 +08:00
parent dc4b944712
commit 33736c6776
1 changed files with 33 additions and 1 deletions

View File

@ -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)