Movatterモバイル変換


[0]ホーム

URL:


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

Commitd066330

Browse files
committed
improve pio.defaults test
1 parent6837831 commitd066330

File tree

1 file changed

+88
-3
lines changed

1 file changed

+88
-3
lines changed

‎tests/test_optional/test_kaleido/test_kaleido.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,100 @@ def test_bytesio():
154154

155155
deftest_defaults():
156156
"""Test that image output defaults can be set using pio.defaults.*"""
157+
test_fig=go.Figure(fig)
158+
test_image_bytes=b"mock image data"
159+
160+
# Check initial defaults
161+
assertpio.defaults.default_format=="png"
162+
assertpio.defaults.default_width==700
163+
assertpio.defaults.default_height==500
164+
assertpio.defaults.default_scale==1
165+
assertpio.defaults.mathjaxisNone
166+
assertpio.defaults.topojsonisNone
167+
assertpio.defaults.plotlyjsisNone
168+
157169
try:
158-
assertpio.defaults.default_format=="png"
170+
# Set new defaults
159171
pio.defaults.default_format="svg"
172+
pio.defaults.default_width=701
173+
pio.defaults.default_height=501
174+
pio.defaults.default_scale=2
175+
pio.defaults.mathjax= (
176+
"https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js"
177+
)
178+
pio.defaults.topojson="path/to/topojson/files/"
179+
pio.defaults.plotlyjs="https://cdn.plot.ly/plotly-3.0.0.js"
180+
181+
# Check that new defaults are saved
160182
assertpio.defaults.default_format=="svg"
161-
result=pio.to_image(fig,format="svg",validate=False)
162-
assertresult.startswith(b"<svg")
183+
assertpio.defaults.default_width==701
184+
assertpio.defaults.default_height==501
185+
assertpio.defaults.default_scale==2
186+
assert (
187+
pio.defaults.mathjax
188+
=="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js"
189+
)
190+
assertpio.defaults.topojson=="path/to/topojson/files/"
191+
assertpio.defaults.plotlyjs=="https://cdn.plot.ly/plotly-3.0.0.js"
192+
193+
ifkaleido_major()>0:
194+
# Check that all the defaults values are passed through to the function call to calc_fig_sync
195+
withpatch(
196+
"plotly.io._kaleido.kaleido.calc_fig_sync",
197+
return_value=test_image_bytes,
198+
)asmock_calc_fig:
199+
# ===== CLAUDE START HERE 1 =====
200+
result=pio.to_image(test_fig,validate=False)
201+
202+
# Verify calc_fig_sync was called with correct args
203+
# taken from pio.defaults
204+
mock_calc_fig.assert_called_once()
205+
args,kwargs=mock_calc_fig.call_args
206+
assertargs[0]==test_fig.to_dict()
207+
assertkwargs["opts"]["format"]=="svg"
208+
assertkwargs["opts"]["width"]==701
209+
assertkwargs["opts"]["height"]==501
210+
assertkwargs["opts"]["scale"]==2
211+
assertkwargs["topojson"]=="path/to/topojson/files/"
212+
# mathjax and plotlyjs are passed through in kopts
213+
assert (
214+
kwargs["kopts"]["mathjax"]
215+
=="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js"
216+
)
217+
assert (
218+
kwargs["kopts"]["plotlyjs"]
219+
=="https://cdn.plot.ly/plotly-3.0.0.js"
220+
)
221+
222+
else:
223+
# Check that all the default values have been set in pio._kaleido.scope
224+
assertpio._kaleido.scope.default_format=="svg"
225+
assertpio._kaleido.scope.default_width==701
226+
assertpio._kaleido.scope.default_height==501
227+
assertpio._kaleido.scope.default_scale==2
228+
assert (
229+
pio._kaleido.scope.mathjax
230+
=="https://cdn.jsdelivr.net/npm/mathjax@3.1.2/es5/tex-svg.js"
231+
)
232+
assertpio._kaleido.scope.topojson=="path/to/topojson/files/"
233+
assertpio._kaleido.scope.plotlyjs=="https://cdn.plot.ly/plotly-3.0.0.js"
234+
163235
finally:
236+
# Reset defaults to original values and check that they are restored
164237
pio.defaults.default_format="png"
238+
pio.defaults.default_width=700
239+
pio.defaults.default_height=500
240+
pio.defaults.default_scale=1
241+
pio.defaults.mathjax=None
242+
pio.defaults.topojson=None
243+
pio.defaults.plotlyjs=None
165244
assertpio.defaults.default_format=="png"
245+
assertpio.defaults.default_width==700
246+
assertpio.defaults.default_height==500
247+
assertpio.defaults.default_scale==1
248+
assertpio.defaults.mathjaxisNone
249+
assertpio.defaults.topojsonisNone
250+
assertpio.defaults.plotlyjsisNone
166251

167252

168253
deftest_fig_write_image():

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp