Skip to content

Commit c08e203

Browse files
committed
Clean up
1 parent d1da3e6 commit c08e203

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

tests/test_core/test_offline/test_offline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import pytest
1010

1111
import plotly
12+
from plotly.offline import get_plotlyjs
1213
import plotly.io as pio
1314
from plotly.io._utils import plotly_cdn_url
15+
from plotly.io._html import _generate_sri_hash
1416

1517
packages_root = os.path.dirname(
1618
os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(plotly.__file__))))
@@ -37,7 +39,7 @@
3739
<script type="text/javascript">\
3840
window.PlotlyConfig = {MathJaxConfig: 'local'};</script>"""
3941

40-
cdn_script = '<script charset="utf-8" src="http://github.com/%7Bcdn_url%7D"'.format(cdn_url=plotly_cdn_url())
42+
cdn_script = '<script charset="utf-8" src="http://github.com/%7Bcdn_url%7D" integrity="{js_hash}" crossorigin="anonymous"></script>'.format(cdn_url=plotly_cdn_url(), js_hash=_generate_sri_hash(get_plotlyjs()))
4143

4244
directory_script = '<script charset="utf-8" src="plotly.min.js"></script>'
4345

tests/test_io/test_html.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
import numpy as np
5+
import re
56

67

78
import plotly.graph_objs as go
@@ -59,8 +60,6 @@ def test_cdn_includes_integrity_attribute(fig1):
5960
assert 'crossorigin="anonymous"' in html_output
6061

6162
# Verify it's in the correct script tag
62-
import re
63-
6463
cdn_pattern = re.compile(
6564
r'<script[^>]*src="'
6665
+ re.escape(plotly_cdn_url())
@@ -75,8 +74,6 @@ def test_cdn_integrity_hash_matches_bundled_content(fig1):
7574
html_output = pio.to_html(fig1, include_plotlyjs="cdn")
7675

7776
# Extract the integrity hash from the HTML output
78-
import re
79-
8077
integrity_pattern = re.compile(r'integrity="(sha256-[A-Za-z0-9+/=]+)"')
8178
match = integrity_pattern.search(html_output)
8279
assert match is not None, "Integrity attribute not found"

0 commit comments

Comments
 (0)