Skip to content

Commit 87a4e8f

Browse files
ddworkenclaude
andcommitted
Apply formatting fixes from linter
- Fix formatting in test_html.py - Fix formatting in test_offline.py - Fix formatting in _html.py 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 912733d commit 87a4e8f

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

plotly/io/_html.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
def _generate_sri_hash(content):
1515
"""Generate SHA256 hash for SRI (Subresource Integrity)"""
1616
if isinstance(content, str):
17-
content = content.encode('utf-8')
17+
content = content.encode("utf-8")
1818
sha256_hash = hashlib.sha256(content).digest()
19-
return 'sha256-' + base64.b64encode(sha256_hash).decode('utf-8')
19+
return "sha256-" + base64.b64encode(sha256_hash).decode("utf-8")
2020

2121

2222
# Build script to set global PlotlyConfig object. This must execute before
@@ -265,14 +265,14 @@ def to_html(
265265
# Generate SRI hash from the bundled plotly.js content
266266
plotlyjs_content = get_plotlyjs()
267267
sri_hash = _generate_sri_hash(plotlyjs_content)
268-
268+
269269
load_plotlyjs = """\
270270
{win_config}
271271
<script charset="utf-8" src="{cdn_url}" integrity="{integrity}" crossorigin="anonymous"></script>\
272272
""".format(
273-
win_config=_window_plotly_config,
273+
win_config=_window_plotly_config,
274274
cdn_url=plotly_cdn_url(),
275-
integrity=sri_hash
275+
integrity=sri_hash,
276276
)
277277

278278
elif include_plotlyjs == "directory":

tests/test_core/test_offline/test_offline.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737
<script type="text/javascript">\
3838
window.PlotlyConfig = {MathJaxConfig: 'local'};</script>"""
3939

40-
cdn_script = '<script charset="utf-8" src="{cdn_url}"'.format(
41-
cdn_url=plotly_cdn_url()
42-
)
40+
cdn_script = '<script charset="utf-8" src="{cdn_url}"'.format(cdn_url=plotly_cdn_url())
4341

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

tests/test_io/test_html.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,40 @@ def test_html_deterministic(fig1):
5353
def test_cdn_includes_integrity_attribute(fig1):
5454
"""Test that the CDN script tag includes an integrity attribute with SHA256 hash"""
5555
html_output = pio.to_html(fig1, include_plotlyjs="cdn")
56-
56+
5757
# Check that the script tag includes integrity attribute
5858
assert 'integrity="sha256-' in html_output
5959
assert 'crossorigin="anonymous"' in html_output
60-
60+
6161
# Verify it's in the correct script tag
6262
import re
63-
cdn_pattern = re.compile(r'<script[^>]*src="' + re.escape(plotly_cdn_url()) + r'"[^>]*integrity="sha256-[A-Za-z0-9+/=]+"[^>]*>')
63+
64+
cdn_pattern = re.compile(
65+
r'<script[^>]*src="'
66+
+ re.escape(plotly_cdn_url())
67+
+ r'"[^>]*integrity="sha256-[A-Za-z0-9+/=]+"[^>]*>'
68+
)
6469
match = cdn_pattern.search(html_output)
6570
assert match is not None, "CDN script tag with integrity attribute not found"
6671

6772

6873
def test_cdn_integrity_hash_matches_bundled_content(fig1):
6974
"""Test that the SRI hash in CDN script tag matches the bundled plotly.js content"""
7075
html_output = pio.to_html(fig1, include_plotlyjs="cdn")
71-
76+
7277
# Extract the integrity hash from the HTML output
7378
import re
79+
7480
integrity_pattern = re.compile(r'integrity="(sha256-[A-Za-z0-9+/=]+)"')
7581
match = integrity_pattern.search(html_output)
7682
assert match is not None, "Integrity attribute not found"
7783
extracted_hash = match.group(1)
78-
84+
7985
# Generate expected hash from bundled content
8086
plotlyjs_content = get_plotlyjs()
8187
expected_hash = _generate_sri_hash(plotlyjs_content)
82-
88+
8389
# Verify they match
84-
assert extracted_hash == expected_hash, f"Hash mismatch: expected {expected_hash}, got {extracted_hash}"
90+
assert (
91+
extracted_hash == expected_hash
92+
), f"Hash mismatch: expected {expected_hash}, got {extracted_hash}"

0 commit comments

Comments
 (0)