-
Notifications
You must be signed in to change notification settings - Fork 10
/
tests.py
266 lines (185 loc) · 8.47 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
import os
import unittest
from nose.plugins import PluginTester
from nose_exclude import NoseExclude
class TestNoseExcludeDirs_Relative_Args(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using relative paths passed
on the commandline via --exclude-dir
"""
activate = "--exclude-dir=test_dirs/build"
args = ['--exclude-dir=test_dirs/test_not_me']
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirs_Absolute_Args(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using absolute paths passed
on the commandline via --exclude-dir
"""
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def __init__(self, *args, **kwargs):
self.activate = "--exclude-dir=%s" % \
os.path.join(self.suitepath, 'build')
arg_path = os.path.join(self.suitepath, 'test_not_me')
self.args = ['--exclude-dir=%s' % arg_path]
super(TestNoseExcludeDirs_Absolute_Args, self).__init__(*args, **kwargs)
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirs_Relative_Args_File(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using relative paths passed
by file using --exclude-dir-file
"""
activate = "--exclude-dir-file=test_dirs/exclude_dirs.txt"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirs_Relative_Args_Mixed(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using paths passed
by file and commandline
"""
activate = "--exclude-dir-file=test_dirs/exclude_dirs2.txt"
args = ["--exclude-dir=test_dirs/test_not_me"]
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeEnvVariables(PluginTester, unittest.TestCase):
"""Test nose-exclude's use of environment variables"""
#args = ['--exclude-dir=test_dirs/test_not_me']
activate = "-v"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
env = {'NOSE_EXCLUDE_DIRS': 'test_dirs/build;test_dirs/test_not_me'}
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirsEnvFile(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using relative paths passed
by file specified by environment variable
"""
activate = "-v"
plugins = [NoseExclude()]
env = {'NOSE_EXCLUDE_DIRS_FILE': 'test_dirs/exclude_dirs.txt'}
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirs_Arg_Does_Not_Exist(PluginTester, unittest.TestCase):
"""Test nose-exclude directories for a directory that doesn't exist.
"""
activate = "--exclude-dir=test_dirs/build"
args = ["--exclude-dir=test_dirs/test_not_me \n --exclude-dir=test_dirs/test_i_dont_exist"]
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirsNoseWorkingDir(PluginTester, unittest.TestCase):
"""Test nose-exclude directories with Nose's working directory."""
activate = "--exclude-dir=test_not_me"
args = ["--where=test_dirs"]
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def tearDown(self):
# Nose changes cwd to config.workingDir, need to reset it
import os
os.chdir(os.path.join(os.getcwd(), os.path.pardir))
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeTest(PluginTester, unittest.TestCase):
"""Test nose-exclude a single test"""
activate = "--exclude-test=test_dirs.unittest.tests.UnitTests.test_a"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_test_excluded(self):
assert 'Ran 2 tests' in self.output
class TestNoseExcludeTestNegative(PluginTester, unittest.TestCase):
"""Test nose-exclude a test that does not exist"""
activate = "--exclude-test=test_dirs.unittest.tests.UnitTests.does_not_exist"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_test_excluded_negative(self):
assert 'Ran 3 tests' in self.output
class TestNoseExcludeTestsEnvVariables(PluginTester, unittest.TestCase):
"""Test nose-exclude's use of environment variables"""
activate = "-v"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
env = {'NOSE_EXCLUDE_TESTS':
'test_dirs.unittest.tests.UnitTests.test_a;'
'test_dirs.unittest.tests.test_c'
}
def test_test_excluded(self):
assert 'Ran 1 test' in self.output
class TestNoseExcludeMultipleTest(PluginTester, unittest.TestCase):
"""Test nose-exclude multiple tests"""
activate = "--exclude-test=test_dirs.unittest.tests.UnitTests.test_a"
args = [
"--exclude-test=test_dirs.unittest.tests.UnitTests.test_b",
"--exclude-test=test_dirs.unittest.tests.test_c"
]
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_tests_excluded(self):
assert 'Ran 0 tests' in self.output
class TestNoseExcludeTestViaFile(PluginTester, unittest.TestCase):
"""Test nose-exclude tests with a file"""
activate = "--exclude-test-file=test_dirs/exclude_tests.txt"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_tests_excluded(self):
assert 'Ran 1 test' in self.output
class TestNoseExcludeDirAndTests(PluginTester, unittest.TestCase):
"""Test nose-exclude tests by specifying dirs and tests"""
activate = "--exclude-test=test_dirs.unittest.tests.UnitTests.test_a"
args = [
"--exclude-dir=test_dirs/build",
"--exclude-dir=test_dirs/build2",
"--exclude-dir=test_dirs/fish",
"--exclude-dir=test_dirs/test_not_me",
"--exclude-dir=test_dirs/test_yes",
"--exclude-dir=test_dirs/test_yes2",
]
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_tests_excluded(self):
assert 'Ran 2 tests' in self.output
class TestNoseExcludeTestClass(PluginTester, unittest.TestCase):
"""Test nose-exclude tests by class"""
activate = "--exclude-test=test_dirs.unittest.tests.UnitTests"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_tests_excluded(self):
assert 'Ran 1 test' in self.output
class TestNoseExcludeTestFunction(PluginTester, unittest.TestCase):
"""Test nose-exclude tests by function"""
activate = "--exclude-test=test_dirs.unittest.tests.test_c"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_tests_excluded(self):
assert 'Ran 2 tests' in self.output
class TestNoseExcludeTestModule(PluginTester, unittest.TestCase):
"""Test nose-exclude tests by module"""
activate = "--exclude-test=test_dirs.unittest.test"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def test_tests_excluded(self):
assert 'Ran 3 tests' in self.output
class TestNoseDoesNotExcludeTestClass(PluginTester, unittest.TestCase):
"""Test nose-exclude tests by class"""
activate = "--exclude-test=test_dirs.unittest.test"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest')
def setUp(self):
def mock_get_method_class(meth):
raise AttributeError('foobar')
import nose_exclude
self.old_get_method_class = nose_exclude.get_method_class
nose_exclude.get_method_class = mock_get_method_class
super(TestNoseDoesNotExcludeTestClass, self).setUp()
def tearDown(self):
import nose_exclude
nose_exclude.get_method_class = self.old_get_method_class
def test_tests_not_excluded(self):
assert 'Ran 3 tests' in self.output
if __name__ == '__main__':
unittest.main()