8e536a3275de39bc47b18ca65d9044ddbcaa8def
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / views / buildbot_results_unittest.py
1 # Copyright (C) 2012 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #     * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #     * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #     * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import StringIO
30 import unittest
31
32 from webkitpy.common.host_mock import MockHost
33
34 from webkitpy.layout_tests.models import test_expectations
35 from webkitpy.layout_tests.models import test_failures
36 from webkitpy.layout_tests.models import test_run_results
37 from webkitpy.layout_tests.models import test_run_results
38 from webkitpy.layout_tests.models import test_run_results_unittest
39 from webkitpy.layout_tests.views import buildbot_results
40
41
42 class BuildBotPrinterTests(unittest.TestCase):
43     def assertEmpty(self, stream):
44         self.assertFalse(stream.getvalue())
45
46     def assertNotEmpty(self, stream):
47         self.assertTrue(stream.getvalue())
48
49     def get_printer(self):
50         stream = StringIO.StringIO()
51         printer = buildbot_results.BuildBotPrinter(stream, debug_logging=True)
52         return printer, stream
53
54     def test_print_unexpected_results(self):
55         port = MockHost().port_factory.get('test')
56         printer, out = self.get_printer()
57
58         # test everything running as expected
59         DASHED_LINE = "-" * 78 + "\n"
60         summary = test_run_results_unittest.summarized_results(port, expected=True, passing=False, flaky=False)
61         printer.print_unexpected_results(summary)
62         self.assertEqual(out.getvalue(), DASHED_LINE)
63
64         # test failures
65         printer, out = self.get_printer()
66         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=False)
67         printer.print_unexpected_results(summary)
68         self.assertNotEmpty(out)
69
70         # test unexpected flaky
71         printer, out = self.get_printer()
72         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=True)
73         printer.print_unexpected_results(summary)
74         self.assertNotEmpty(out)
75
76         printer, out = self.get_printer()
77         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=False)
78         printer.print_unexpected_results(summary)
79         self.assertNotEmpty(out)
80
81         printer, out = self.get_printer()
82         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=False)
83         printer.print_unexpected_results(summary)
84         self.assertNotEmpty(out)
85
86         printer, out = self.get_printer()
87         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False)
88         printer.print_unexpected_results(summary)
89         self.assertNotEmpty(out)
90
91     def test_print_results(self):
92         port = MockHost().port_factory.get('test')
93         printer, out = self.get_printer()
94         initial_results = test_run_results_unittest.run_results(port)
95         summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False)
96         details = test_run_results.RunDetails(summary['num_regressions'], summary, initial_results, None)
97         printer.print_results(details)
98         self.assertNotEmpty(out)