aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-06-11 10:06:07 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-06-11 10:06:07 -0400
commitd8a906e53110721efb94b09776a96b22a06d5148 (patch)
tree3248cc38e76870e6ee9d9ba21577bb3e3750a900
parent0a1776fc9fdf8e03757f2ccc08f5267489472432 (diff)
downloadb4-d8a906e53110721efb94b09776a96b22a06d5148.tar.gz
Test to make sure mbox files contain unixfrom
Start a test suite for generated mbox files. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--tests/test___init__.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/test___init__.py b/tests/test___init__.py
index 5a09584..d78667e 100644
--- a/tests/test___init__.py
+++ b/tests/test___init__.py
@@ -1,5 +1,7 @@
import pytest # noqa
import b4
+import re
+import os
@pytest.mark.parametrize('source,expected', [
@@ -13,3 +15,36 @@ def test_check_gpg_status(source, expected):
with open(f'tests/samples/gpg-{source}.txt', 'r') as fh:
status = fh.read()
assert b4.check_gpg_status(status) == expected
+
+
+@pytest.mark.parametrize('source,regex,flags,ismbox', [
+ (None, r'^From git@z ', 0, False),
+ (None, r'\n\nFrom git@z ', 0, False),
+])
+def test_save_git_am_mbox(tmpdir, source, regex, flags, ismbox):
+ import re
+ if source is not None:
+ if ismbox:
+ import mailbox
+ mbx = mailbox.mbox(f'tests/samples/{source}.txt')
+ msgs = list(mbx)
+ else:
+ import email
+ with open(f'tests/samples/{source}.txt', 'rb') as fh:
+ msg = email.message_from_binary_file(fh)
+ msgs = [msg]
+ else:
+ import email.message
+ msgs = list()
+ for x in range(0, 3):
+ msg = email.message.EmailMessage()
+ msg.set_payload(f'Hello world {x}\n')
+ msg['Subject'] = f'Hello world {x}'
+ msg['From'] = f'Me{x} <me{x}@foo.bar>'
+ msgs.append(msg)
+ dest = os.path.join(tmpdir, 'out')
+ with open(dest, 'w') as fh:
+ b4.save_git_am_mbox(msgs, fh)
+ with open(dest, 'r') as fh:
+ res = fh.read()
+ assert re.search(regex, res, flags=flags)