~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:45:22 UTC
  • mfrom: (18.2.1 testcase-mixin)
  • Revision ID: robertc@robertcollins.net-20120404104522-7fho5wxapc2uqmw5
* ``TestWithScenarios`` is now backed by a mixin - WithScenarios - which can be
  mixed into different unittest implementations more cleanly (e.g. unittest2).
  (James Polley, 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
20
21
from testtools.tests.helpers import LoggingResult
21
22
 
22
23
 
23
 
class TestTestWithScenarios(unittest.TestCase):
 
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
24
36
 
25
37
    def test_no_scenarios_no_error(self):
26
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
38
        class ReferenceTest(self.Implementation):
27
39
            def test_pass(self):
28
40
                pass
29
41
        test = ReferenceTest("test_pass")
33
45
        self.assertEqual(1, result.testsRun)
34
46
 
35
47
    def test_with_one_scenario_one_run(self):
36
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
48
        class ReferenceTest(self.Implementation):
37
49
            scenarios = [('demo', {})]
38
50
            def test_pass(self):
39
51
                pass
48
60
            log[0][1].id())
49
61
 
50
62
    def test_with_two_scenarios_two_run(self):
51
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
63
        class ReferenceTest(self.Implementation):
52
64
            scenarios = [('1', {}), ('2', {})]
53
65
            def test_pass(self):
54
66
                pass
66
78
            log[4][1].id())
67
79
 
68
80
    def test_attributes_set(self):
69
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
81
        class ReferenceTest(self.Implementation):
70
82
            scenarios = [
71
83
                ('1', {'foo': 1, 'bar': 2}),
72
84
                ('2', {'foo': 2, 'bar': 4})]
80
92
        self.assertEqual(2, result.testsRun)
81
93
 
82
94
    def test_scenarios_attribute_cleared(self):
83
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
95
        class ReferenceTest(self.Implementation):
84
96
            scenarios = [
85
97
                ('1', {'foo': 1, 'bar': 2}),
86
98
                ('2', {'foo': 2, 'bar': 4})]
97
109
        self.assertEqual(None, log[4][1].scenarios)
98
110
 
99
111
    def test_countTestCases_no_scenarios(self):
100
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
112
        class ReferenceTest(self.Implementation):
101
113
            def test_check_foo(self):
102
114
                pass
103
115
        test = ReferenceTest("test_check_foo")
104
116
        self.assertEqual(1, test.countTestCases())
105
117
 
106
118
    def test_countTestCases_empty_scenarios(self):
107
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
119
        class ReferenceTest(self.Implementation):
108
120
            scenarios = []
109
121
            def test_check_foo(self):
110
122
                pass
112
124
        self.assertEqual(1, test.countTestCases())
113
125
 
114
126
    def test_countTestCases_1_scenarios(self):
115
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
127
        class ReferenceTest(self.Implementation):
116
128
            scenarios = [('1', {'foo': 1, 'bar': 2})]
117
129
            def test_check_foo(self):
118
130
                pass
120
132
        self.assertEqual(1, test.countTestCases())
121
133
 
122
134
    def test_countTestCases_2_scenarios(self):
123
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
135
        class ReferenceTest(self.Implementation):
124
136
            scenarios = [
125
137
                ('1', {'foo': 1, 'bar': 2}),
126
138
                ('2', {'foo': 2, 'bar': 4})]
131
143
 
132
144
    def test_debug_2_scenarios(self):
133
145
        log = []
134
 
        class ReferenceTest(testscenarios.TestWithScenarios):
 
146
        class ReferenceTest(self.Implementation):
135
147
            scenarios = [
136
148
                ('1', {'foo': 1, 'bar': 2}),
137
149
                ('2', {'foo': 2, 'bar': 4})]