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

Side by Side Diff: build/android/pylib/local/device/local_device_test_run_test.py

Issue 1987763002: [Android] Expose each try result in test results JSON. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 7 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
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 # pylint: disable=protected-access
7
8 import unittest
9
10 from pylib.base import base_test_result
11 from pylib.constants import host_paths
12 from pylib.local.device import local_device_test_run
13
14 with host_paths.SysPath(host_paths.PYMOCK_PATH):
15 import mock # pylint: disable=import-error
16
17
18 class TestLocalDeviceTestRun(local_device_test_run.LocalDeviceTestRun):
19
20 # pylint: disable=abstract-method
21
22 def __init__(self):
23 super(TestLocalDeviceTestRun, self).__init__(
24 mock.MagicMock(), mock.MagicMock())
25
26
27 class TestLocalDeviceNonStringTestRun(
28 local_device_test_run.LocalDeviceTestRun):
29
30 # pylint: disable=abstract-method
31
32 def __init__(self):
33 super(TestLocalDeviceNonStringTestRun, self).__init__(
34 mock.MagicMock(), mock.MagicMock())
35
36 def _GetTestName(self, test):
37 return test['name']
38
39
40 class LocalDeviceTestRunTest(unittest.TestCase):
41
42 def testGetTestsToRetry_allTestsPassed(self):
43 results = [
44 base_test_result.BaseTestResult(
45 'Test1', base_test_result.ResultType.PASS),
46 base_test_result.BaseTestResult(
47 'Test2', base_test_result.ResultType.PASS),
48 ]
49
50 tests = [r.GetName() for r in results]
51 try_results = base_test_result.TestRunResults()
52 try_results.AddResults(results)
53
54 test_run = TestLocalDeviceTestRun()
55 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
56 self.assertEquals(0, len(tests_to_retry))
57
58 def testGetTestsToRetry_testFailed(self):
59 results = [
60 base_test_result.BaseTestResult(
61 'Test1', base_test_result.ResultType.FAIL),
62 base_test_result.BaseTestResult(
63 'Test2', base_test_result.ResultType.PASS),
64 ]
65
66 tests = [r.GetName() for r in results]
67 try_results = base_test_result.TestRunResults()
68 try_results.AddResults(results)
69
70 test_run = TestLocalDeviceTestRun()
71 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
72 self.assertEquals(1, len(tests_to_retry))
73 self.assertIn('Test1', tests_to_retry)
74
75 def testGetTestsToRetry_testUnknown(self):
76 results = [
77 base_test_result.BaseTestResult(
78 'Test2', base_test_result.ResultType.PASS),
79 ]
80
81 tests = ['Test1'] + [r.GetName() for r in results]
82 try_results = base_test_result.TestRunResults()
83 try_results.AddResults(results)
84
85 test_run = TestLocalDeviceTestRun()
86 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
87 self.assertEquals(1, len(tests_to_retry))
88 self.assertIn('Test1', tests_to_retry)
89
90 def testGetTestsToRetry_wildcardFilter_allPass(self):
91 results = [
92 base_test_result.BaseTestResult(
93 'TestCase.Test1', base_test_result.ResultType.PASS),
94 base_test_result.BaseTestResult(
95 'TestCase.Test2', base_test_result.ResultType.PASS),
96 ]
97
98 tests = ['TestCase.*']
99 try_results = base_test_result.TestRunResults()
100 try_results.AddResults(results)
101
102 test_run = TestLocalDeviceTestRun()
103 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
104 self.assertEquals(0, len(tests_to_retry))
105
106 def testGetTestsToRetry_wildcardFilter_oneFails(self):
107 results = [
108 base_test_result.BaseTestResult(
109 'TestCase.Test1', base_test_result.ResultType.PASS),
110 base_test_result.BaseTestResult(
111 'TestCase.Test2', base_test_result.ResultType.FAIL),
112 ]
113
114 tests = ['TestCase.*']
115 try_results = base_test_result.TestRunResults()
116 try_results.AddResults(results)
117
118 test_run = TestLocalDeviceTestRun()
119 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
120 self.assertEquals(1, len(tests_to_retry))
121 self.assertIn('TestCase.*', tests_to_retry)
122
123 def testGetTestsToRetry_nonStringTests(self):
124 results = [
125 base_test_result.BaseTestResult(
126 'TestCase.Test1', base_test_result.ResultType.PASS),
127 base_test_result.BaseTestResult(
128 'TestCase.Test2', base_test_result.ResultType.FAIL),
129 ]
130
131 tests = [
132 {'name': 'TestCase.Test1'},
133 {'name': 'TestCase.Test2'},
134 ]
135 try_results = base_test_result.TestRunResults()
136 try_results.AddResults(results)
137
138 test_run = TestLocalDeviceNonStringTestRun()
139 tests_to_retry = test_run._GetTestsToRetry(tests, try_results)
140 self.assertEquals(1, len(tests_to_retry))
141 self.assertIsInstance(tests_to_retry[0], dict)
142 self.assertEquals(tests[1], tests_to_retry[0])
143
144
145 if __name__ == '__main__':
146 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « build/android/pylib/local/device/local_device_test_run.py ('k') | build/android/pylib/remote/device/remote_device_test_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698