~jayvdb/testscenarios/fix-py3-tests

« back to all changes in this revision

Viewing changes to lib/testscenarios/scenarios.py

  • Committer: john.lenton at canonical
  • Date: 2012-05-11 07:29:26 UTC
  • Revision ID: john.lenton@canonical.com-20120511072926-3or2hpro1ez2244c
make it work in python 3 (ran tests with 2.6, 2.7 and 3.2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from testtools import iterate_tests
35
35
 
36
36
 
37
 
def apply_scenario((name, parameters), test):
 
37
def apply_scenario(scenario, test):
38
38
    """Apply scenario to test.
39
39
 
40
40
    :param scenario: A tuple (name, parameters) to apply to the test. The test
43
43
    :param test: The test to apply the scenario to. This test is unaltered.
44
44
    :return: A new test cloned from test, with the scenario applied.
45
45
    """
 
46
    (name, parameters) = scenario
46
47
    scenario_suffix = '(' + name + ')'
47
48
    newtest = clone_test_with_new_id(test,
48
49
        test.id() + scenario_suffix)
50
51
    if test_desc is not None:
51
52
        newtest_desc = "%(test_desc)s %(scenario_suffix)s" % vars()
52
53
        newtest.shortDescription = (lambda: newtest_desc)
53
 
    for key, value in parameters.iteritems():
 
54
    for key, value in parameters.items():
54
55
        setattr(newtest, key, value)
55
56
    return newtest
56
57