Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance_test.py

Issue 2095013002: [Android] Fix feature annotation filtering for instrumentation tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unit tests for instrumentation_test_instance."""
6 7
7 """Unit tests for instrumentation.TestRunner.""" 8 # pylint: disable=protected-access
8 9
9 import unittest 10 import unittest
10 11
11 from pylib.base import base_test_result 12 from pylib.base import base_test_result
12 from pylib.constants import host_paths 13 from pylib.constants import host_paths
13 from pylib.instrumentation import instrumentation_test_instance 14 from pylib.instrumentation import instrumentation_test_instance
14 15
15 with host_paths.SysPath(host_paths.PYMOCK_PATH): 16 with host_paths.SysPath(host_paths.PYMOCK_PATH):
16 import mock # pylint: disable=import-error 17 import mock # pylint: disable=import-error
17 18
18 19
19 class InstrumentationTestInstanceTest(unittest.TestCase): 20 class InstrumentationTestInstanceTest(unittest.TestCase):
20 21
21 def setUp(self): 22 def setUp(self):
22 options = mock.Mock() 23 options = mock.Mock()
23 options.tool = '' 24 options.tool = ''
24 25
26 @staticmethod
27 def createTestInstance():
28 c = ('pylib.instrumentation.instrumentation_test_instance.'
29 'InstrumentationTestInstance')
30 with mock.patch('%s._initializeApkAttributes' % c), (
31 mock.patch('%s._initializeDataDependencyAttributes' % c)), (
32 mock.patch('%s._initializeTestFilterAttributes' % c)), (
33 mock.patch('%s._initializeFlagAttributes' % c)), (
34 mock.patch('%s._initializeDriverAttributes' % c)), (
35 mock.patch('%s._initializeTestControlAttributes' % c)), (
36 mock.patch('%s._initializeTestCoverageAttributes' % c)):
37 return instrumentation_test_instance.InstrumentationTestInstance(
38 mock.MagicMock(), mock.MagicMock(), lambda s: None)
39
40 def testGetTests_noFilter(self):
41 o = self.createTestInstance()
42 raw_tests = [
43 {
44 'annotations': {'Feature': {'value': ['Foo']}},
45 'class': 'org.chromium.test.SampleTest',
46 'methods': [
47 {
48 'annotations': {'SmallTest': None},
49 'method': 'testMethod1',
50 },
51 {
52 'annotations': {'MediumTest': None},
53 'method': 'testMethod2',
54 },
55 ],
56 },
57 {
58 'annotations': {'Feature': {'value': ['Bar']}},
59 'class': 'org.chromium.test.SampleTest2',
60 'methods': [
61 {
62 'annotations': {'SmallTest': None},
63 'method': 'testMethod1',
64 },
65 ],
66 }
67 ]
68
69 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
70
71 expected_tests = [
72 {
73 'annotations': {
74 'Feature': {'value': ['Foo']},
75 'SmallTest': None,
76 },
77 'class': 'org.chromium.test.SampleTest',
78 'method': 'testMethod1',
79 },
80 {
81 'annotations': {
82 'Feature': {'value': ['Foo']},
83 'MediumTest': None,
84 },
85 'class': 'org.chromium.test.SampleTest',
86 'method': 'testMethod2',
87 },
88 {
89 'annotations': {
90 'Feature': {'value': ['Bar']},
91 'SmallTest': None,
92 },
93 'class': 'org.chromium.test.SampleTest2',
94 'method': 'testMethod1',
95 },
96 ]
97
98 actual_tests = o.GetTests()
99 self.assertEquals(actual_tests, expected_tests)
100
101 def testGetTests_simpleGtestFilter(self):
102 o = self.createTestInstance()
103 raw_tests = [
104 {
105 'annotations': {'Feature': {'value': ['Foo']}},
106 'class': 'org.chromium.test.SampleTest',
107 'methods': [
108 {
109 'annotations': {'SmallTest': None},
110 'method': 'testMethod1',
111 },
112 {
113 'annotations': {'MediumTest': None},
114 'method': 'testMethod2',
115 },
116 ],
117 }
118 ]
119
120 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
121 o._test_filter = 'org.chromium.test.SampleTest.testMethod1'
122
123 expected_tests = [
124 {
125 'annotations': {
126 'Feature': {'value': ['Foo']},
127 'SmallTest': None,
128 },
129 'class': 'org.chromium.test.SampleTest',
130 'method': 'testMethod1',
131 },
132 ]
133
134 actual_tests = o.GetTests()
135 self.assertEquals(actual_tests, expected_tests)
136
137 def testGetTests_wildcardGtestFilter(self):
138 o = self.createTestInstance()
139 raw_tests = [
140 {
141 'annotations': {'Feature': {'value': ['Foo']}},
142 'class': 'org.chromium.test.SampleTest',
143 'methods': [
144 {
145 'annotations': {'SmallTest': None},
146 'method': 'testMethod1',
147 },
148 {
149 'annotations': {'MediumTest': None},
150 'method': 'testMethod2',
151 },
152 ],
153 },
154 {
155 'annotations': {'Feature': {'value': ['Bar']}},
156 'class': 'org.chromium.test.SampleTest2',
157 'methods': [
158 {
159 'annotations': {'SmallTest': None},
160 'method': 'testMethod1',
161 },
162 ],
163 }
164 ]
165
166 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
167 o._test_filter = 'org.chromium.test.SampleTest2.*'
168
169 expected_tests = [
170 {
171 'annotations': {
172 'Feature': {'value': ['Bar']},
173 'SmallTest': None,
174 },
175 'class': 'org.chromium.test.SampleTest2',
176 'method': 'testMethod1',
177 },
178 ]
179
180 actual_tests = o.GetTests()
181 self.assertEquals(actual_tests, expected_tests)
182
183 @unittest.skip('crbug.com/623047')
184 def testGetTests_negativeGtestFilter(self):
185 o = self.createTestInstance()
186 raw_tests = [
187 {
188 'annotations': {'Feature': {'value': ['Foo']}},
189 'class': 'org.chromium.test.SampleTest',
190 'methods': [
191 {
192 'annotations': {'SmallTest': None},
193 'method': 'testMethod1',
194 },
195 {
196 'annotations': {'MediumTest': None},
197 'method': 'testMethod2',
198 },
199 ],
200 },
201 {
202 'annotations': {'Feature': {'value': ['Bar']}},
203 'class': 'org.chromium.test.SampleTest2',
204 'methods': [
205 {
206 'annotations': {'SmallTest': None},
207 'method': 'testMethod1',
208 },
209 ],
210 }
211 ]
212
213 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
214 o._test_filter = '*-org.chromium.test.SampleTest.testMethod1'
215
216 expected_tests = [
217 {
218 'annotations': {
219 'Feature': {'value': ['Foo']},
220 'MediumTest': None,
221 },
222 'class': 'org.chromium.test.SampleTest',
223 'method': 'testMethod2',
224 },
225 {
226 'annotations': {
227 'Feature': {'value': ['Bar']},
228 'SmallTest': None,
229 },
230 'class': 'org.chromium.test.SampleTest2',
231 'method': 'testMethod1',
232 },
233 ]
234
235 actual_tests = o.GetTests()
236 self.assertEquals(actual_tests, expected_tests)
237
238 def testGetTests_annotationFilter(self):
239 o = self.createTestInstance()
240 raw_tests = [
241 {
242 'annotations': {'Feature': {'value': ['Foo']}},
243 'class': 'org.chromium.test.SampleTest',
244 'methods': [
245 {
246 'annotations': {'SmallTest': None},
247 'method': 'testMethod1',
248 },
249 {
250 'annotations': {'MediumTest': None},
251 'method': 'testMethod2',
252 },
253 ],
254 },
255 {
256 'annotations': {'Feature': {'value': ['Bar']}},
257 'class': 'org.chromium.test.SampleTest2',
258 'methods': [
259 {
260 'annotations': {'SmallTest': None},
261 'method': 'testMethod1',
262 },
263 ],
264 }
265 ]
266
267 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
268 o._annotations = {'SmallTest': None}
269
270 expected_tests = [
271 {
272 'annotations': {
273 'Feature': {'value': ['Foo']},
274 'SmallTest': None,
275 },
276 'class': 'org.chromium.test.SampleTest',
277 'method': 'testMethod1',
278 },
279 {
280 'annotations': {
281 'Feature': {'value': ['Bar']},
282 'SmallTest': None,
283 },
284 'class': 'org.chromium.test.SampleTest2',
285 'method': 'testMethod1',
286 },
287 ]
288
289 actual_tests = o.GetTests()
290 self.assertEquals(actual_tests, expected_tests)
291
292 def testGetTests_excludedAnnotationFilter(self):
293 o = self.createTestInstance()
294 raw_tests = [
295 {
296 'annotations': {'Feature': {'value': ['Foo']}},
297 'class': 'org.chromium.test.SampleTest',
298 'methods': [
299 {
300 'annotations': {'SmallTest': None},
301 'method': 'testMethod1',
302 },
303 {
304 'annotations': {'MediumTest': None},
305 'method': 'testMethod2',
306 },
307 ],
308 },
309 {
310 'annotations': {'Feature': {'value': ['Bar']}},
311 'class': 'org.chromium.test.SampleTest2',
312 'methods': [
313 {
314 'annotations': {'SmallTest': None},
315 'method': 'testMethod1',
316 },
317 ],
318 }
319 ]
320
321 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
322 o._excluded_annotations = {'SmallTest': None}
323
324 expected_tests = [
325 {
326 'annotations': {
327 'Feature': {'value': ['Foo']},
328 'MediumTest': None,
329 },
330 'class': 'org.chromium.test.SampleTest',
331 'method': 'testMethod2',
332 },
333 ]
334
335 actual_tests = o.GetTests()
336 self.assertEquals(actual_tests, expected_tests)
337
338 def testGetTests_annotationSimpleValueFilter(self):
339 o = self.createTestInstance()
340 raw_tests = [
341 {
342 'annotations': {'Feature': {'value': ['Foo']}},
343 'class': 'org.chromium.test.SampleTest',
344 'methods': [
345 {
346 'annotations': {
347 'SmallTest': None,
348 'TestValue': '1',
349 },
350 'method': 'testMethod1',
351 },
352 {
353 'annotations': {
354 'MediumTest': None,
355 'TestValue': '2',
356 },
357 'method': 'testMethod2',
358 },
359 ],
360 },
361 {
362 'annotations': {'Feature': {'value': ['Bar']}},
363 'class': 'org.chromium.test.SampleTest2',
364 'methods': [
365 {
366 'annotations': {
367 'SmallTest': None,
368 'TestValue': '3',
369 },
370 'method': 'testMethod1',
371 },
372 ],
373 }
374 ]
375
376 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
377 o._annotations = {'TestValue': '1'}
378
379 expected_tests = [
380 {
381 'annotations': {
382 'Feature': {'value': ['Foo']},
383 'SmallTest': None,
384 'TestValue': '1',
385 },
386 'class': 'org.chromium.test.SampleTest',
387 'method': 'testMethod1',
388 },
389 ]
390
391 actual_tests = o.GetTests()
392 self.assertEquals(actual_tests, expected_tests)
393
394 def testGetTests_annotationDictValueFilter(self):
395 o = self.createTestInstance()
396 raw_tests = [
397 {
398 'annotations': {'Feature': {'value': ['Foo']}},
399 'class': 'org.chromium.test.SampleTest',
400 'methods': [
401 {
402 'annotations': {'SmallTest': None},
403 'method': 'testMethod1',
404 },
405 {
406 'annotations': {'MediumTest': None},
407 'method': 'testMethod2',
408 },
409 ],
410 },
411 {
412 'annotations': {'Feature': {'value': ['Bar']}},
413 'class': 'org.chromium.test.SampleTest2',
414 'methods': [
415 {
416 'annotations': {'SmallTest': None},
417 'method': 'testMethod1',
418 },
419 ],
420 }
421 ]
422
423 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
424 o._annotations = {'Feature': 'Bar'}
425
426 expected_tests = [
427 {
428 'annotations': {
429 'Feature': {'value': ['Bar']},
430 'SmallTest': None,
431 },
432 'class': 'org.chromium.test.SampleTest2',
433 'method': 'testMethod1',
434 },
435 ]
436
437 actual_tests = o.GetTests()
438 self.assertEquals(actual_tests, expected_tests)
439
25 def testGenerateTestResults_noStatus(self): 440 def testGenerateTestResults_noStatus(self):
26 results = instrumentation_test_instance.GenerateTestResults( 441 results = instrumentation_test_instance.GenerateTestResults(
27 None, None, [], 0, 1000) 442 None, None, [], 0, 1000)
28 self.assertEqual([], results) 443 self.assertEqual([], results)
29 444
30 def testGenerateTestResults_testPassed(self): 445 def testGenerateTestResults_testPassed(self):
31 statuses = [ 446 statuses = [
32 (1, { 447 (1, {
33 'class': 'test.package.TestClass', 448 'class': 'test.package.TestClass',
34 'test': 'testMethod', 449 'test': 'testMethod',
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 ] 529 ]
115 results = instrumentation_test_instance.GenerateTestResults( 530 results = instrumentation_test_instance.GenerateTestResults(
116 None, None, statuses, 0, 1000) 531 None, None, statuses, 0, 1000)
117 self.assertEqual(1, len(results)) 532 self.assertEqual(1, len(results))
118 self.assertEqual(base_test_result.ResultType.FAIL, results[0].GetType()) 533 self.assertEqual(base_test_result.ResultType.FAIL, results[0].GetType())
119 self.assertEqual(stacktrace, results[0].GetLog()) 534 self.assertEqual(stacktrace, results[0].GetLog())
120 535
121 536
122 if __name__ == '__main__': 537 if __name__ == '__main__':
123 unittest.main(verbosity=2) 538 unittest.main(verbosity=2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698