Skip to content

Commit 93d9c5d

Browse files
committed
Re-add helper functions to assert equality of FSArray instances
1 parent 742a4ca commit 93d9c5d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

curtsies/formatstringarray.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,37 @@ def simple_format(x):
297297
return "\n".join(actualize(l) for l in x)
298298

299299

300+
def assertFSArraysEqual(a, b):
301+
# type: (FSArray, FSArray) -> None
302+
assert isinstance(a, FSArray)
303+
assert isinstance(b, FSArray)
304+
assert (
305+
a.width == b.width and a.hight == b.hight
306+
), f"fsarray dimensions do not match: {a.shape} {b.shape}"
307+
for i, (a_row, b_row) in enumerate(zip(a, b)):
308+
assert a_row == b_row, "FSArrays differ first on line {}:\n{}".format(
309+
i, FSArray.diff(a, b)
310+
)
311+
312+
313+
def assertFSArraysEqualIgnoringFormatting(a, b):
314+
# type: (FSArray, FSArray) -> None
315+
"""Also accepts arrays of strings"""
316+
assert len(a) == len(b), "fsarray heights do not match: %s %s \n%s \n%s" % (
317+
len(a),
318+
len(b),
319+
simple_format(a),
320+
simple_format(b),
321+
)
322+
for i, (a_row, b_row) in enumerate(zip(a, b)):
323+
a_row = a_row.s if isinstance(a_row, FmtStr) else a_row
324+
b_row = b_row.s if isinstance(b_row, FmtStr) else b_row
325+
assert a_row == b_row, "FSArrays differ first on line %s:\n%s" % (
326+
i,
327+
FSArray.diff(a, b, ignore_formatting=True),
328+
)
329+
330+
300331
if __name__ == "__main__":
301332
a = FSArray(3, 14, bg="blue")
302333
a[0:2, 5:11] = cast(

0 commit comments

Comments
 (0)