66import pytest
77
88from kaleido import PageGenerator
9+ from kaleido ._page_generator import DEFAULT_MATHJAX , DEFAULT_PLOTLY
910
1011# allows to create a browser pool for tests
1112pytestmark = pytest .mark .asyncio (loop_scope = "function" )
1213
1314_logger = logistro .getLogger (__name__ )
1415
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'''
1621<!DOCTYPE html>
1722<html>
1823 <head>
2530 MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
2631 </script>
2732
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>
3039 <script src="\S[^\n]*/kaleido_scopes\.js"></script>
3140 </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>
3342</html>
34- """ ) # noqa: E501 line too long
43+ """
44+ )
45+ no_imports_result_re = re .compile (no_imports_result_raw )
3546
36- all_defaults_re = re .compile (r"""
47+ all_defaults_re = re .compile (
48+ r'''
3749<!DOCTYPE html>
3850<html>
3951 <head>
4658 MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
4759 </script>
4860
61+ <script src="'''
62+ + _re_default_mathjax
63+ + r""""></script>
4964 <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>
5165 <script src="\S[^\n]*/kaleido_scopes\.js"></script>
5266 </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>
5468</html>
55- """ )
69+ """ ,
70+ )
5671
57- with_plot_result_re = re .compile (r"""
72+ with_plot_result_re = re .compile (
73+ r'''
5874<!DOCTYPE html>
5975<html>
6076 <head>
6783 MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
6884 </script>
6985
86+ <script src="'''
87+ + _re_default_mathjax
88+ + r""""></script>
7089 <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>
7290 <script src="\S[^\n]*/kaleido_scopes\.js"></script>
7391 </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>
7593</html>
76- """ )
94+ """ ,
95+ )
7796
7897without_math_result_re = re .compile (r"""
7998<!DOCTYPE html>
91110 <script src="https://with_plot" charset="utf-8"></script>
92111 <script src="\S[^\n]*/kaleido_scopes\.js"></script>
93112 </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>
95114</html>
96115""" )
97116
98- with_others_result_re = re . compile ( r"""
117+ with_others_result_raw = r"""
99118<!DOCTYPE html>
100119<html>
101120 <head>
108127 MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\)
109128 </script>
110129
111- <script src="https://with_plot" charset="utf-8"></script>
112130 <script src="https://with_mathjax"></script>
131+ <script src="https://with_plot" charset="utf-8"></script>
113132 <script src="https://1"></script>
114133 <script src="https://2"></script>
115134 <script src="\S[^\n]*/kaleido_scopes\.js"></script>
116135 </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>
118137</html>
119- """ )
138+ """
139+ with_others_result_re = re .compile (with_others_result_raw )
120140
121141
122142@pytest .mark .order (1 )
@@ -136,7 +156,11 @@ async def test_page_generator():
136156 "in the main group." ,
137157 )
138158 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+ )
140164 sys .path = old_path
141165
142166 # this imports plotly so above test must have already been done
@@ -157,7 +181,11 @@ async def test_page_generator():
157181 mathjax = "https://with_mathjax" ,
158182 others = ["https://1" , "https://2" ],
159183 ).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+ )
161189
162190
163191# test others
0 commit comments