~jayvdb/testscenarios/0.4

« back to all changes in this revision

Viewing changes to lib/testscenarios/tests/test_testcase.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:
17
17
import unittest
18
18
 
19
19
import testscenarios
20
 
import testtools
21
20
from testtools.tests.helpers import LoggingResult
22
21
 
23
22
 
24
 
class TestTestWithScenarios(testtools.TestCase):
25
 
 
26
 
    scenarios = testscenarios.scenarios.per_module_scenarios(
27
 
        'impl', (('unittest', 'unittest'), ('unittest2', 'unittest2')))
28
 
 
29
 
    @property
30
 
    def Implementation(self):
31
 
        if isinstance(self.impl, tuple):
32
 
            self.skipTest('import failed - module not installed?')
33
 
        class Implementation(testscenarios.WithScenarios, self.impl.TestCase):
34
 
            pass
35
 
        return Implementation
 
23
class TestTestWithScenarios(unittest.TestCase):
36
24
 
37
25
    def test_no_scenarios_no_error(self):
38
 
        class ReferenceTest(self.Implementation):
 
26
        class ReferenceTest(testscenarios.TestWithScenarios):
39
27
            def test_pass(self):
40
28
                pass
41
29
        test = ReferenceTest("test_pass")
45
33
        self.assertEqual(1, result.testsRun)
46
34
 
47
35
    def test_with_one_scenario_one_run(self):
48
 
        class ReferenceTest(self.Implementation):
 
36
        class ReferenceTest(testscenarios.TestWithScenarios):
49
37
            scenarios = [('demo', {})]
50
38
            def test_pass(self):
51
39
                pass
60
48
            log[0][1].id())
61
49
 
62
50
    def test_with_two_scenarios_two_run(self):
63
 
        class ReferenceTest(self.Implementation):
 
51
        class ReferenceTest(testscenarios.TestWithScenarios):
64
52
            scenarios = [('1', {}), ('2', {})]
65
53
            def test_pass(self):
66
54
                pass
78
66
            log[4][1].id())
79
67
 
80
68
    def test_attributes_set(self):
81
 
        class ReferenceTest(self.Implementation):
 
69
        class ReferenceTest(testscenarios.TestWithScenarios):
82
70
            scenarios = [
83
71
                ('1', {'foo': 1, 'bar': 2}),
84
72
                ('2', {'foo': 2, 'bar': 4})]
92
80
        self.assertEqual(2, result.testsRun)
93
81
 
94
82
    def test_scenarios_attribute_cleared(self):
95
 
        class ReferenceTest(self.Implementation):
 
83
        class ReferenceTest(testscenarios.TestWithScenarios):
96
84
            scenarios = [
97
85
                ('1', {'foo': 1, 'bar': 2}),
98
86
                ('2', {'foo': 2, 'bar': 4})]
109
97
        self.assertEqual(None, log[4][1].scenarios)
110
98
 
111
99
    def test_countTestCases_no_scenarios(self):
112
 
        class ReferenceTest(self.Implementation):
 
100
        class ReferenceTest(testscenarios.TestWithScenarios):
113
101
            def test_check_foo(self):
114
102
                pass
115
103
        test = ReferenceTest("test_check_foo")
116
104
        self.assertEqual(1, test.countTestCases())
117
105
 
118
106
    def test_countTestCases_empty_scenarios(self):
119
 
        class ReferenceTest(self.Implementation):
 
107
        class ReferenceTest(testscenarios.TestWithScenarios):
120
108
            scenarios = []
121
109
            def test_check_foo(self):
122
110
                pass
124
112
        self.assertEqual(1, test.countTestCases())
125
113
 
126
114
    def test_countTestCases_1_scenarios(self):
127
 
        class ReferenceTest(self.Implementation):
 
115
        class ReferenceTest(testscenarios.TestWithScenarios):
128
116
            scenarios = [('1', {'foo': 1, 'bar': 2})]
129
117
            def test_check_foo(self):
130
118
                pass
132
120
        self.assertEqual(1, test.countTestCases())
133
121
 
134
122
    def test_countTestCases_2_scenarios(self):
135
 
        class ReferenceTest(self.Implementation):
 
123
        class ReferenceTest(testscenarios.TestWithScenarios):
136
124
            scenarios = [
137
125
                ('1', {'foo': 1, 'bar': 2}),
138
126
                ('2', {'foo': 2, 'bar': 4})]
143
131
 
144
132
    def test_debug_2_scenarios(self):
145
133
        log = []
146
 
        class ReferenceTest(self.Implementation):
 
134
        class ReferenceTest(testscenarios.TestWithScenarios):
147
135
            scenarios = [
148
136
                ('1', {'foo': 1, 'bar': 2}),
149
137
                ('2', {'foo': 2, 'bar': 4})]