test_result_writer_unittest.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2011 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. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  14. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  15. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  18. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  19. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. import unittest2 as unittest
  25. from webkitpy.common.host_mock import MockHost
  26. from webkitpy.layout_tests.controllers import test_result_writer
  27. from webkitpy.layout_tests.models import test_failures
  28. from webkitpy.port.driver import DriverOutput
  29. from webkitpy.port.test import TestPort
  30. class TestResultWriterTest(unittest.TestCase):
  31. def test_reftest_diff_image(self):
  32. """A write_test_result should call port.diff_image with tolerance=0 in case of FailureReftestMismatch."""
  33. used_tolerance_values = []
  34. class ImageDiffTestPort(TestPort):
  35. def diff_image(self, expected_contents, actual_contents, tolerance=None):
  36. used_tolerance_values.append(tolerance)
  37. return (True, 1, None)
  38. host = MockHost()
  39. port = ImageDiffTestPort(host)
  40. test_name = 'failures/unexpected/reftest.html'
  41. test_reference_file = host.filesystem.join(port.layout_tests_dir(), 'failures/unexpected/reftest-expected.html')
  42. driver_output1 = DriverOutput('text1', 'image1', 'imagehash1', 'audio1')
  43. driver_output2 = DriverOutput('text2', 'image2', 'imagehash2', 'audio2')
  44. failures = [test_failures.FailureReftestMismatch(test_reference_file)]
  45. test_result_writer.write_test_result(host.filesystem, ImageDiffTestPort(host), port.results_directory(), test_name,
  46. driver_output1, driver_output2, failures)
  47. self.assertEqual([0], used_tolerance_values)