Skip to content

Commit aebebe9

Browse files
committed
make tests more lenient
1 parent 688d877 commit aebebe9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tests/test_utilities.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,13 @@ def test_write_png_rgb():
187187
)
188188
def test_linear_gradient(hex_list: List[str], n_colors: int, expected_output: List[str]):
189189
result = ut.linear_gradient(hex_list, n_colors)
190-
assert result == expected_output
190+
assert len(result) == len(expected_output), "Output length mismatch"
191+
192+
# because we rewrote this function, we allow a difference of 1 between the old and the new version
193+
tolerance = 1
194+
for actual, expected in zip(result, expected_output):
195+
r1, g1, b1 = (int(actual[i:i+2], 16) for i in (1, 3, 5))
196+
r2, g2, b2 = (int(expected[i:i+2], 16) for i in (1, 3, 5))
197+
if not all(abs(a - b) <= tolerance for a, b in zip((r1, g1, b1), (r2, g2, b2))):
198+
# to get a nice output, assert the full array when we spot a failure
199+
assert result == expected_output

0 commit comments

Comments
 (0)