diff --git a/lib/matplotlib/testing/compare.py b/lib/matplotlib/testing/compare.py index afb7edb8c828..48feb89f3f51 100644 --- a/lib/matplotlib/testing/compare.py +++ b/lib/matplotlib/testing/compare.py @@ -124,7 +124,7 @@ def _read_until(self, terminator): raise _ConverterError buf.extend(c) if buf.endswith(terminator): - return bytes(buf[:-len(terminator)]) + return bytes(buf) class _GSConverter(_Converter): @@ -154,15 +154,16 @@ def encode_and_escape(name): + b") run flush\n") self._proc.stdin.flush() # GS> if nothing left on the stack; GS if n items left on the stack. - err = self._read_until(b"GS") - stack = self._read_until(b">") + err = self._read_until((b"GS<", b"GS>")) + stack = "" + if err.endswith(b"GS<"): + stack = self._read_until(b">") if stack or not os.path.exists(dest): - stack_size = int(stack[1:]) if stack else 0 + stack_size = int(stack[:-1]) if stack else 0 self._proc.stdin.write(b"pop\n" * stack_size) # Using the systemencoding should at least get the filenames right. raise ImageComparisonFailure( - (err + b"GS" + stack + b">") - .decode(sys.getfilesystemencoding(), "replace")) + (err + stack).decode(sys.getfilesystemencoding(), "replace")) class _SVGConverter(_Converter):