-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_lorifier.py
107 lines (93 loc) · 3.04 KB
/
test_lorifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import lorifier
import os
import subprocess
import time
import urllib
def test_sample_1():
""" Just a typical example email """
out = subprocess.run(
"cat samples/1.email | ./lorifier.py",
shell=True,
check=True,
capture_output=True,
)
assert len(out.stderr) == 0
lines = [
"\nX-Date: ",
"\nX-URI: https://lore.kernel.org/lkml/[email protected]\n",
]
for line in lines:
assert line in out.stdout.decode("utf-8")
def test_sample_2():
""" A typical example, with emoji in body """
out = subprocess.run(
"cat samples/2.email | ./lorifier.py",
shell=True,
check=True,
capture_output=True,
)
assert len(out.stderr) == 0
lines = [
"\nX-Date: ",
"\nX-URI: https://lore.kernel.org/lkml/[email protected]\n",
"\nHello,\n",
"\nHere is some emoji! 🍌🍌🚀🚀\n",
]
for line in lines:
assert line in out.stdout.decode("utf-8")
def test_sample_3():
""" UTF-8 headers """
out = subprocess.run(
"cat samples/3.email | ./lorifier.py",
shell=True,
check=True,
capture_output=True,
)
assert len(out.stderr) == 0
lines = [
"\nX-Date: ",
"\nX-URI: https://lore.kernel.org/lkml/CADYN=9LEVUgz_ou6kWrXZGBpUZ5Ti7BB+0Uxp1NtP18BJDVHCg@mail.gmail.com\n",
"\nCc: =?UTF-8?B?RGFuaWVsIETDrWF6?= <[email protected]>,\n",
'\n "open list:KERNEL SELFTEST FRAMEWORK" \n',
]
for line in lines:
assert line in out.stdout.decode("utf-8")
def test_get_lorifier_list_fresh(mocker):
with open("samples/lists.txt") as f:
lists = f.read()
with open(".in", "w") as f:
f.write(lists)
mocker.patch("urllib.request.urlretrieve")
lore_lists = lorifier.muttemail._get_lorifier_list(
cache_file=os.path.abspath(".in")
)
urllib.request.urlretrieve.assert_not_called()
assert len(lore_lists) == 29
for line in lists.splitlines():
(key, value) = line.split(": ")
assert lore_lists[key] == value
os.remove(".in")
def test_get_lorifier_list_old(mocker):
with open("samples/lists.txt") as f:
lists = f.read()
with open(".in", "w") as f:
f.write(lists)
os.utime(".in", (time.time(), time.time() - 604800))
mocker.patch("urllib.request.urlretrieve")
lorifier.muttemail._get_lorifier_list(
url="https://lore.kernel.org/lists.txt",
cache_file=os.path.abspath(".in"),
cache_ttl=86400,
)
urllib.request.urlretrieve.assert_called_once_with(
"https://lore.kernel.org/lists.txt", os.path.abspath(".in")
)
os.remove(".in")
def test_get_lorifier_list_first_run(mocker):
mocker.patch("urllib.request.urlretrieve")
lorifier.muttemail._get_lorifier_list(
url="https://lore.kernel.org/lists.txt", cache_file=os.path.abspath(".in")
)
urllib.request.urlretrieve.assert_called_once_with(
"https://lore.kernel.org/lists.txt", os.path.abspath(".in")
)