-
Notifications
You must be signed in to change notification settings - Fork 47
Andrew/mathjax #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Andrew/mathjax #393
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,36 @@ | ||
<!DOCTYPE html> | ||
|
||
<!-- | ||
THIS FILE IS AN EXAMPLE, IT IS GENERATED AUTOMATICALLY AT RUNTIME | ||
TO ENSURE FULLY UPDATED RESOURCES | ||
--> | ||
|
||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Kaleido-fier</title> | ||
|
||
<script> | ||
window.PlotlyConfig = {MathJaxConfig: 'local'}; | ||
// Plotly won't fetch MathJax; you'll provide it | ||
window.PlotlyConfig = { MathJaxConfig: 'local' }; | ||
</script> | ||
|
||
<!-- Only your one tweak; preset handles TeX+AMS+SVG --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||
<script type="text/x-mathjax-config"> | ||
MathJax.Hub.Config({ "SVG": {blacker: 0 }}); | ||
MathJax.Hub.Config({ | ||
SVG: { blacker: 0 } | ||
}); | ||
</script> | ||
<script src="https://cdn.plot.ly/plotly-2.35.3.min.js" charset="utf-8"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js"></script> | ||
|
||
<!-- Preset loads TeX input, AMS, and SVG output --> | ||
<script src="/vendor/mathjax/2.7.5/MathJax.js?config=TeX-AMS_SVG"></script> | ||
|
||
<!-- Plotly after MathJax (since we're in 'local' mode) --> | ||
<script src="https://cdn.plot.ly/plotly-2.35.3.min.js"></script> | ||
|
||
<script src="./kaleido_scopes.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="margin:0; padding:0;"> | ||
<img id="kaleido-image" /> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,18 @@ | |
import pytest | ||
|
||
from kaleido import PageGenerator | ||
from kaleido._page_generator import DEFAULT_MATHJAX, DEFAULT_PLOTLY | ||
|
||
# allows to create a browser pool for tests | ||
pytestmark = pytest.mark.asyncio(loop_scope="function") | ||
|
||
_logger = logistro.getLogger(__name__) | ||
|
||
no_imports_result_re = re.compile(r""" | ||
_re_default_mathjax = re.escape(DEFAULT_MATHJAX) | ||
_re_default_plotly = re.escape(DEFAULT_PLOTLY) | ||
|
||
no_imports_result_raw = ( | ||
r''' | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
@@ -25,15 +30,22 @@ | |
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) | ||
</script> | ||
|
||
<script src="https://cdn\.plot\.ly/plotly-2\.35\.2\.js" charset="utf-8"></script> | ||
<script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script> | ||
<script src="''' | ||
+ _re_default_mathjax | ||
+ r'''"></script> | ||
<script src="''' | ||
+ _re_default_plotly | ||
+ r"""" charset="utf\-8"></script> | ||
<script src="\S[^\n]*/kaleido_scopes\.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido\-image" /></body> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the backslash in the id? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super happy with how convoluted these tests are and I'm thinking about doing them line by line. In certain instances, '-' is a reserved character in regex. In this particular instance, it doesn't need to be, but can be, escaped. There's a run on testing today, this whole strategy might change in another PR. |
||
</html> | ||
""") # noqa: E501 line too long | ||
""" | ||
) | ||
no_imports_result_re = re.compile(no_imports_result_raw) | ||
|
||
all_defaults_re = re.compile(r""" | ||
all_defaults_re = re.compile( | ||
r''' | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
@@ -46,15 +58,19 @@ | |
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) | ||
</script> | ||
|
||
<script src="''' | ||
+ _re_default_mathjax | ||
+ r""""></script> | ||
<script src="\S[^\n]*/package_data/plotly\.min\.js" charset="utf-8"></script> | ||
<script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script> | ||
<script src="\S[^\n]*/kaleido_scopes\.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image" /></body> | ||
</html> | ||
""") | ||
""", | ||
) | ||
|
||
with_plot_result_re = re.compile(r""" | ||
with_plot_result_re = re.compile( | ||
r''' | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
@@ -67,13 +83,16 @@ | |
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) | ||
</script> | ||
|
||
<script src="''' | ||
+ _re_default_mathjax | ||
+ r""""></script> | ||
<script src="https://with_plot" charset="utf-8"></script> | ||
<script src="https://cdn\.jsdelivr\.net/npm/mathjax@3\.2\.2/es5/tex-svg\.js"></script> | ||
<script src="\S[^\n]*/kaleido_scopes\.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image" /></body> | ||
</html> | ||
""") | ||
""", | ||
) | ||
|
||
without_math_result_re = re.compile(r""" | ||
<!DOCTYPE html> | ||
|
@@ -91,11 +110,11 @@ | |
<script src="https://with_plot" charset="utf-8"></script> | ||
<script src="\S[^\n]*/kaleido_scopes\.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image" /></body> | ||
</html> | ||
""") | ||
|
||
with_others_result_re = re.compile(r""" | ||
with_others_result_raw = r""" | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
|
@@ -108,15 +127,16 @@ | |
MathJax\.Hub\.Config\({ "SVG": { blacker: 0 }}\) | ||
</script> | ||
|
||
<script src="https://with_plot" charset="utf-8"></script> | ||
<script src="https://with_mathjax"></script> | ||
<script src="https://with_plot" charset="utf-8"></script> | ||
<script src="https://1"></script> | ||
<script src="https://2"></script> | ||
<script src="\S[^\n]*/kaleido_scopes\.js"></script> | ||
</head> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image"></img></body> | ||
<body style="{margin: 0; padding: 0;}"><img id="kaleido-image" /></body> | ||
</html> | ||
""") | ||
""" | ||
with_others_result_re = re.compile(with_others_result_raw) | ||
|
||
|
||
@pytest.mark.order(1) | ||
|
@@ -136,7 +156,11 @@ async def test_page_generator(): | |
"in the main group.", | ||
) | ||
no_imports = PageGenerator().generate_index() | ||
assert no_imports_result_re.findall(no_imports) | ||
assert no_imports_result_re.findall(no_imports), ( | ||
f"{len(no_imports_result_raw)}: {no_imports_result_raw}" | ||
"\n" | ||
f"{len(no_imports)}: {no_imports}" | ||
) | ||
sys.path = old_path | ||
|
||
# this imports plotly so above test must have already been done | ||
|
@@ -157,7 +181,11 @@ async def test_page_generator(): | |
mathjax="https://with_mathjax", | ||
others=["https://1", "https://2"], | ||
).generate_index() | ||
assert with_others_result_re.findall(with_others) | ||
assert with_others_result_re.findall(with_others), ( | ||
f"{len(with_others_result_raw)}: {with_others_result_raw}" | ||
"\n" | ||
f"{len(with_others)}: {with_others}" | ||
) | ||
|
||
|
||
# test others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't make sense to me, what is the function of this file? Should it be checked into git at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legacy code that I've been using throughout this process and as documentation. It's definitely on its way out, I can axe it.