~testtools-committers/testscenarios/trunk

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2012-04-04 10:02:46 UTC
  • mfrom: (18.1.1 module-scenarios)
  • Revision ID: robertc@robertcollins.net-20120404100246-n6ap8h2x14uxg144
* New function ``per_module_scenarios`` for tests that should be applied across 
  multiple modules providing the same interface, some of which may not be 
  available at run time.  (Martin Pool, Robert Collins)

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
# Copyright (c) 2010, 2011 Martin Pool <mbp@sourcefrog.net>
6
6
7
7
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
8
8
# license at the users choice. A copy of both licenses are available in the
239
239
        self.assertEqual(
240
240
            'a,a,a,a',
241
241
            scenarios[0][0])
 
242
 
 
243
 
 
244
class TestPerModuleScenarios(testtools.TestCase):
 
245
 
 
246
    def test_per_module_scenarios(self):
 
247
        """Generate scenarios for available modules"""
 
248
        s = testscenarios.scenarios.per_module_scenarios(
 
249
            'the_module', [
 
250
                ('Python', 'testscenarios'),
 
251
                ('unittest', 'unittest'),
 
252
                ('nonexistent', 'nonexistent'),
 
253
                ])
 
254
        self.assertEqual('nonexistent', s[-1][0])
 
255
        self.assertIsInstance(s[-1][1]['the_module'], tuple)
 
256
        s[-1][1]['the_module'] = None
 
257
        self.assertEqual(s, [
 
258
            ('Python', {'the_module': testscenarios}),
 
259
            ('unittest', {'the_module': unittest}),
 
260
            ('nonexistent', {'the_module': None}),
 
261
            ])