Exemple #1
0
    def diff_image(self, expected_contents, actual_contents, tolerance):
        if tolerance != self._tolerance or (
                self._process and self._process.has_available_stdout()):
            self.stop()
        try:
            assert (expected_contents)
            assert (actual_contents)
            assert (tolerance is not None)

            if not self._process:
                self._start(tolerance)
            # Note that although we are handed 'old', 'new', ImageDiff wants 'new', 'old'.
            buffer = BytesIO()
            buffer.write(
                string_utils.encode('Content-Length: {}\n'.format(
                    len(actual_contents))))
            buffer.write(actual_contents)
            buffer.write(
                string_utils.encode('Content-Length: {}\n'.format(
                    len(expected_contents))))
            buffer.write(expected_contents)
            self._process.write(buffer.getvalue())
            return self._read()
        except IOError as exception:
            return (None, 0,
                    "Failed to compute an image diff: %s" % str(exception))
Exemple #2
0
 def test_bytesio(self):
     stream = BytesIO()
     stream.write(b'bytes data')
     self.assertEqual(stream.getvalue(), b'bytes data')