diff options
author | Martin Pool <mbp@sourcefrog.net> | 2010-10-12 15:50:57 +1100 |
---|---|---|
committer | Martin Pool <mbp@sourcefrog.net> | 2010-10-12 15:50:57 +1100 |
commit | 977abd578ffa376be31e6382d4b0baab1c54ccef (patch) | |
tree | 016d3f96e73dda73e8bec77bf0158a9e21a3d92a /lib/testscenarios/scenarios.py | |
parent | 494fcff75bd2df7a42f14fee6d2f82f011f2da3f (diff) | |
download | testscenarios-977abd578ffa376be31e6382d4b0baab1c54ccef.tar.gz |
Add multiply_scenarios
Diffstat (limited to 'lib/testscenarios/scenarios.py')
-rw-r--r-- | lib/testscenarios/scenarios.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/testscenarios/scenarios.py b/lib/testscenarios/scenarios.py index 3cf8091..c284afd 100644 --- a/lib/testscenarios/scenarios.py +++ b/lib/testscenarios/scenarios.py @@ -22,6 +22,11 @@ __all__ = [ 'load_tests_apply_scenarios', ] + +from itertools import ( + chain, + product, + ) import unittest from testtools.testcase import clone_test_with_new_id @@ -104,3 +109,23 @@ def load_tests_apply_scenarios(*params): result = loader.suiteClass() result.addTests(generate_scenarios(standard_tests)) return result + + +def multiply_scenarios(*scenarios): + """Multiply two or more iterables of scenarios. + + It is safe to pass scenario generators or iterators. + + :returns: A list of compound scenarios: the cross-product of all + scenarios, with the names concatenated and the parameters + merged together. + """ + r = [] + scenario_lists = map(list, scenarios) + products = product(*scenario_lists) + for combo in products: + names, params = zip(*combo) + for p in params: + d.update(p.iteritems()) + r.append((','.join(names), d)) + return r |