veekun_pokedex/pokedex/tests/__init__.py

46 lines
1,009 B
Python
Raw Normal View History

2009-08-24 03:43:39 +00:00
2011-05-02 07:20:28 +00:00
import inspect
from functools import wraps
# test support code
def params(funcarglist):
"""Basic list-of-dicts test parametrization
From: http://pytest.org/funcargs.html
Example:
@params([dict(a=1, b=2), dict(a=3, b=4)])
def test_lt(a, b):
assert a < b
"""
def decorator(function):
function.funcarglist = funcarglist
return function
return decorator
def positional_params(*paramlist):
"""Magic list-of-lists parametrization
Example:
@params([(1, 2), (3, 4)])
def test_lt(a, b):
assert a < b
"""
def decorator(function):
function.posarglist = paramlist
return function
return decorator
def single_params(*paramlist):
"""Magic list-of-lists parametrization
Example:
@params('1', '2', '3', '4'])
def test_int(k):
assert int(k)
"""
def decorator(function):
function.posarglist = [[param] for param in paramlist]
return function
return decorator