Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit 59d92b0

Browse files
committed
Add simple match_quotes test
This is much easier to debug than the big tests with real-world e-mails.
1 parent 310e2c7 commit 59d92b0

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

test/data/simple/blocks.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[text This is a standalone line.]
2+
[quote at 0-1 This is the first line.]
3+
[text This is a reply to the first line.]
4+
[quote at 2-3 This is the second line.]
5+
[text This is a reply to the second line.]
6+
[quote at 4-7 This is the third line.
7+
8+
This is the fourth line.]
9+
[text This is a reply to the third and fourth lines.]

test/data/simple/msg.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This is the first line.
2+
3+
This is the second line.
4+
5+
This is the third line.
6+
7+
This is the fourth line.

test/data/simple/reply.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This is a standalone line.
2+
3+
> This is the first line.
4+
5+
This is a reply to the first line.
6+
7+
> This is the second line.
8+
9+
This is a reply to the second line.
10+
11+
> This is the third line.
12+
>
13+
> This is the fourth line.
14+
15+
This is a reply to the third and fourth lines.

test/test_match.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from emailthreads import quotes
2+
import os
3+
import unittest
4+
from email.message import EmailMessage
5+
6+
class MatchBlocksTestCase(unittest.TestCase):
7+
def _read_file(self, name):
8+
dir_path = os.path.dirname(os.path.realpath(__file__))
9+
with open(dir_path + "/data/" + name, 'r') as f:
10+
return f.read().strip()
11+
12+
def _read_file_as_message(self, name):
13+
msg = EmailMessage()
14+
msg.set_content(self._read_file(name))
15+
return msg
16+
17+
def test_simple(self):
18+
msg = self._read_file_as_message("simple/msg.txt")
19+
reply = self._read_file_as_message("simple/reply.txt")
20+
want = self._read_file("simple/blocks.txt")
21+
22+
blocks = quotes.parse_blocks(reply)
23+
blocks = quotes.match_quotes(blocks, msg)
24+
got = "\n".join([str(block) for block in blocks])
25+
26+
self.assertEqual(got, want)
27+
28+
if __name__ == '__main__':
29+
unittest.main()

0 commit comments

Comments
 (0)