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

Allow "None" for formatting - discards output #97

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
42 changes: 25 additions & 17 deletions chispa/rows_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ def assert_basic_rows_equality(rows1, rows2, underline_cells=False, formats=Defa
all_rows_equal = True
for r1, r2 in zipped:
if r1 is None and r2 is not None:
t.add_row([None, format_string(r2, formats.mismatched_rows)])
if formats.mismatched_rows is not None:
t.add_row([None, format_string(r2, formats.mismatched_rows)])
all_rows_equal = False
elif r1 is not None and r2 is None:
t.add_row([format_string(r1, formats.mismatched_rows), None])
if formats.mismatched_rows is not None:
t.add_row([format_string(r1, formats.mismatched_rows), None])
all_rows_equal = False
else:
r_zipped = list(six.moves.zip_longest(r1.__fields__, r2.__fields__))
r1_string = []
r2_string = []
for r1_field, r2_field in r_zipped:
if r1[r1_field] != r2[r2_field]:
all_rows_equal = False
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.mismatched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.mismatched_cells))
if formats.mismatched_cells is not None:
all_rows_equal = False
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.mismatched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.mismatched_cells))
else:
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.matched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.matched_cells))
if formats.matched_cells is not None:
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.matched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.matched_cells))
r1_res = ", ".join(r1_string)
r2_res = ", ".join(r2_string)

Expand All @@ -49,26 +53,30 @@ def assert_generic_rows_equality(rows1, rows2, row_equality_fun, row_equality_fu
for r1, r2 in zipped:
# rows are not equal when one is None and the other isn't
if (r1 is not None and r2 is None) or (r2 is not None and r1 is None):
all_rows_equal = False
t.add_row([format_string(r1, formats.mismatched_rows), format_string(r2, formats.mismatched_rows)])
if formats.matched_rows is not None:
all_rows_equal = False
t.add_row([format_string(r1, formats.mismatched_rows), format_string(r2, formats.mismatched_rows)])
# rows are equal
elif row_equality_fun(r1, r2, *row_equality_fun_args):
r1_string = ", ".join(map(lambda f: f"{f}={r1[f]}", r1.__fields__))
r2_string = ", ".join(map(lambda f: f"{f}={r2[f]}", r2.__fields__))
t.add_row([format_string(r1_string, formats.matched_rows), format_string(r2_string, formats.matched_rows)])
if formats.matched_rows is not None:
r1_string = ", ".join(map(lambda f: f"{f}={r1[f]}", r1.__fields__))
r2_string = ", ".join(map(lambda f: f"{f}={r2[f]}", r2.__fields__))
t.add_row([format_string(r1_string, formats.matched_rows), format_string(r2_string, formats.matched_rows)])
# otherwise, rows aren't equal
else:
r_zipped = list(six.moves.zip_longest(r1.__fields__, r2.__fields__))
r1_string = []
r2_string = []
for r1_field, r2_field in r_zipped:
if r1[r1_field] != r2[r2_field]:
all_rows_equal = False
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.mismatched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.mismatched_cells))
if formats.matched_cells is not None:
all_rows_equal = False
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.mismatched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.mismatched_cells))
else:
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.matched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.matched_cells))
if formats.matched_cells is not None:
r1_string.append(format_string(f"{r1_field}={r1[r1_field]}", formats.matched_cells))
r2_string.append(format_string(f"{r2_field}={r2[r2_field]}", formats.matched_cells))
r1_res = ", ".join(r1_string)
r2_res = ", ".join(r2_string)

Expand Down