Exemple #1
0
def apply_scenario(scenario, test):
    """Apply scenario to test.

    :param scenario: A tuple (name, parameters) to apply to the test. The test
        is cloned, its id adjusted to have (name) after it, and the parameters
        dict is used to update the new test.
    :param test: The test to apply the scenario to. This test is unaltered.
    :return: A new test cloned from test, with the scenario applied.
    """
    name, parameters = scenario
    scenario_suffix = '(' + name + ')'
    newtest = clone_test_with_new_id(test, test.id() + scenario_suffix)
    test_desc = test.shortDescription()
    if test_desc is not None:
        newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
        newtest.shortDescription = (lambda: newtest_desc)
    for key, value in parameters.items():
        setattr(newtest, key, value)
    return newtest
Exemple #2
0
def apply_scenario(scenario, test):
    """Apply scenario to test.

    :param scenario: A tuple (name, parameters) to apply to the test. The test
        is cloned, its id adjusted to have (name) after it, and the parameters
        dict is used to update the new test.
    :param test: The test to apply the scenario to. This test is unaltered.
    :return: A new test cloned from test, with the scenario applied.
    """
    name, parameters = scenario
    scenario_suffix = '(' + name + ')'
    newtest = clone_test_with_new_id(test,
        test.id() + scenario_suffix)
    test_desc = test.shortDescription()
    if test_desc is not None:
        newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
        newtest.shortDescription = (lambda: newtest_desc)
    for key, value in parameters.items():
        setattr(newtest, key, value)
    return newtest
from testtools.testcase import clone_test_with_new_id
from testtools import iterate_tests


def apply_scenario((name, parameters), test):
    """Apply scenario to test.

    :param scenario: A tuple (name, parameters) to apply to the test. The test
        is cloned, its id adjusted to have (name) after it, and the parameters
        dict is used to update the new test.
    :param test: The test to apply the scenario to. This test is unaltered.
    :return: A new test cloned from test, with the scenario applied.
    """
    scenario_suffix = '(' + name + ')'
    newtest = clone_test_with_new_id(test,
        test.id() + scenario_suffix)
    test_desc = test.shortDescription()
    if test_desc is not None:
        newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
        newtest.shortDescription = (lambda: newtest_desc)
    for key, value in parameters.iteritems():
        setattr(newtest, key, value)
    return newtest


def apply_scenarios(scenarios, test):
    """Apply many scenarios to a test.

    :param scenarios: An iterable of scenarios.
    :param test: A test to apply the scenarios to.
    :return: A generator of tests.