summaryrefslogtreecommitdiff
path: root/lib/testscenarios/scenarios.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/testscenarios/scenarios.py')
-rw-r--r--lib/testscenarios/scenarios.py25
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