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
4 # found in the LICENSE file.
8 from pylib
.base
import base_test_result
9 from pylib
.results
import json_results
12 class JsonResultsTest(unittest
.TestCase
):
14 def testGenerateResultsDict_passedResult(self
):
15 result
= base_test_result
.BaseTestResult(
16 'test.package.TestName', base_test_result
.ResultType
.PASS
)
18 all_results
= base_test_result
.TestRunResults()
19 all_results
.AddResult(result
)
21 results_dict
= json_results
.GenerateResultsDict(all_results
)
23 ['test.package.TestName'],
24 results_dict
['all_tests'])
25 self
.assertEquals(1, len(results_dict
['per_iteration_data']))
27 iteration_result
= results_dict
['per_iteration_data'][0]
28 self
.assertTrue('test.package.TestName' in iteration_result
)
29 self
.assertEquals(1, len(iteration_result
['test.package.TestName']))
31 test_iteration_result
= iteration_result
['test.package.TestName'][0]
32 self
.assertTrue('status' in test_iteration_result
)
33 self
.assertEquals('SUCCESS', test_iteration_result
['status'])
35 def testGenerateResultsDict_skippedResult(self
):
36 result
= base_test_result
.BaseTestResult(
37 'test.package.TestName', base_test_result
.ResultType
.SKIP
)
39 all_results
= base_test_result
.TestRunResults()
40 all_results
.AddResult(result
)
42 results_dict
= json_results
.GenerateResultsDict(all_results
)
44 ['test.package.TestName'],
45 results_dict
['all_tests'])
46 self
.assertEquals(1, len(results_dict
['per_iteration_data']))
48 iteration_result
= results_dict
['per_iteration_data'][0]
49 self
.assertTrue('test.package.TestName' in iteration_result
)
50 self
.assertEquals(1, len(iteration_result
['test.package.TestName']))
52 test_iteration_result
= iteration_result
['test.package.TestName'][0]
53 self
.assertTrue('status' in test_iteration_result
)
54 self
.assertEquals('SKIPPED', test_iteration_result
['status'])
56 def testGenerateResultsDict_failedResult(self
):
57 result
= base_test_result
.BaseTestResult(
58 'test.package.TestName', base_test_result
.ResultType
.FAIL
)
60 all_results
= base_test_result
.TestRunResults()
61 all_results
.AddResult(result
)
63 results_dict
= json_results
.GenerateResultsDict(all_results
)
65 ['test.package.TestName'],
66 results_dict
['all_tests'])
67 self
.assertEquals(1, len(results_dict
['per_iteration_data']))
69 iteration_result
= results_dict
['per_iteration_data'][0]
70 self
.assertTrue('test.package.TestName' in iteration_result
)
71 self
.assertEquals(1, len(iteration_result
['test.package.TestName']))
73 test_iteration_result
= iteration_result
['test.package.TestName'][0]
74 self
.assertTrue('status' in test_iteration_result
)
75 self
.assertEquals('FAILURE', test_iteration_result
['status'])
77 def testGenerateResultsDict_duration(self
):
78 result
= base_test_result
.BaseTestResult(
79 'test.package.TestName', base_test_result
.ResultType
.PASS
, duration
=123)
81 all_results
= base_test_result
.TestRunResults()
82 all_results
.AddResult(result
)
84 results_dict
= json_results
.GenerateResultsDict(all_results
)
86 ['test.package.TestName'],
87 results_dict
['all_tests'])
88 self
.assertEquals(1, len(results_dict
['per_iteration_data']))
90 iteration_result
= results_dict
['per_iteration_data'][0]
91 self
.assertTrue('test.package.TestName' in iteration_result
)
92 self
.assertEquals(1, len(iteration_result
['test.package.TestName']))
94 test_iteration_result
= iteration_result
['test.package.TestName'][0]
95 self
.assertTrue('elapsed_time_ms' in test_iteration_result
)
96 self
.assertEquals(123, test_iteration_result
['elapsed_time_ms'])
98 def testGenerateResultsDict_multipleResults(self
):
99 result1
= base_test_result
.BaseTestResult(
100 'test.package.TestName1', base_test_result
.ResultType
.PASS
)
101 result2
= base_test_result
.BaseTestResult(
102 'test.package.TestName2', base_test_result
.ResultType
.PASS
)
104 all_results
= base_test_result
.TestRunResults()
105 all_results
.AddResult(result1
)
106 all_results
.AddResult(result2
)
108 results_dict
= json_results
.GenerateResultsDict(all_results
)
110 ['test.package.TestName1', 'test.package.TestName2'],
111 results_dict
['all_tests'])
112 self
.assertEquals(2, len(results_dict
['per_iteration_data']))
114 expected_tests
= set([
115 'test.package.TestName1',
116 'test.package.TestName2',
119 for iteration_result
in results_dict
['per_iteration_data']:
120 self
.assertEquals(1, len(iteration_result
))
121 name
= iteration_result
.keys()[0]
122 self
.assertTrue(name
in expected_tests
)
123 expected_tests
.remove(name
)
124 self
.assertEquals(1, len(iteration_result
[name
]))
126 test_iteration_result
= iteration_result
[name
][0]
127 self
.assertTrue('status' in test_iteration_result
)
128 self
.assertEquals('SUCCESS', test_iteration_result
['status'])
131 if __name__
== '__main__':
132 unittest
.main(verbosity
=2)