-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_arglinker.py
120 lines (85 loc) · 2.85 KB
/
test_arglinker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
import unittest
import arglinker
TestCase = arglinker.add_test_linker(unittest.TestCase)
class Test_fixture_evaluation(TestCase):
# fixtures with automatic fixture injection
def one(self):
return 1
def two(self, one):
return one + one
def three(self, two, one):
return one + two
def five(self, three, two):
return three + two
def ten(self, five):
return five + five
# tests
def test_fixture_method_parameters_are_auto_injected(self, ten):
self.assertEqual(10, ten)
def test_fixture_methods_are_simple_methods(self):
self.assertEqual(10, self.ten(five=5))
class Test_fixture_sharing(TestCase):
# fixtures
def value(self):
return object()
def implicit_value(self, value):
return value
# test
def test_fixtures_are_evaluated_only_once_per_tests(
self, value, implicit_value
):
# calling value twice returns different objects
self.assertIsNot(self.value(), self.value())
self.assertIsNot(value, self.value())
# yet implicit_value is the same as value
self.assertIs(value, implicit_value)
class Test_invalid_tests_and_fixtures(TestCase):
# fixtures
def value(self):
return 1
@property
def property_value(self):
return 'property as fixture will not work'
# tests
@unittest.expectedFailure
def test_property_as_fixture_does_not_work(self, property_value):
pass
@classmethod
@unittest.expectedFailure
def test_classmethod_as_test_does_not_work(cls, value):
pass
@staticmethod
@unittest.expectedFailure
def test_staticmethod_as_test_does_not_work(value):
pass
class Test_unittest_test_decorators(TestCase):
# fixtures
def dummy_fixture(self):
return 'Dummy'
def bad_fixture(self):
raise IOError('failure in fixture')
# tests
@unittest.skip('skipped')
def test_skip(self, dummy_fixture):
self.fail('not skipped')
@unittest.skipIf(True, "unconditionally skipped")
def test_skipIf(self, dummy_fixture):
self.fail('not skipped')
@unittest.expectedFailure
def test_expectedFailure(self, dummy_fixture):
self.fail('this should be an x failure not an F failure')
@unittest.skip('skipped')
def test_skip_bad(self, bad_fixture):
self.fail('not skipped')
@unittest.skipIf(True, "unconditionally skipped")
def test_skipIf_bad(self, bad_fixture):
self.fail('not skipped')
@unittest.expectedFailure
def test_expectedFailure_bad(self, bad_fixture):
self.fail('this should be an x failure not an F failure')
if __name__ == '__main__':
unittest.main()