6
6
import pytest
7
7
8
8
from kaleido import PageGenerator
9
+ from kaleido ._page_generator import DEFAULT_MATHJAX , DEFAULT_PLOTLY
9
10
10
11
# allows to create a browser pool for tests
11
12
pytestmark = pytest .mark .asyncio (loop_scope = "function" )
12
13
13
14
_logger = logistro .getLogger (__name__ )
14
15
15
- no_imports_result_re = re .compile (r"""
16
+ _re_default_mathjax = re .escape (DEFAULT_MATHJAX )
17
+ _re_default_plotly = re .escape (DEFAULT_PLOTLY )
18
+
19
+ no_imports_result_raw = (
20
+ r'''
16
21
<!DOCTYPE html>
17
22
<html>
18
23
<head>
25
30
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
26
31
</script>
27
32
28
- <script src="https://cdn\.plot\.ly/plotly-2\.35\.2\.js" charset="utf-8"></script>
29
- <script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script>
33
+ <script src="'''
34
+ + _re_default_mathjax
35
+ + r'''"></script>
36
+ <script src="'''
37
+ + _re_default_plotly
38
+ + r"""" charset="utf\-8"></script>
30
39
<script src="\S[^\n]*/kaleido_scopes\.js"></script>
31
40
</head>
32
- <body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img ></body>
41
+ <body style="{margin: 0; padding: 0;}"><img id="kaleido\ -image" / ></body>
33
42
</html>
34
- """ ) # noqa: E501 line too long
43
+ """
44
+ )
45
+ no_imports_result_re = re .compile (no_imports_result_raw )
35
46
36
- all_defaults_re = re .compile (r"""
47
+ all_defaults_re = re .compile (
48
+ r'''
37
49
<!DOCTYPE html>
38
50
<html>
39
51
<head>
46
58
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
47
59
</script>
48
60
61
+ <script src="'''
62
+ + _re_default_mathjax
63
+ + r""""></script>
49
64
<script src="\S[^\n]*/package_data/plotly\.min\.js" charset="utf-8"></script>
50
- <script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script>
51
65
<script src="\S[^\n]*/kaleido_scopes\.js"></script>
52
66
</head>
53
- <body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img ></body>
67
+ <body style="{margin: 0; padding: 0;}"><img id="kaleido-image" / ></body>
54
68
</html>
55
- """ )
69
+ """ ,
70
+ )
56
71
57
- with_plot_result_re = re .compile (r"""
72
+ with_plot_result_re = re .compile (
73
+ r'''
58
74
<!DOCTYPE html>
59
75
<html>
60
76
<head>
67
83
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
68
84
</script>
69
85
86
+ <script src="'''
87
+ + _re_default_mathjax
88
+ + r""""></script>
70
89
<script src="https://with_plot" charset="utf-8"></script>
71
- <script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script>
72
90
<script src="\S[^\n]*/kaleido_scopes\.js"></script>
73
91
</head>
74
- <body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img ></body>
92
+ <body style="{margin: 0; padding: 0;}"><img id="kaleido-image" / ></body>
75
93
</html>
76
- """ )
94
+ """ ,
95
+ )
77
96
78
97
without_math_result_re = re .compile (r"""
79
98
<!DOCTYPE html>
91
110
<script src="https://with_plot" charset="utf-8"></script>
92
111
<script src="\S[^\n]*/kaleido_scopes\.js"></script>
93
112
</head>
94
- <body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img ></body>
113
+ <body style="{margin: 0; padding: 0;}"><img id="kaleido-image" / ></body>
95
114
</html>
96
115
""" )
97
116
98
- with_others_result_re = re . compile ( r"""
117
+ with_others_result_raw = r"""
99
118
<!DOCTYPE html>
100
119
<html>
101
120
<head>
108
127
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
109
128
</script>
110
129
111
- <script src="https://with_plot" charset="utf-8"></script>
112
130
<script src="https://with_mathjax"></script>
131
+ <script src="https://with_plot" charset="utf-8"></script>
113
132
<script src="https://1"></script>
114
133
<script src="https://2"></script>
115
134
<script src="\S[^\n]*/kaleido_scopes\.js"></script>
116
135
</head>
117
- <body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img ></body>
136
+ <body style="{margin: 0; padding: 0;}"><img id="kaleido-image" / ></body>
118
137
</html>
119
- """ )
138
+ """
139
+ with_others_result_re = re .compile (with_others_result_raw )
120
140
121
141
122
142
@pytest .mark .order (1 )
@@ -136,7 +156,11 @@ async def test_page_generator():
136
156
"in the main group." ,
137
157
)
138
158
no_imports = PageGenerator ().generate_index ()
139
- assert no_imports_result_re .findall (no_imports )
159
+ assert no_imports_result_re .findall (no_imports ), (
160
+ f"{ len (no_imports_result_raw )} : { no_imports_result_raw } "
161
+ "\n "
162
+ f"{ len (no_imports )} : { no_imports } "
163
+ )
140
164
sys .path = old_path
141
165
142
166
# this imports plotly so above test must have already been done
@@ -157,7 +181,11 @@ async def test_page_generator():
157
181
mathjax = "https://with_mathjax" ,
158
182
others = ["https://1" , "https://2" ],
159
183
).generate_index ()
160
- assert with_others_result_re .findall (with_others )
184
+ assert with_others_result_re .findall (with_others ), (
185
+ f"{ len (with_others_result_raw )} : { with_others_result_raw } "
186
+ "\n "
187
+ f"{ len (with_others )} : { with_others } "
188
+ )
161
189
162
190
163
191
# test others
0 commit comments