buildbot_results_unittest.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. import StringIO
  30. import unittest2 as unittest
  31. from webkitpy.common.host_mock import MockHost
  32. from webkitpy.layout_tests.models import test_expectations
  33. from webkitpy.layout_tests.models import test_failures
  34. from webkitpy.layout_tests.models import test_run_results
  35. from webkitpy.layout_tests.models import test_run_results
  36. from webkitpy.layout_tests.models import test_run_results_unittest
  37. from webkitpy.layout_tests.views import buildbot_results
  38. class BuildBotPrinterTests(unittest.TestCase):
  39. def assertEmpty(self, stream):
  40. self.assertFalse(stream.getvalue())
  41. def assertNotEmpty(self, stream):
  42. self.assertTrue(stream.getvalue())
  43. def get_printer(self):
  44. stream = StringIO.StringIO()
  45. printer = buildbot_results.BuildBotPrinter(stream, debug_logging=True)
  46. return printer, stream
  47. def test_print_unexpected_results(self):
  48. port = MockHost().port_factory.get('test')
  49. printer, out = self.get_printer()
  50. # test everything running as expected
  51. DASHED_LINE = "-" * 78 + "\n"
  52. summary = test_run_results_unittest.summarized_results(port, expected=True, passing=False, flaky=False)
  53. printer.print_unexpected_results(summary)
  54. self.assertEqual(out.getvalue(), DASHED_LINE)
  55. # test failures
  56. printer, out = self.get_printer()
  57. summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=False)
  58. printer.print_unexpected_results(summary)
  59. self.assertNotEmpty(out)
  60. # test unexpected flaky
  61. printer, out = self.get_printer()
  62. summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=True)
  63. printer.print_unexpected_results(summary)
  64. self.assertNotEmpty(out)
  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. printer, out = self.get_printer()
  70. summary = test_run_results_unittest.summarized_results(port, expected=False, passing=False, flaky=False)
  71. printer.print_unexpected_results(summary)
  72. self.assertNotEmpty(out)
  73. printer, out = self.get_printer()
  74. summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False)
  75. printer.print_unexpected_results(summary)
  76. self.assertNotEmpty(out)
  77. def test_print_results(self):
  78. port = MockHost().port_factory.get('test')
  79. printer, out = self.get_printer()
  80. initial_results = test_run_results_unittest.run_results(port)
  81. summary = test_run_results_unittest.summarized_results(port, expected=False, passing=True, flaky=False)
  82. details = test_run_results.RunDetails(summary['num_regressions'], summary, initial_results, None)
  83. printer.print_results(details)
  84. self.assertNotEmpty(out)