Changeset 69153 in webkit


Ignore:
Timestamp:
Oct 5, 2010 3:33:18 PM (14 years ago)
Author:
tony@chromium.org
Message:

2010-10-05 Tony Chang <tony@chromium.org>

Reviewed by Ojan Vafai.

[chromium] fix image diffing in NRWT
https://bugs.webkit.org/show_bug.cgi?id=47128

  • Scripts/webkitpy/layout_tests/port/chromium.py: Stop using

NamedTemporaryFile since it doesn't work on Windows.

  • Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
Location:
trunk/WebKitTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r69151 r69153  
     12010-10-05  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Ojan Vafai.
     4
     5        [chromium] fix image diffing in NRWT
     6        https://bugs.webkit.org/show_bug.cgi?id=47128
     7
     8        * Scripts/webkitpy/layout_tests/port/chromium.py: Stop using
     9            NamedTemporaryFile since it doesn't work on Windows.
     10        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
     11
    1122010-10-05  Kenneth Russell  <kbr@google.com>
    213
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/base.py

    r69065 r69153  
    260260        if not os.path.exists(path):
    261261            return None
    262         with codecs.open(path, 'r', encoding) as file:
     262        open_mode = 'r'
     263        if encoding is None:
     264            open_mode = 'r+b'
     265        with codecs.open(path, open_mode, encoding) as file:
    263266            return file.read()
    264267
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/chromium.py

    r69075 r69153  
    135135                   diff_filename=None, tolerance=0):
    136136        executable = self._path_to_image_diff()
    137         expected_tmpfile = tempfile.NamedTemporaryFile()
    138         expected_tmpfile.write(expected_contents)
    139         actual_tmpfile = tempfile.NamedTemporaryFile()
    140         actual_tmpfile.write(actual_contents)
     137
     138        tempdir = tempfile.mkdtemp()
     139        expected_filename = os.path.join(tempdir, "expected.png")
     140        with open(expected_filename, 'w+b') as file:
     141            file.write(expected_contents)
     142        actual_filename = os.path.join(tempdir, "actual.png")
     143        with open(actual_filename, 'w+b') as file:
     144            file.write(actual_contents)
     145
    141146        if diff_filename:
    142             cmd = [executable, '--diff', expected_tmpfile.name,
    143                    actual_tmpfile.name, diff_filename]
     147            cmd = [executable, '--diff', expected_filename,
     148                   actual_filename, diff_filename]
    144149        else:
    145             cmd = [executable, expected_tmpfile.name, actual_tmpfile.name]
     150            cmd = [executable, expected_filename, actual_filename]
    146151
    147152        result = True
    148153        try:
    149             if self._executive.run_command(cmd, return_exit_code=True) == 0:
    150                 return False
     154            exit_code = self._executive.run_command(cmd, return_exit_code=True)
     155            if exit_code == 0:
     156                # The images are the same.
     157                result = False
     158            elif exit_code != 1:
     159                # Some other error occurred.
     160                raise ValueError("image diff returned an exit code of " +
     161                                 str(exit_code))
    151162        except OSError, e:
    152163            if e.errno == errno.ENOENT or e.errno == errno.EACCES:
     
    155166                raise e
    156167        finally:
    157             expected_tmpfile.close()
    158             actual_tmpfile.close()
     168            shutil.rmtree(tempdir)
    159169        return result
    160170
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py

    r69075 r69153  
    157157        self.assertTrue(port.default_configuration_called)
    158158
     159    def test_diff_image(self):
     160        class TestPort(ChromiumPortTest.TestLinuxPort):
     161            def _path_to_image_diff(self):
     162                return "/path/to/image_diff"
     163
     164        class EmptyOptions:
     165            use_drt = False
     166
     167        class MockExecute:
     168            def __init__(self, result):
     169                self._result = result
     170
     171            def run_command(self,
     172                            args,
     173                            cwd=None,
     174                            input=None,
     175                            error_handler=None,
     176                            return_exit_code=False,
     177                            return_stderr=True,
     178                            decode_output=False):
     179                return self._result
     180
     181        options = EmptyOptions()
     182        port = ChromiumPortTest.TestLinuxPort(options)
     183
     184        # Images are different.
     185        port._executive = MockExecute(0)
     186        self.assertEquals(False, port.diff_image("EXPECTED", "ACTUAL"))
     187
     188        # Images are the same.
     189        port._executive = MockExecute(1)
     190        self.assertEquals(True, port.diff_image("EXPECTED", "ACTUAL"))
     191
     192        # There was some error running image_diff.
     193        port._executive = MockExecute(2)
     194        exception_raised = False
     195        try:
     196            port.diff_image("EXPECTED", "ACTUAL")
     197        except ValueError, e:
     198            exception_raised = True
     199        self.assertTrue(exception_raised)
     200
    159201if __name__ == '__main__':
    160202    unittest.main()
  • trunk/WebKitTools/Scripts/webkitpy/layout_tests/test_types/image_diff.py

    r67974 r69153  
    105105
    106106        expected_image = port.expected_image(filename)
    107         with codecs.open(actual_filename, 'r', None) as file:
     107        with codecs.open(actual_filename, 'r+b', None) as file:
    108108            actual_image = file.read()
    109109
Note: See TracChangeset for help on using the changeset viewer.