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

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

Issue 1851143002: Find annotated tests by exposing API in instrumentation_test_instance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 5 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 """Unit tests for instrumentation_test_instance."""
7 7
8 # pylint: disable=protected-access 8 # pylint: disable=protected-access
9 9
10 import unittest 10 import unittest
11 11
12 from pylib.base import base_test_result 12 from pylib.base import base_test_result
13 from pylib.constants import host_paths 13 from pylib.constants import host_paths
14 from pylib.instrumentation import instrumentation_test_instance 14 from pylib.instrumentation import instrumentation_test_instance
15 15
16 with host_paths.SysPath(host_paths.PYMOCK_PATH): 16 with host_paths.SysPath(host_paths.PYMOCK_PATH):
17 import mock # pylint: disable=import-error 17 import mock # pylint: disable=import-error
18 18
19 _INSTRUMENTATION_TEST_INSTANCE_PATH = (
20 'pylib.instrumentation.instrumentation_test_instance.%s')
19 21
20 class InstrumentationTestInstanceTest(unittest.TestCase): 22 class InstrumentationTestInstanceTest(unittest.TestCase):
21 23
22 def setUp(self): 24 def setUp(self):
23 options = mock.Mock() 25 options = mock.Mock()
24 options.tool = '' 26 options.tool = ''
25 27
26 @staticmethod 28 @staticmethod
27 def createTestInstance(): 29 def createTestInstance():
28 c = ('pylib.instrumentation.instrumentation_test_instance.' 30 c = _INSTRUMENTATION_TEST_INSTANCE_PATH % 'InstrumentationTestInstance'
29 'InstrumentationTestInstance')
30 with mock.patch('%s._initializeApkAttributes' % c), ( 31 with mock.patch('%s._initializeApkAttributes' % c), (
31 mock.patch('%s._initializeDataDependencyAttributes' % c)), ( 32 mock.patch('%s._initializeDataDependencyAttributes' % c)), (
32 mock.patch('%s._initializeTestFilterAttributes' % c)), ( 33 mock.patch('%s._initializeTestFilterAttributes' % c)), (
33 mock.patch('%s._initializeFlagAttributes' % c)), ( 34 mock.patch('%s._initializeFlagAttributes' % c)), (
34 mock.patch('%s._initializeDriverAttributes' % c)), ( 35 mock.patch('%s._initializeDriverAttributes' % c)), (
35 mock.patch('%s._initializeTestControlAttributes' % c)), ( 36 mock.patch('%s._initializeTestControlAttributes' % c)), (
36 mock.patch('%s._initializeTestCoverageAttributes' % c)): 37 mock.patch('%s._initializeTestCoverageAttributes' % c)):
37 return instrumentation_test_instance.InstrumentationTestInstance( 38 return instrumentation_test_instance.InstrumentationTestInstance(
38 mock.MagicMock(), mock.MagicMock(), lambda s: None) 39 mock.MagicMock(), mock.MagicMock(), lambda s: None)
39 40
(...skipping 19 matching lines...) Expand all
59 'class': 'org.chromium.test.SampleTest2', 60 'class': 'org.chromium.test.SampleTest2',
60 'methods': [ 61 'methods': [
61 { 62 {
62 'annotations': {'SmallTest': None}, 63 'annotations': {'SmallTest': None},
63 'method': 'testMethod1', 64 'method': 'testMethod1',
64 }, 65 },
65 ], 66 ],
66 } 67 }
67 ] 68 ]
68 69
69 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
70
71 expected_tests = [ 70 expected_tests = [
72 { 71 {
73 'annotations': { 72 'annotations': {
74 'Feature': {'value': ['Foo']}, 73 'Feature': {'value': ['Foo']},
75 'SmallTest': None, 74 'SmallTest': None,
76 }, 75 },
77 'class': 'org.chromium.test.SampleTest', 76 'class': 'org.chromium.test.SampleTest',
78 'method': 'testMethod1', 77 'method': 'testMethod1',
79 }, 78 },
80 { 79 {
81 'annotations': { 80 'annotations': {
82 'Feature': {'value': ['Foo']}, 81 'Feature': {'value': ['Foo']},
83 'MediumTest': None, 82 'MediumTest': None,
84 }, 83 },
85 'class': 'org.chromium.test.SampleTest', 84 'class': 'org.chromium.test.SampleTest',
86 'method': 'testMethod2', 85 'method': 'testMethod2',
87 }, 86 },
88 { 87 {
89 'annotations': { 88 'annotations': {
90 'Feature': {'value': ['Bar']}, 89 'Feature': {'value': ['Bar']},
91 'SmallTest': None, 90 'SmallTest': None,
92 }, 91 },
93 'class': 'org.chromium.test.SampleTest2', 92 'class': 'org.chromium.test.SampleTest2',
94 'method': 'testMethod1', 93 'method': 'testMethod1',
95 }, 94 },
96 ] 95 ]
97 96
98 actual_tests = o.GetTests() 97 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
98 return_value=raw_tests):
99 actual_tests = o.GetTests()
100
99 self.assertEquals(actual_tests, expected_tests) 101 self.assertEquals(actual_tests, expected_tests)
100 102
101 def testGetTests_simpleGtestFilter(self): 103 def testGetTests_simpleGtestFilter(self):
102 o = self.createTestInstance() 104 o = self.createTestInstance()
103 raw_tests = [ 105 raw_tests = [
104 { 106 {
105 'annotations': {'Feature': {'value': ['Foo']}}, 107 'annotations': {'Feature': {'value': ['Foo']}},
106 'class': 'org.chromium.test.SampleTest', 108 'class': 'org.chromium.test.SampleTest',
107 'methods': [ 109 'methods': [
108 { 110 {
109 'annotations': {'SmallTest': None}, 111 'annotations': {'SmallTest': None},
110 'method': 'testMethod1', 112 'method': 'testMethod1',
111 }, 113 },
112 { 114 {
113 'annotations': {'MediumTest': None}, 115 'annotations': {'MediumTest': None},
114 'method': 'testMethod2', 116 'method': 'testMethod2',
115 }, 117 },
116 ], 118 ],
117 } 119 }
118 ] 120 ]
119 121
120 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
121 o._test_filter = 'org.chromium.test.SampleTest.testMethod1'
122
123 expected_tests = [ 122 expected_tests = [
124 { 123 {
125 'annotations': { 124 'annotations': {
126 'Feature': {'value': ['Foo']}, 125 'Feature': {'value': ['Foo']},
127 'SmallTest': None, 126 'SmallTest': None,
128 }, 127 },
129 'class': 'org.chromium.test.SampleTest', 128 'class': 'org.chromium.test.SampleTest',
130 'method': 'testMethod1', 129 'method': 'testMethod1',
131 }, 130 },
132 ] 131 ]
133 132
134 actual_tests = o.GetTests() 133 o._test_filter = 'org.chromium.test.SampleTest.testMethod1'
134 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
135 return_value=raw_tests):
136 actual_tests = o.GetTests()
137
135 self.assertEquals(actual_tests, expected_tests) 138 self.assertEquals(actual_tests, expected_tests)
136 139
137 def testGetTests_wildcardGtestFilter(self): 140 def testGetTests_wildcardGtestFilter(self):
138 o = self.createTestInstance() 141 o = self.createTestInstance()
139 raw_tests = [ 142 raw_tests = [
140 { 143 {
141 'annotations': {'Feature': {'value': ['Foo']}}, 144 'annotations': {'Feature': {'value': ['Foo']}},
142 'class': 'org.chromium.test.SampleTest', 145 'class': 'org.chromium.test.SampleTest',
143 'methods': [ 146 'methods': [
144 { 147 {
(...skipping 11 matching lines...) Expand all
156 'class': 'org.chromium.test.SampleTest2', 159 'class': 'org.chromium.test.SampleTest2',
157 'methods': [ 160 'methods': [
158 { 161 {
159 'annotations': {'SmallTest': None}, 162 'annotations': {'SmallTest': None},
160 'method': 'testMethod1', 163 'method': 'testMethod1',
161 }, 164 },
162 ], 165 ],
163 } 166 }
164 ] 167 ]
165 168
166 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
167 o._test_filter = 'org.chromium.test.SampleTest2.*'
168
169 expected_tests = [ 169 expected_tests = [
170 { 170 {
171 'annotations': { 171 'annotations': {
172 'Feature': {'value': ['Bar']}, 172 'Feature': {'value': ['Bar']},
173 'SmallTest': None, 173 'SmallTest': None,
174 }, 174 },
175 'class': 'org.chromium.test.SampleTest2', 175 'class': 'org.chromium.test.SampleTest2',
176 'method': 'testMethod1', 176 'method': 'testMethod1',
177 }, 177 },
178 ] 178 ]
179 179
180 actual_tests = o.GetTests() 180 o._test_filter = 'org.chromium.test.SampleTest2.*'
181 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
182 return_value=raw_tests):
183 actual_tests = o.GetTests()
184
181 self.assertEquals(actual_tests, expected_tests) 185 self.assertEquals(actual_tests, expected_tests)
182 186
183 @unittest.skip('crbug.com/623047') 187 @unittest.skip('crbug.com/623047')
184 def testGetTests_negativeGtestFilter(self): 188 def testGetTests_negativeGtestFilter(self):
185 o = self.createTestInstance() 189 o = self.createTestInstance()
186 raw_tests = [ 190 raw_tests = [
187 { 191 {
188 'annotations': {'Feature': {'value': ['Foo']}}, 192 'annotations': {'Feature': {'value': ['Foo']}},
189 'class': 'org.chromium.test.SampleTest', 193 'class': 'org.chromium.test.SampleTest',
190 'methods': [ 194 'methods': [
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 'class': 'org.chromium.test.SampleTest2', 261 'class': 'org.chromium.test.SampleTest2',
258 'methods': [ 262 'methods': [
259 { 263 {
260 'annotations': {'SmallTest': None}, 264 'annotations': {'SmallTest': None},
261 'method': 'testMethod1', 265 'method': 'testMethod1',
262 }, 266 },
263 ], 267 ],
264 } 268 }
265 ] 269 ]
266 270
267 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
268 o._annotations = {'SmallTest': None}
269
270 expected_tests = [ 271 expected_tests = [
271 { 272 {
272 'annotations': { 273 'annotations': {
273 'Feature': {'value': ['Foo']}, 274 'Feature': {'value': ['Foo']},
274 'SmallTest': None, 275 'SmallTest': None,
275 }, 276 },
276 'class': 'org.chromium.test.SampleTest', 277 'class': 'org.chromium.test.SampleTest',
277 'method': 'testMethod1', 278 'method': 'testMethod1',
278 }, 279 },
279 { 280 {
280 'annotations': { 281 'annotations': {
281 'Feature': {'value': ['Bar']}, 282 'Feature': {'value': ['Bar']},
282 'SmallTest': None, 283 'SmallTest': None,
283 }, 284 },
284 'class': 'org.chromium.test.SampleTest2', 285 'class': 'org.chromium.test.SampleTest2',
285 'method': 'testMethod1', 286 'method': 'testMethod1',
286 }, 287 },
287 ] 288 ]
288 289
289 actual_tests = o.GetTests() 290 o._annotations = {'SmallTest': None}
291 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
292 return_value=raw_tests):
293 actual_tests = o.GetTests()
294
290 self.assertEquals(actual_tests, expected_tests) 295 self.assertEquals(actual_tests, expected_tests)
291 296
292 def testGetTests_excludedAnnotationFilter(self): 297 def testGetTests_excludedAnnotationFilter(self):
293 o = self.createTestInstance() 298 o = self.createTestInstance()
294 raw_tests = [ 299 raw_tests = [
295 { 300 {
296 'annotations': {'Feature': {'value': ['Foo']}}, 301 'annotations': {'Feature': {'value': ['Foo']}},
297 'class': 'org.chromium.test.SampleTest', 302 'class': 'org.chromium.test.SampleTest',
298 'methods': [ 303 'methods': [
299 { 304 {
(...skipping 11 matching lines...) Expand all
311 'class': 'org.chromium.test.SampleTest2', 316 'class': 'org.chromium.test.SampleTest2',
312 'methods': [ 317 'methods': [
313 { 318 {
314 'annotations': {'SmallTest': None}, 319 'annotations': {'SmallTest': None},
315 'method': 'testMethod1', 320 'method': 'testMethod1',
316 }, 321 },
317 ], 322 ],
318 } 323 }
319 ] 324 ]
320 325
321 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
322 o._excluded_annotations = {'SmallTest': None}
323
324 expected_tests = [ 326 expected_tests = [
325 { 327 {
326 'annotations': { 328 'annotations': {
327 'Feature': {'value': ['Foo']}, 329 'Feature': {'value': ['Foo']},
328 'MediumTest': None, 330 'MediumTest': None,
329 }, 331 },
330 'class': 'org.chromium.test.SampleTest', 332 'class': 'org.chromium.test.SampleTest',
331 'method': 'testMethod2', 333 'method': 'testMethod2',
332 }, 334 },
333 ] 335 ]
334 336
335 actual_tests = o.GetTests() 337 o._excluded_annotations = {'SmallTest': None}
338 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
339 return_value=raw_tests):
340 actual_tests = o.GetTests()
341
336 self.assertEquals(actual_tests, expected_tests) 342 self.assertEquals(actual_tests, expected_tests)
337 343
338 def testGetTests_annotationSimpleValueFilter(self): 344 def testGetTests_annotationSimpleValueFilter(self):
339 o = self.createTestInstance() 345 o = self.createTestInstance()
340 raw_tests = [ 346 raw_tests = [
341 { 347 {
342 'annotations': {'Feature': {'value': ['Foo']}}, 348 'annotations': {'Feature': {'value': ['Foo']}},
343 'class': 'org.chromium.test.SampleTest', 349 'class': 'org.chromium.test.SampleTest',
344 'methods': [ 350 'methods': [
345 { 351 {
(...skipping 20 matching lines...) Expand all
366 'annotations': { 372 'annotations': {
367 'SmallTest': None, 373 'SmallTest': None,
368 'TestValue': '3', 374 'TestValue': '3',
369 }, 375 },
370 'method': 'testMethod1', 376 'method': 'testMethod1',
371 }, 377 },
372 ], 378 ],
373 } 379 }
374 ] 380 ]
375 381
376 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
377 o._annotations = {'TestValue': '1'}
378
379 expected_tests = [ 382 expected_tests = [
380 { 383 {
381 'annotations': { 384 'annotations': {
382 'Feature': {'value': ['Foo']}, 385 'Feature': {'value': ['Foo']},
383 'SmallTest': None, 386 'SmallTest': None,
384 'TestValue': '1', 387 'TestValue': '1',
385 }, 388 },
386 'class': 'org.chromium.test.SampleTest', 389 'class': 'org.chromium.test.SampleTest',
387 'method': 'testMethod1', 390 'method': 'testMethod1',
388 }, 391 },
389 ] 392 ]
390 393
391 actual_tests = o.GetTests() 394 o._annotations = {'TestValue': '1'}
395 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
396 return_value=raw_tests):
397 actual_tests = o.GetTests()
398
392 self.assertEquals(actual_tests, expected_tests) 399 self.assertEquals(actual_tests, expected_tests)
393 400
394 def testGetTests_annotationDictValueFilter(self): 401 def testGetTests_annotationDictValueFilter(self):
395 o = self.createTestInstance() 402 o = self.createTestInstance()
396 raw_tests = [ 403 raw_tests = [
397 { 404 {
398 'annotations': {'Feature': {'value': ['Foo']}}, 405 'annotations': {'Feature': {'value': ['Foo']}},
399 'class': 'org.chromium.test.SampleTest', 406 'class': 'org.chromium.test.SampleTest',
400 'methods': [ 407 'methods': [
401 { 408 {
(...skipping 11 matching lines...) Expand all
413 'class': 'org.chromium.test.SampleTest2', 420 'class': 'org.chromium.test.SampleTest2',
414 'methods': [ 421 'methods': [
415 { 422 {
416 'annotations': {'SmallTest': None}, 423 'annotations': {'SmallTest': None},
417 'method': 'testMethod1', 424 'method': 'testMethod1',
418 }, 425 },
419 ], 426 ],
420 } 427 }
421 ] 428 ]
422 429
423 o._GetTestsFromPickle = mock.MagicMock(return_value=raw_tests)
424 o._annotations = {'Feature': 'Bar'}
425
426 expected_tests = [ 430 expected_tests = [
427 { 431 {
428 'annotations': { 432 'annotations': {
429 'Feature': {'value': ['Bar']}, 433 'Feature': {'value': ['Bar']},
430 'SmallTest': None, 434 'SmallTest': None,
431 }, 435 },
432 'class': 'org.chromium.test.SampleTest2', 436 'class': 'org.chromium.test.SampleTest2',
433 'method': 'testMethod1', 437 'method': 'testMethod1',
434 }, 438 },
435 ] 439 ]
436 440
437 actual_tests = o.GetTests() 441 o._annotations = {'Feature': 'Bar'}
442 with mock.patch(_INSTRUMENTATION_TEST_INSTANCE_PATH % '_GetTestsFromPickle',
443 return_value=raw_tests):
444 actual_tests = o.GetTests()
445
438 self.assertEquals(actual_tests, expected_tests) 446 self.assertEquals(actual_tests, expected_tests)
439 447
440 def testGenerateTestResults_noStatus(self): 448 def testGenerateTestResults_noStatus(self):
441 results = instrumentation_test_instance.GenerateTestResults( 449 results = instrumentation_test_instance.GenerateTestResults(
442 None, None, [], 0, 1000) 450 None, None, [], 0, 1000)
443 self.assertEqual([], results) 451 self.assertEqual([], results)
444 452
445 def testGenerateTestResults_testPassed(self): 453 def testGenerateTestResults_testPassed(self):
446 statuses = [ 454 statuses = [
447 (1, { 455 (1, {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 ] 537 ]
530 results = instrumentation_test_instance.GenerateTestResults( 538 results = instrumentation_test_instance.GenerateTestResults(
531 None, None, statuses, 0, 1000) 539 None, None, statuses, 0, 1000)
532 self.assertEqual(1, len(results)) 540 self.assertEqual(1, len(results))
533 self.assertEqual(base_test_result.ResultType.FAIL, results[0].GetType()) 541 self.assertEqual(base_test_result.ResultType.FAIL, results[0].GetType())
534 self.assertEqual(stacktrace, results[0].GetLog()) 542 self.assertEqual(stacktrace, results[0].GetLog())
535 543
536 544
537 if __name__ == '__main__': 545 if __name__ == '__main__':
538 unittest.main(verbosity=2) 546 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « build/android/pylib/instrumentation/instrumentation_test_instance.py ('k') | tools/android/find_annotated_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698