Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support binary output diffs #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions rere.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import sys
import subprocess
from difflib import unified_diff
from difflib import diff_bytes, unified_diff
from typing import List, BinaryIO, Tuple, Optional

def read_blob_field(f: BinaryIO, name: bytes) -> bytes:
Expand Down Expand Up @@ -143,19 +143,19 @@ def load_snapshots(file_path: str) -> list[dict]:
print(f" ACTUAL: {process.returncode}")
failed = True
if process.stdout != snapshot['stdout']:
# TODO: support binary outputs
a = snapshot['stdout'].decode('utf-8').splitlines(keepends=True)
b = process.stdout.decode('utf-8').splitlines(keepends=True)
a = snapshot['stdout'].splitlines(keepends=True)
b = process.stdout.splitlines(keepends=True)
print(f"UNEXPECTED: stdout")
for line in unified_diff(a, b, fromfile="expected", tofile="actual"):
print(line, end='')
for line in diff_bytes(unified_diff, a, b, fromfile=b"expected", tofile=b"actual"):
# See https://docs.python.org/3/library/codecs.html#error-handlers
print(line.decode("utf-8", errors='backslashreplace'), end='')
failed = True
if process.stderr != snapshot['stderr']:
a = snapshot['stderr'].decode('utf-8').splitlines(keepends=True)
b = process.stderr.decode('utf-8').splitlines(keepends=True)
a = snapshot['stderr'].splitlines(keepends=True)
b = process.stderr.splitlines(keepends=True)
print(f"UNEXPECTED: stderr")
for line in unified_diff(a, b, fromfile="expected", tofile="actual"):
print(line, end='')
for line in diff_bytes(unified_diff, a, b, fromfile=b"expected", tofile=b"actual"):
print(line.decode("utf-8", errors='backslashreplace'), end='')
failed = True
if failed:
exit(1)
Expand Down