コード例 #1
0
ファイル: mochi_auto_test.py プロジェクト: monovinyl/mochi
def make_paramters(module_names, file_path=__file__):
    """Create parameters for py.test.generated tests.

    Creates a generator with pairs of functions.
    The first function is to be tested and the second functions returns
    th expected result of the first function.
    Converted into a list it would like this:
    [<function func_1>, <function result_func_1>,
     <function func_2>, <function result_func_2>,
     ...
     <function func_n>, <function result_func_n>,]
    """
    modules = [get_module(m_name, file_path) for m_name in module_names]
    params = (auto_test(module) for module in modules)
    return it.chain(*params)  # pylint: disable=star-args
コード例 #2
0
ファイル: mochi_auto_test.py プロジェクト: d6e/mochi
def make_paramters(module_names, file_path=__file__):
    """Create parameters for py.test.generated tests.

    Creates a generator with pairs of functions.
    The first function is to be tested and the second functions returns
    th expected result of the first function.
    Converted into a list it would like this:
    [<function func_1>, <function result_func_1>,
     <function func_2>, <function result_func_2>,
     ...
     <function func_n>, <function result_func_n>,]
    """
    modules = [get_module(m_name, file_path) for m_name in module_names]
    params = (auto_test(module) for module in modules)
    return it.chain(*params)  # pylint: disable=star-args
コード例 #3
0
from conftest import auto_test

get_module = partial(get_module, file_path=__file__)
get_function = partial(get_function, file_path=__file__)

factorial = get_function('factorial')
fizzbuzz = get_function('fizzbuzz')
patterns = get_module('patterns')


def test_factorial_1():
    assert factorial(1) == 1


def test_factorial_2():
    assert factorial(2) == 2


def test_fizzbuzz():
    res = [1, 2, 'fizz', 4, 'buzz', 'fizz', 7, 8, 'fizz', 'buzz', 11, 'fizz',
           13, 14, 'fizzbuzz', 16, 17, 'fizz', 19, 'buzz', 'fizz', 22, 23,
           'fizz', 'buzz', 26, 'fizz', 28, 29, 'fizzbuzz']
    assert [fizzbuzz(n) for n in range(1, 31)] == res


@pytest.mark.parametrize("func,result", auto_test(patterns))
def test_patterns(func, result):
    assert func() == result()