Skip to content

Commit 94af988

Browse files
committed
Use simple string comparison as a fallback if diff isn't available
for example, under Pyodide
1 parent f3442b7 commit 94af988

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

test/builtin/drawing/test_plot_detail.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,20 @@ def one_test(name, str_expr, vec, opt, act_dir="/tmp"):
133133
with open(act_fn, "w") as act_f:
134134
print_expression_tree(act_expr, file=act_f)
135135

136-
# use diff to compare the actual result in act_fn to reference result in ref_fn
136+
# use diff to compare the actual result in act_fn to reference result in ref_fn,
137+
# with a fallback of simple string comparison if diff is not available
137138
ref_fn = os.path.join(ref_dir, f"{name}.txt")
138-
result = subprocess.run(
139-
["diff", "-U", "5", ref_fn, act_fn], capture_output=False
140-
)
141-
assert result.returncode == 0, "reference and actual result differ"
139+
try:
140+
result = subprocess.run(
141+
["diff", "-U", "5", ref_fn, act_fn], capture_output=False
142+
)
143+
assert result.returncode == 0, "reference and actual result differ"
144+
except OSError:
145+
with open(ref_fn) as ref_f, open(act_fn) as act_f:
146+
ref_str, act_str = ref_f.read(), act_f.read()
147+
assert ref_str == act_str, "reference and actual result differ"
148+
149+
# remove /tmp file if test was successful
142150
if act_fn != ref_fn:
143151
os.remove(act_fn)
144152

0 commit comments

Comments
 (0)