OLD | NEW |
| (Empty) |
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """Unittests for TestRunResults.""" | |
6 | |
7 import unittest | |
8 | |
9 from pylib.base.base_test_result import BaseTestResult | |
10 from pylib.base.base_test_result import TestRunResults | |
11 from pylib.base.base_test_result import ResultType | |
12 | |
13 | |
14 class TestTestRunResults(unittest.TestCase): | |
15 def setUp(self): | |
16 self.p1 = BaseTestResult('p1', ResultType.PASS, log='pass1') | |
17 other_p1 = BaseTestResult('p1', ResultType.PASS) | |
18 self.p2 = BaseTestResult('p2', ResultType.PASS) | |
19 self.f1 = BaseTestResult('f1', ResultType.FAIL, log='failure1') | |
20 self.c1 = BaseTestResult('c1', ResultType.CRASH, log='crash1') | |
21 self.u1 = BaseTestResult('u1', ResultType.UNKNOWN) | |
22 self.tr = TestRunResults() | |
23 self.tr.AddResult(self.p1) | |
24 self.tr.AddResult(other_p1) | |
25 self.tr.AddResult(self.p2) | |
26 self.tr.AddResults(set([self.f1, self.c1, self.u1])) | |
27 | |
28 def testGetAll(self): | |
29 self.assertFalse( | |
30 self.tr.GetAll().symmetric_difference( | |
31 [self.p1, self.p2, self.f1, self.c1, self.u1])) | |
32 | |
33 def testGetPass(self): | |
34 self.assertFalse(self.tr.GetPass().symmetric_difference( | |
35 [self.p1, self.p2])) | |
36 | |
37 def testGetNotPass(self): | |
38 self.assertFalse(self.tr.GetNotPass().symmetric_difference( | |
39 [self.f1, self.c1, self.u1])) | |
40 | |
41 def testGetAddTestRunResults(self): | |
42 tr2 = TestRunResults() | |
43 other_p1 = BaseTestResult('p1', ResultType.PASS) | |
44 f2 = BaseTestResult('f2', ResultType.FAIL) | |
45 tr2.AddResult(other_p1) | |
46 tr2.AddResult(f2) | |
47 tr2.AddTestRunResults(self.tr) | |
48 self.assertFalse( | |
49 tr2.GetAll().symmetric_difference( | |
50 [self.p1, self.p2, self.f1, self.c1, self.u1, f2])) | |
51 | |
52 def testGetLogs(self): | |
53 log_print = ('[FAIL] f1:\n' | |
54 'failure1\n' | |
55 '[CRASH] c1:\n' | |
56 'crash1') | |
57 self.assertEqual(self.tr.GetLogs(), log_print) | |
58 | |
59 def testGetShortForm(self): | |
60 short_print = ('ALL: 5 PASS: 2 FAIL: 1 ' | |
61 'CRASH: 1 TIMEOUT: 0 UNKNOWN: 1 ') | |
62 self.assertEqual(self.tr.GetShortForm(), short_print) | |
63 | |
64 def testGetGtestForm(self): | |
65 gtest_print = ('[==========] 5 tests ran.\n' | |
66 '[ PASSED ] 2 tests.\n' | |
67 '[ FAILED ] 3 tests, listed below:\n' | |
68 '[ FAILED ] f1\n' | |
69 '[ FAILED ] c1 (CRASHED)\n' | |
70 '[ FAILED ] u1 (UNKNOWN)\n' | |
71 '\n' | |
72 '3 FAILED TESTS') | |
73 self.assertEqual(gtest_print, self.tr.GetGtestForm()) | |
74 | |
75 def testRunPassed(self): | |
76 self.assertFalse(self.tr.DidRunPass()) | |
77 tr2 = TestRunResults() | |
78 self.assertTrue(tr2.DidRunPass()) | |
79 | |
80 | |
81 if __name__ == '__main__': | |
82 unittest.main() | |
OLD | NEW |