~testing-cabal/ubuntu/natty/python-testscenarios/daily-build-packaging

« back to all changes in this revision

Viewing changes to lib/testscenarios/tests/test_scenarios.py

  • Committer: Robert Collins
  • Date: 2010-10-12 06:57:23 UTC
  • mfrom: (17.1.3 658044-multiply)
  • Revision ID: robertc@robertcollins.net-20101012065723-13z174op8al4s6zn
Merge a tweaked version of Martins load_tests and multiply_scenarios patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#  dependency injection ('scenarios') by tests.
3
3
#
4
4
# Copyright (c) 2009, Robert Collins <robertc@robertcollins.net>
 
5
# Copyright (c) 2010 Martin Pool <mbp@sourcefrog.net>
5
6
6
7
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
7
8
# license at the users choice. A copy of both licenses are available in the
21
22
    apply_scenario,
22
23
    apply_scenarios,
23
24
    generate_scenarios,
 
25
    load_tests_apply_scenarios,
 
26
    multiply_scenarios,
24
27
    )
25
28
import testtools
26
29
from testtools.tests.helpers import LoggingResult
171
174
        tests = list(apply_scenarios(ReferenceTest.scenarios, test))
172
175
        self.assertEqual([('demo', {})], ReferenceTest.scenarios)
173
176
        self.assertEqual(ReferenceTest.scenarios, tests[0].scenarios)
 
177
 
 
178
 
 
179
class TestLoadTests(testtools.TestCase):
 
180
 
 
181
    class SampleTest(unittest.TestCase):
 
182
        def test_nothing(self): 
 
183
            pass
 
184
        scenarios = [
 
185
            ('a', {}),
 
186
            ('b', {}),
 
187
            ]
 
188
 
 
189
    def test_load_tests_apply_scenarios(self):
 
190
        suite = load_tests_apply_scenarios(
 
191
            unittest.TestLoader(),
 
192
            [self.SampleTest('test_nothing')],
 
193
            None)
 
194
        result_tests = list(testtools.iterate_tests(suite))
 
195
        self.assertEquals(
 
196
            2,
 
197
            len(result_tests),
 
198
            result_tests)
 
199
 
 
200
    def test_load_tests_apply_scenarios_old_style(self):
 
201
        """Call load_tests in the way used by bzr."""
 
202
        suite = load_tests_apply_scenarios(
 
203
            [self.SampleTest('test_nothing')],
 
204
            self.__class__.__module__,
 
205
            unittest.TestLoader(),
 
206
            )
 
207
        result_tests = list(testtools.iterate_tests(suite))
 
208
        self.assertEquals(
 
209
            2,
 
210
            len(result_tests),
 
211
            result_tests)
 
212
 
 
213
 
 
214
class TestMultiplyScenarios(testtools.TestCase):
 
215
 
 
216
    def test_multiply_scenarios(self):
 
217
        def factory(name):
 
218
            for i in 'ab':
 
219
                yield i, {name: i}
 
220
        scenarios = multiply_scenarios(factory('p'), factory('q'))
 
221
        self.assertEqual([
 
222
            ('a,a', dict(p='a', q='a')),
 
223
            ('a,b', dict(p='a', q='b')),
 
224
            ('b,a', dict(p='b', q='a')),
 
225
            ('b,b', dict(p='b', q='b')),
 
226
            ],
 
227
            scenarios)
 
228
 
 
229
    def test_multiply_many_scenarios(self):
 
230
        def factory(name):
 
231
            for i in 'abc':
 
232
                yield i, {name: i}
 
233
        scenarios = multiply_scenarios(factory('p'), factory('q'),
 
234
            factory('r'), factory('t'))
 
235
        self.assertEqual(
 
236
            3**4,
 
237
            len(scenarios),
 
238
            scenarios)
 
239
        self.assertEqual(
 
240
            'a,a,a,a',
 
241
            scenarios[0][0])