diff options
author | Robert Collins <robertc@robertcollins.net> | 2010-10-12 19:57:23 +1300 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2010-10-12 19:57:23 +1300 |
commit | e1339ea008f571b21ad13c5d69926ed6d66bb290 (patch) | |
tree | b4b75f7b8ceb5626cbd9df75872f7bed1e7fded9 /lib/testscenarios/tests | |
parent | 553e0a70a190ab8fa81348532fb32b118ea6592f (diff) | |
parent | 977abd578ffa376be31e6382d4b0baab1c54ccef (diff) | |
download | testscenarios-e1339ea008f571b21ad13c5d69926ed6d66bb290.tar.gz |
Merge a tweaked version of Martins load_tests and multiply_scenarios patch.
Diffstat (limited to 'lib/testscenarios/tests')
-rw-r--r-- | lib/testscenarios/tests/test_scenarios.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/testscenarios/tests/test_scenarios.py b/lib/testscenarios/tests/test_scenarios.py index 4c80150..063df51 100644 --- a/lib/testscenarios/tests/test_scenarios.py +++ b/lib/testscenarios/tests/test_scenarios.py @@ -2,6 +2,7 @@ # dependency injection ('scenarios') by tests. # # Copyright (c) 2009, Robert Collins <robertc@robertcollins.net> +# Copyright (c) 2010 Martin Pool <mbp@sourcefrog.net> # # Licensed under either the Apache License, Version 2.0 or the BSD 3-clause # license at the users choice. A copy of both licenses are available in the @@ -21,6 +22,8 @@ from testscenarios.scenarios import ( apply_scenario, apply_scenarios, generate_scenarios, + load_tests_apply_scenarios, + multiply_scenarios, ) import testtools from testtools.tests.helpers import LoggingResult @@ -171,3 +174,68 @@ class TestApplyScenarios(testtools.TestCase): tests = list(apply_scenarios(ReferenceTest.scenarios, test)) self.assertEqual([('demo', {})], ReferenceTest.scenarios) self.assertEqual(ReferenceTest.scenarios, tests[0].scenarios) + + +class TestLoadTests(testtools.TestCase): + + class SampleTest(unittest.TestCase): + def test_nothing(self): + pass + scenarios = [ + ('a', {}), + ('b', {}), + ] + + def test_load_tests_apply_scenarios(self): + suite = load_tests_apply_scenarios( + unittest.TestLoader(), + [self.SampleTest('test_nothing')], + None) + result_tests = list(testtools.iterate_tests(suite)) + self.assertEquals( + 2, + len(result_tests), + result_tests) + + def test_load_tests_apply_scenarios_old_style(self): + """Call load_tests in the way used by bzr.""" + suite = load_tests_apply_scenarios( + [self.SampleTest('test_nothing')], + self.__class__.__module__, + unittest.TestLoader(), + ) + result_tests = list(testtools.iterate_tests(suite)) + self.assertEquals( + 2, + len(result_tests), + result_tests) + + +class TestMultiplyScenarios(testtools.TestCase): + + def test_multiply_scenarios(self): + def factory(name): + for i in 'ab': + yield i, {name: i} + scenarios = multiply_scenarios(factory('p'), factory('q')) + self.assertEqual([ + ('a,a', dict(p='a', q='a')), + ('a,b', dict(p='a', q='b')), + ('b,a', dict(p='b', q='a')), + ('b,b', dict(p='b', q='b')), + ], + scenarios) + + def test_multiply_many_scenarios(self): + def factory(name): + for i in 'abc': + yield i, {name: i} + scenarios = multiply_scenarios(factory('p'), factory('q'), + factory('r'), factory('t')) + self.assertEqual( + 3**4, + len(scenarios), + scenarios) + self.assertEqual( + 'a,a,a,a', + scenarios[0][0]) |