Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / 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         output = out.getvalue()
90         self.assertTrue(output)
91         self.assertTrue(output.find('Skip') == -1)
92
93     def test_print_results(self):
94         port = MockHost().port_factory.get('test')
95         printer, out = self.get_printer()
96         initial_results = test_run_results_unittest.run_results(port)
97         full_summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False)
98         failing_summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False, only_include_failing=True)
99         details = test_run_results.RunDetails(failing_summary['num_regressions'], full_summary, failing_summary, initial_results, None)
100         printer.print_results(details)
101         self.assertTrue(out.getvalue().find('but passed') != -1)