Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1e7607

Browse files
committed
Add some width/height testing.
1 parent bcdccf4 commit f1e7607

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎tests/test_optional/test_kaleido/test_kaleido.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pathlib import Path
55
import tempfile
66
from unittest.mock import patch
7+
import xml.etree.ElementTree as ET
78

89
from pdfrw import PdfReader
910
from PIL import Image
@@ -314,3 +315,54 @@ def test_get_chrome():
314315

315316
# Verify that kaleido.get_chrome_sync was called
316317
mock_get_chrome.assert_called_once()
318+
319+
320+
def create_figure(width=None, height=None):
321+
"""Create a simple figure with optional layout dimensions."""
322+
layout = {}
323+
if width:
324+
layout['width'] = width
325+
if height:
326+
layout['height'] = height
327+
328+
return go.Figure(
329+
data=[go.Scatter(x=[1, 2, 3], y=[1, 2, 3])],
330+
layout=layout
331+
)
332+
333+
334+
def parse_svg_dimensions(svg_bytes):
335+
"""Parse width and height from SVG bytes."""
336+
svg_str = svg_bytes.decode('utf-8')
337+
root = ET.fromstring(svg_str)
338+
width = root.get('width')
339+
height = root.get('height')
340+
return int(width) if width else None, int(height) if height else None
341+
342+
343+
def test_width_height_priority():
344+
"""Test width/height priority: arguments > layout.width/height > defaults."""
345+
346+
# Test case 1: Arguments override layout
347+
fig = create_figure(layout_width=800, layout_height=600)
348+
svg_bytes = pio.to_image(fig, format='svg', width=1000, height=900)
349+
width, height = parse_svg_dimensions(svg_bytes)
350+
assert width == 1000 and height == 900, "Arguments should override layout dimensions"
351+
352+
# Test case 2: Layout dimensions used when no arguments
353+
fig = create_figure(layout_width=800, layout_height=600)
354+
svg_bytes = pio.to_image(fig, format='svg')
355+
width, height = parse_svg_dimensions(svg_bytes)
356+
assert width == 800 and height == 600, "Layout dimensions should be used when no arguments provided"
357+
358+
# Test case 3: Partial override (only width argument)
359+
fig = create_figure(layout_width=800, layout_height=600)
360+
svg_bytes = pio.to_image(fig, format='svg', width=1200)
361+
width, height = parse_svg_dimensions(svg_bytes)
362+
assert width == 1200 and height == 600, "Width argument should override layout, height should use layout"
363+
364+
# Test case 4: Defaults used when no layout or arguments
365+
fig = create_figure()
366+
svg_bytes = pio.to_image(fig, format='svg')
367+
width, height = parse_svg_dimensions(svg_bytes)
368+
assert width is not None and height is not None, "Default dimensions should be used when no layout or arguments"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /