-
Notifications
You must be signed in to change notification settings - Fork 3
/
tests.py
executable file
·404 lines (286 loc) · 16.4 KB
/
tests.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/usr/bin/env python
import os
import unittest
from nose.plugins import PluginTester
from nose.plugins.collect import CollectOnly
from nose.plugins.skip import Skip
from nose.plugins.xunit import Xunit
from nose.tools import assert_in, eq_
try:
from nose.tools import assert_raises_regex
except ImportError:
# For python 2.7
from nose.tools import assert_raises_regexp as assert_raises_regex
from nosedep import NoseDep, depends
class NoseDepPluginTester(PluginTester, unittest.TestCase):
activate = '--with-nosedep'
args = ['-v']
plugins = [NoseDep(), Skip()]
# This is a bit odd. If using the absolute path on Windows
# it tries to import module 'C' due to the ':' , if only relative path
# it splits on the '.' before the file extension.
# So I only got it to work with a relative path appended with a ':'.
suitepath = None
def makeSuite(self):
raise Exception("Should not be used currently")
def check(self, expect):
results = len(expect)
for line in self.output:
if expect:
self.assertEqual(expect.pop(0), line.strip())
# Verify that we ran the expected number of tests
assert_in("Ran {} test{} in".format(results, 's' if results > 1 else ''),
str(self.output))
class TestUndecoratedFunctional(NoseDepPluginTester):
suitepath = "test_scripts/undecorated_functional_tests.py:"
def runTest(self):
self.check(['test_scripts.undecorated_functional_tests.test_x ... ok',
'test_scripts.undecorated_functional_tests.test_y ... ERROR'])
class TestUndecoratedFunctionalXunit(NoseDepPluginTester):
# Initially there was a bug causing Xunit to fail in
# combination with nosedep. This test verifies that it works.
args = ['-v', '--with-xunit']
plugins = [NoseDep(), Xunit()]
suitepath = "test_scripts/undecorated_functional_tests.py:"
def setUp(self):
if os.path.isfile('nosetests.xml'):
os.remove('nosetests.xml')
super(TestUndecoratedFunctionalXunit, self).setUp()
def tearDown(self):
with open('nosetests.xml') as xml:
assert_in('tests="2"', xml.read())
super(TestUndecoratedFunctionalXunit, self).tearDown()
def runTest(self):
self.check(['test_scripts.undecorated_functional_tests.test_x ... ok',
'test_scripts.undecorated_functional_tests.test_y ... ERROR'])
class TestDecoratedClass(NoseDepPluginTester):
suitepath = "test_scripts/decorated_class.py"
def setUp(self):
try:
super(TestDecoratedClass, self).setUp()
except ValueError as e:
eq_(str(e), "depends decorator can only be used on functions or methods")
class TestSimple(NoseDepPluginTester):
suitepath = "test_scripts/simple.py"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple.TestSimple) ... FAIL',
'test_simple_ok (test_scripts.simple.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple.TestSimple) ... SKIP'])
class TestSimpleDecorated(NoseDepPluginTester):
suitepath = "test_scripts/simple_decorated.py"
def runTest(self):
self.check(['test_simple_decorated_ok (test_scripts.simple_decorated.TestSimpleDecorated) ... ok',
'test_simple_decorated_fail (test_scripts.simple_decorated.TestSimpleDecorated) ... FAIL',
'test_simple_decorated_skip (test_scripts.simple_decorated.TestSimpleDecorated) ... SKIP:'
' Required test \'test_simple_decorated_fail\' FAILED'])
class TestSimpleCollect(NoseDepPluginTester):
args = ['-v', '--collect-only']
plugins = [NoseDep(), CollectOnly()]
suitepath = "test_scripts/simple.py"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple.TestSimple) ... ok',
'test_simple_ok (test_scripts.simple.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple.TestSimple) ... ok'])
class TestSimpleSetupFailNoNosedep(NoseDepPluginTester):
"""Setup failure should not generate error in collect mode without nosedep
(verify expectation)
"""
activate = '-v'
args = ['--collect-only']
plugins = [CollectOnly()]
suitepath = "test_scripts/simple_setup_fail.py"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple_setup_fail.TestSimple) ... ok',
'test_simple_ok (test_scripts.simple_setup_fail.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple_setup_fail.TestSimple) ... ok'])
class TestSimpleSetupFailCollect(NoseDepPluginTester):
"""Setup failure should not generate error in collect mode with nosedep"""
args = ['-v', '--collect-only']
plugins = [NoseDep(), CollectOnly()]
suitepath = "test_scripts/simple_setup_fail.py"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple_setup_fail.TestSimple) ... ok',
'test_simple_ok (test_scripts.simple_setup_fail.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple_setup_fail.TestSimple) ... ok'])
class TestSimpleSetupFail(NoseDepPluginTester):
"""Setup failure should generate error"""
suitepath = "test_scripts/simple_setup_fail.py"
def runTest(self):
eq_('ERROR\n', list(self.output)[0])
class TestSimpleDecoratedCollect(NoseDepPluginTester):
args = ['-v', '--collect-only']
plugins = [NoseDep(), CollectOnly()]
suitepath = "test_scripts/simple_decorated.py"
def runTest(self):
self.check(['test_simple_decorated_fail (test_scripts.simple_decorated.TestSimpleDecorated) ... ok',
'test_simple_decorated_ok (test_scripts.simple_decorated.TestSimpleDecorated) ... ok',
'test_simple_decorated_skip (test_scripts.simple_decorated.TestSimpleDecorated) ... ok'])
class TestSimpleColon(NoseDepPluginTester):
suitepath = "test_scripts/simple.py:"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple.TestSimple) ... FAIL',
'test_simple_ok (test_scripts.simple.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple.TestSimple) ... SKIP'])
class TestSimpleClass(NoseDepPluginTester):
suitepath = "test_scripts/simple.py:TestSimple"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple.TestSimple) ... FAIL',
'test_simple_ok (test_scripts.simple.TestSimple) ... ok',
'test_simple_skip (test_scripts.simple.TestSimple) ... SKIP'])
class TestSimpleClassTestOK(NoseDepPluginTester):
suitepath = "test_scripts/simple.py:TestSimple.test_simple_ok"
def runTest(self):
self.check(['test_simple_ok (test_scripts.simple.TestSimple) ... ok'])
class TestSimpleClassTestSKIP(NoseDepPluginTester):
suitepath = "test_scripts/simple.py:TestSimple.test_simple_skip"
def runTest(self):
self.check(['test_simple_skip (test_scripts.simple.TestSimple) ... SKIP'])
class TestSimpleClassTestFAIL(NoseDepPluginTester):
suitepath = "test_scripts/simple.py:TestSimple.test_simple_fail"
def runTest(self):
self.check(['test_simple_fail (test_scripts.simple.TestSimple) ... FAIL'])
class TestDecoratedFunctionalAll(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_tests.py:"
def runTest(self):
self.check(['test_scripts.decorated_functional_tests.test_dft_f ... ok',
'test_scripts.decorated_functional_tests.test_dft_b ... ok',
'test_scripts.decorated_functional_tests.test_dft_e ... ok',
'test_scripts.decorated_functional_tests.test_dft_a ... ok',
'test_scripts.decorated_functional_tests.test_dft_c ... ok',
'test_scripts.decorated_functional_tests.test_dft_d ... ok'])
class TestDecoratedFunctionalDepSkip(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_dep_skip.py:"
def runTest(self):
self.check(['test_scripts.decorated_functional_dep_skip.test_dfds_c ... ok',
'test_scripts.decorated_functional_dep_skip.test_dfds_b ... FAIL',
'test_scripts.decorated_functional_dep_skip.test_dfds_e ... SKIP: skippington',
'test_scripts.decorated_functional_dep_skip.test_dfds_a ... SKIP:'
' Required test \'test_dfds_b\' FAILED',
'test_scripts.decorated_functional_dep_skip.test_dfds_d ... ERROR',
'test_scripts.decorated_functional_dep_skip.test_dfds_f ... SKIP:'
' Required test \'test_dfds_e\' SKIPPED'])
class TestDecoratedFunctionalFunc(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_func.py:"
def runTest(self):
self.check(['test_scripts.decorated_functional_func.test_dff_b ... ok',
'test_scripts.decorated_functional_func.test_dff_a ... ok',
'test_scripts.decorated_functional_func.test_dff_c ... ok'])
class TestDecoratedFunctionalMult(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_mult.py:"
def runTest(self):
self.check(['test_scripts.decorated_functional_mult.test_dfm_b ... ok',
'test_scripts.decorated_functional_mult.test_dfm_c ... ok',
'test_scripts.decorated_functional_mult.test_dfm_a ... ok'])
class TestDecoratedFunctionalSpecificDep(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_tests.py:test_dft_d"
def runTest(self):
self.check(['test_scripts.decorated_functional_tests.test_dft_b ... ok',
'test_scripts.decorated_functional_tests.test_dft_a ... ok',
'test_scripts.decorated_functional_tests.test_dft_d ... ok'])
class TestDecoratedFunctionalSpecificNoDep(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_tests.py:test_dft_f"
def runTest(self):
self.check(['test_scripts.decorated_functional_tests.test_dft_f ... ok'])
class TestDecoratedFunctionalSpecificC(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_tests.py:test_dft_c"
def runTest(self):
self.check(['test_scripts.decorated_functional_tests.test_dft_b ... ok',
'test_scripts.decorated_functional_tests.test_dft_c ... ok'])
class TestUndecoratedMethod(NoseDepPluginTester):
suitepath = "test_scripts/undecorated_method_tests.py:"
def runTest(self):
self.check(['test_scripts.undecorated_method_tests.TestNoseUndecoratedMethod.test_c_a ... ok',
'test_scripts.undecorated_method_tests.TestNoseUndecoratedMethod.test_c_b ... ok'])
class TestDecoratedMethod(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_tests.py:"
def runTest(self):
self.check(['test_scripts.decorated_method_tests.TestNoseDecoratedMethod.test_cd_a ... ok',
'test_scripts.decorated_method_tests.TestNoseDecoratedMethod.test_cd_c ... ok',
'test_scripts.decorated_method_tests.TestNoseDecoratedMethod.test_cd_b ... ok'])
class TestDecoratedSubclass(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_subclass.py:"
def runTest(self):
self.check(['test_scripts.decorated_method_subclass.TestNoseDecoratedChild.test_cd_a ... ok',
'test_scripts.decorated_method_subclass.TestNoseDecoratedChild.test_cd_c ... ok',
'test_scripts.decorated_method_subclass.TestNoseDecoratedChild.test_cd_b ... ok'])
class TestDecoratedSubclassTestCase(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_subclass_testcase.py:"
def runTest(self):
self.check(
['test_cdt_a (test_scripts.decorated_method_subclass_testcase.TestNoseDecoratedTestCaseChild) ... ok',
'test_cdt_c (test_scripts.decorated_method_subclass_testcase.TestNoseDecoratedTestCaseChild) ... ok',
'test_cdt_b (test_scripts.decorated_method_subclass_testcase.TestNoseDecoratedTestCaseChild) ... ok'])
class TestDecoratedMethodSpecificNoDep(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_tests.py:TestNoseDecoratedMethod.test_cd_a"
def runTest(self):
self.check(['test_scripts.decorated_method_tests.TestNoseDecoratedMethod.test_cd_a ... ok'])
class TestDecoratedMethodSpecificDep(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_tests.py:TestNoseDecoratedMethod.test_cd_b"
def runTest(self):
self.check(['test_scripts.decorated_method_tests.TestNoseDecoratedMethod.test_cd_b ... ok'])
class TestDecoratedFunctionalPriority(NoseDepPluginTester):
suitepath = "test_scripts/decorated_functional_priority.py:"
def runTest(self):
self.check(['test_scripts.decorated_functional_priority.test_dfp_b ... ok',
'test_scripts.decorated_functional_priority.test_dfp_a ... ok',
'test_scripts.decorated_functional_priority.test_dfp_f ... ok',
'test_scripts.decorated_functional_priority.test_dfp_g ... ok',
'test_scripts.decorated_functional_priority.test_dfp_h ... ok',
'test_scripts.decorated_functional_priority.test_dfp_i ... ok',
'test_scripts.decorated_functional_priority.test_dfp_d ... ok',
'test_scripts.decorated_functional_priority.test_dfp_e ... ok',
'test_scripts.decorated_functional_priority.test_dfp_c ... ok'])
class TestDecoratedMethodPriority(NoseDepPluginTester):
suitepath = "test_scripts/decorated_method_priority.py:"
def runTest(self):
self.check(['test_scripts.decorated_method_priority.TestMP.test_dmp_b ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_c ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_a ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_f ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_g ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_h ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_i ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_d ... ok',
'test_scripts.decorated_method_priority.TestMP.test_dmp_e ... ok'])
class TestDecoratedDirectory2Levels(NoseDepPluginTester):
suitepath = "test_scripts/dir_test/dir_test_2:"
def runTest(self):
self.check(['test_04 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_03 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_02 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_01 (dir_test_2.dir_tests.DisplayNodeList) ... ok'])
class TestDecoratedDirectoryDirect(NoseDepPluginTester):
suitepath = "test_scripts/dir_test/dir_test_2/dir_tests.py:"
def runTest(self):
self.check(['test_04 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_03 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_02 (dir_test_2.dir_tests.DisplayNodeList) ... ok',
'test_01 (dir_test_2.dir_tests.DisplayNodeList) ... ok'])
class TestDependsNoArgument(NoseDepPluginTester):
def test_no_args(self):
pass
def makeSuite(self):
with assert_raises_regex(ValueError, r'depends decorator needs at least one argument'):
class TC(unittest.TestCase):
@depends()
def run_test_no_args(self):
pass
return [TC('run_test_no_args')]
class TestDependsSelf(NoseDepPluginTester):
def test_self_dep(self):
pass
def makeSuite(self):
with assert_raises_regex(ValueError, r'Test \'run_test_self_dep\' cannot depend on itself'):
class TC(unittest.TestCase):
@depends(after='run_test_self_dep')
def run_test_self_dep(self):
pass
return [TC('run_test_self_dep')]
if __name__ == '__main__':
unittest.main()
# To test:
# * Multiple specifiers
# * Test both with file and __main__ specifying prefix
# In the tested application use of __main__. tests all tests while filename prefix works.
# FIXME: Dependencies are global and not qualified. Would probably be best if
# it contained unique qualifiers. (now we can't use the same test name in different files)