-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconftest.py
103 lines (92 loc) · 3.06 KB
/
conftest.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
#!/usr/bin/env python3
# vim: ai ts=4 sts=4 et sw=4 nu
import pytest
@pytest.fixture(scope="function")
def html_str():
"""sample HTML content with various links"""
return """<html>
<body>
<ul>
<li><a href="download/toto.pdf">PDF doc</a></li>
<li><a href="download/toto.txt">text file</a></li>
<li><a href="dest.html">HTML link</a></li>
<li><a href="no-extension">no ext link</a></li>
<li><a href="http://www.example.com/index/sample.html">external link</a></li>
<li><a href="mailto:[email protected]">e-mail link</a></li>
<li><a media="">no href link</a></li>
<object data="download/toto.jpg" width="300" height="200"></object>
<script src="assets/js/bootstrap/bootsrap.css?v=20190101"></script>
</body>
</html>
"""
@pytest.fixture(scope="function")
def html_str_cn():
"""sample HTML content with chinese characters"""
return """<html>
<body>
<ul>
<li><a href="download/toto.pdf">PDF doc in 汉字</a></li>
<li><a href="download/toto.txt">text file</a></li>
<li><a href="dest.html">HTML link</a></li>
<li><a href="no-extension">no ext link</a></li>
<li><a href="http://www.example.com/index/sample.html">external link</a></li>
<li><a href="mailto:[email protected]">e-mail link</a></li>
<li><a media="">no href link</a></li>
<object data="download/toto.jpg" width="300" height="200"></object>
<script src="assets/js/bootstrap/bootsrap.css?v=20190101"></script>
</body>
</html>
"""
@pytest.fixture(scope="function")
def html_file(tmp_path, html_str):
fpath = tmp_path / "test.html"
with open(fpath, "w") as fh:
fh.write(html_str)
return fpath
@pytest.fixture(scope="function")
def build_data(tmp_path, png_image):
fpath = tmp_path / "test.zim"
redirects_file = tmp_path / "redirects.tsv"
with open(redirects_file, "w") as fh:
fh.write(" \tAccueil\tBienvenue !!\twelcome\n")
fh.write(" \tAccueil2\t\tcommons48.png\n")
fh.write(" \timage\t\tcommons48.png\n")
build_dir = tmp_path / "build"
return {
"build_dir": build_dir,
"fpath": fpath,
"name": "test-zim",
"main_page": "welcome",
"illustration": png_image.name,
"title": "Test ZIM",
"description": "A test ZIM",
"date": None,
"language": "fra",
"creator": "test",
"publisher": "test",
"tags": ["test"],
"redirects": [("picture", "commons48.png", "")],
"redirects_file": redirects_file,
}
@pytest.fixture(scope="function")
def counters():
return {
"text/html": 3,
"application/warc-headers": 28364,
"text/html;raw=true": 6336,
"text/css": 47,
"text/javascript": 98,
"image/png": 968,
"image/webp": 24,
"application/json": 3694,
"image/gif": 10274,
"image/jpeg": 1582,
"font/woff2": 25,
"text/plain": 284,
"application/atom+xml": 247,
"application/x-www-form-urlencoded": 9,
"video/mp4": 9,
"application/x-javascript": 7,
"application/xml": 1,
"image/svg+xml": 5,
}