-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_extract.py
73 lines (61 loc) · 1.57 KB
/
test_extract.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
from extract import *
from pathlib import Path
from pytest import fixture
from tempfile import TemporaryDirectory
TEST_MHT='sample.mhtml'
TEST_URI='cid:[email protected]'
TEST_EXT='618b43ee95de.css'
def filename():
file_path = Path(TEST_URI.split(':')[1])
assert MAGIC_EXT in str(file_path)
file_name = extract_filename(file_path, ['text', 'css'])
return file_name
@fixture
def ex():
ex = Extract(TEST_MHT)
return ex
@fixture
def tmp():
with TemporaryDirectory() as tmpdirname:
yield tmpdirname
def test_ex_html(ex):
assert ex
assert ex.html
assert '_code' in str(ex)
def test_ex_save(ex, tmp):
assert ex.folder =='reportgen'
root = ex.save('/tmp')
assert root
assert root.exists()
assert (root / 'index.html').exists()
assert (root / filename()).exists()
def test_filename(ex):
file_name = filename()
local_file = f'./{file_name}'
assert TEST_EXT in local_file
assert TEST_URI not in str(ex)
assert file_name in str(ex)
def test_ex_attrs(ex):
assert ex.attrs
keys = ex.files()
file_name = keys[0]
assert 'css' in file_name
attrs = ex.attrs.get(file_name)
assert attrs
assert MAGIC_EXT in attrs['uri']
assert MAGIC_EXT not in file_name
assert '.css' in file_name
def test_ex_suffix(ex):
"""every filename has a suffix"""
for key in ex.files():
suffix = Path(key).suffix
assert suffix
def test_ex_update_link(ex):
keys = ex.files()
file_name = keys[0]
attrs = ex.attrs.get(file_name)
uri = attrs['uri']
assert uri not in str(ex)
def test_unquote(ex):
assert '=3D"' in ex.raw_html
assert '=3D"' not in ex.html