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