webkitpy: Handle case where stdout and stderr don't accept unicode
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 00:12:06 +0000 (00:12 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 00:12:06 +0000 (00:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192775
<rdar://problem/46497303>

Reviewed by Stephanie Lewis.

* Scripts/webkitpy/layout_tests/views/metered_stream.py:
(MeteredStream.write): If unicode cannot be written to the stream, replace unicode
characters with '?'.
* Scripts/webkitpy/layout_tests/views/metered_stream_unittest.py:
(RegularTest.test_stream_with_encoding):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239303 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/layout_tests/views/metered_stream.py
Tools/Scripts/webkitpy/layout_tests/views/metered_stream_unittest.py

index e7c0324..15e8644 100644 (file)
@@ -1,3 +1,17 @@
+2018-12-17  Jonathan Bedard  <jbedard@apple.com>
+
+        webkitpy: Handle case where stdout and stderr don't accept unicode
+        https://bugs.webkit.org/show_bug.cgi?id=192775
+        <rdar://problem/46497303>
+
+        Reviewed by Stephanie Lewis.
+
+        * Scripts/webkitpy/layout_tests/views/metered_stream.py:
+        (MeteredStream.write): If unicode cannot be written to the stream, replace unicode
+        characters with '?'.
+        * Scripts/webkitpy/layout_tests/views/metered_stream_unittest.py:
+        (RegularTest.test_stream_with_encoding):
+
 2018-12-17  Daniel Bates  <dabates@apple.com>
 
         Support concatenating StringView with other string types
index b0b2b04..95aa13c 100644 (file)
@@ -107,7 +107,16 @@ class MeteredStream(object):
         if not self._isatty or self._verbose:
             txt = self._ensure_newline(txt)
 
-        self._stream.write(timestamp_string + txt)
+        try:
+            self._stream.write(timestamp_string + txt)
+        except UnicodeEncodeError:
+            output = ''
+            for c in timestamp_string + txt:
+                try:
+                    output += '{}'.format(c)
+                except UnicodeEncodeError:
+                    output += '?'
+            self._stream.write(output)
 
     def writeln(self, txt, now=None, pid=None):
         self.write(self._ensure_newline(txt), now, pid)
index 85ece6b..07662bc 100644 (file)
@@ -117,6 +117,24 @@ class RegularTest(unittest.TestCase):
         self.logger.info('‘example’')
         self.assertEqual(self.buflist[-1][-14:], '‘example’\n')
 
+    def test_stream_with_encoding(self):
+        class AsciiStream(StringIO.StringIO):
+            def write(self, s):
+                return StringIO.StringIO.write(self, '{}'.format(s))
+
+        stream = AsciiStream()
+
+        logger = logging.getLogger(__name__)
+        logger.setLevel(logging.DEBUG)
+        logger.propagate = False
+
+        try:
+            meter = MeteredStream(stream, self.verbose, logger, self.time_fn, 8675, print_timestamps=self.print_timestamps)
+            self.logger.info(u'\u2713')
+            self.assertEqual(stream.buflist[-1][-2:], '?\n')
+        finally:
+            meter.cleanup()
+
 
 class TtyTest(RegularTest):
     verbose = False