Skip to content

Commit

Permalink
test: rewrite test case for better failure message
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-W committed Apr 6, 2024
1 parent a438e75 commit 65373be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/data/attachment-file/attachment01.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst.
Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst.
8 changes: 4 additions & 4 deletions tests/test_render_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_rendered_mail_no_separator(all_mails_base_no_separator):

assert result.exit_code == 0
assert len(all_mails_base_no_separator) == len(all_mails_target)
assert compare_rendered_mail_all(
compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_no_separator,
target_prefix=path_mails_to_send_no_separator,
Expand All @@ -68,7 +68,7 @@ def test_rendered_mail_no_separator_and_csv(all_mails_base_no_separatorr_and_csv

assert result.exit_code == 0
assert len(all_mails_base_no_separatorr_and_csv) == len(all_mails_target)
assert compare_rendered_mail_all(
compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_no_separator_and_csv,
target_prefix=path_mails_to_send_no_separator_and_csv,
Expand All @@ -95,7 +95,7 @@ def test_rendered_mail_with_separator_dash(all_mails_base_with_separator):

assert result.exit_code == 0
assert len(all_mails_base_with_separator) == len(all_mails_target)
assert compare_rendered_mail_all(
compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_with_separator,
target_prefix=path_mails_to_send_with_separator,
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_rendered_mail_with_separator_dash_and_csv(

assert result.exit_code == 0
assert len(all_mails_base_with_separator_and_csv) == len(all_mails_target)
assert compare_rendered_mail_all(
compare_rendered_mail_all(
all_mails_target,
base_prefix=path_pre_rendered_mails_with_separator_and_csv,
target_prefix=path_mails_to_send_with_separator_and_csv,
Expand Down
13 changes: 5 additions & 8 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import filecmp
import json
import os
import pickle
Expand Down Expand Up @@ -26,16 +25,14 @@ def compare_rendered_mail_all(
targets, base_prefix="./data", target_prefix="../examples"
):
for mail_name in targets:
if not compare_rendered_mail(
compare_rendered_mail(
"/".join((base_prefix, mail_name)), "/".join((target_prefix, mail_name))
):
return False

return True
)


def compare_rendered_mail(base, target):
return filecmp.cmp(base, target, shallow=False)
def compare_rendered_mail(base: str, target: str) -> None:
with open(base) as base_file, open(target) as target_file:
assert base_file.read().strip() == target_file.read().strip()


def get_mail_config():
Expand Down

0 comments on commit 65373be

Please sign in to comment.