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.
5 """Unittests for TestRunResults."""
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
14 class TestTestRunResults(unittest
.TestCase
):
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
]))
30 self
.tr
.GetAll().symmetric_difference(
31 [self
.p1
, self
.p2
, self
.f1
, self
.c1
, self
.u1
]))
33 def testGetPass(self
):
34 self
.assertFalse(self
.tr
.GetPass().symmetric_difference(
37 def testGetNotPass(self
):
38 self
.assertFalse(self
.tr
.GetNotPass().symmetric_difference(
39 [self
.f1
, self
.c1
, self
.u1
]))
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
)
47 tr2
.AddTestRunResults(self
.tr
)
49 tr2
.GetAll().symmetric_difference(
50 [self
.p1
, self
.p2
, self
.f1
, self
.c1
, self
.u1
, f2
]))
52 def testGetLogs(self
):
53 log_print
= ('[FAIL] f1:\n'
57 self
.assertEqual(self
.tr
.GetLogs(), log_print
)
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
)
64 def testGetGtestForm(self
):
65 gtest_print
= ('[==========] 5 tests ran.\n'
66 '[ PASSED ] 2 tests.\n'
67 '[ FAILED ] 3 tests, listed below:\n'
69 '[ FAILED ] c1 (CRASHED)\n'
70 '[ FAILED ] u1 (UNKNOWN)\n'
73 self
.assertEqual(gtest_print
, self
.tr
.GetGtestForm())
75 def testRunPassed(self
):
76 self
.assertFalse(self
.tr
.DidRunPass())
77 tr2
= TestRunResults()
78 self
.assertTrue(tr2
.DidRunPass())
81 if __name__
== '__main__':