Skip to content

Commit 6958eef

Browse files
committed
Update calc_fig test
1 parent f776ad1 commit 6958eef

2 files changed

Lines changed: 27 additions & 26 deletions

File tree

src/py/kaleido/kaleido.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def __init__(
109109
self,
110110
# *args: Any, force named vars for all choreographer passthrough
111111
n: int = 1,
112-
timeout: int | None = 90,
112+
timeout: float | None = 90,
113113
page_generator: None | PageGenerator | str | Path = None,
114114
plotlyjs: str | Path | None = None,
115115
mathjax: str | Path | Literal[False] | None = None,
@@ -124,7 +124,7 @@ def __init__(
124124
n (int, optional):
125125
Number of processors to use (parallelization). Defaults to 1.
126126
127-
timeout (int | None, optional):
127+
timeout (float | None, optional):
128128
Number of seconds to wait to render any one image. None for no
129129
timeout. Defaults to 90.
130130
@@ -521,13 +521,13 @@ async def calc_fig(
521521
)
522522

523523
spec: FigureDict = {
524-
"fig": fig,
525-
"opts": opts,
526-
"topojson": topojson,
527-
}
524+
"fig": fig,
525+
"opts": opts,
526+
"topojson": topojson,
527+
}
528528
# pyright > mypy, but:
529529
# pyright doesn't understand literals in overloads as well
530-
return await self.write_fig_from_object( # type: ignore[reportCallIssue]
530+
return await self.write_fig_from_object( # type: ignore[reportCallIssue]
531531
fig_dicts=spec,
532532
cancel_on_error=True,
533533
_write=False,

src/py/tests/test_kaleido.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import re
5+
from typing import TYPE_CHECKING
36
from unittest.mock import AsyncMock, patch
47

58
import pytest
@@ -8,6 +11,11 @@
811

912
from kaleido import Kaleido
1013

14+
if TYPE_CHECKING:
15+
from typing import AsyncGenerator, Generator
16+
17+
from kaleido import FigureDict
18+
1119

1220
# can't do session scope because pytest complains that its used by
1321
# function-scoped loops. tried to create a separate loop in here with
@@ -40,7 +48,7 @@ async def test_write_fig_from_object_sync_generator(simple_figure_with_bytes, tm
4048

4149
file_paths = []
4250

43-
def fig_generator():
51+
def fig_generator() -> Generator[FigureDict, None]:
4452
for i in range(2):
4553
path = tmp_path / f"test_sync_{i}.png"
4654
file_paths.append(path)
@@ -70,7 +78,7 @@ async def test_write_fig_from_object_async_generator(
7078

7179
file_paths = []
7280

73-
async def fig_async_generator():
81+
async def fig_async_generator() -> AsyncGenerator[FigureDict, None]:
7482
for i in range(2):
7583
path = tmp_path / f"test_async_{i}.png"
7684
file_paths.append(path)
@@ -166,7 +174,7 @@ async def test_write_fig_from_object_bare_dictionary(
166174

167175
path1 = tmp_path / "test_dict_1.png"
168176

169-
fig_data = {
177+
fig_data: FigureDict = {
170178
"fig": simple_figure_with_bytes["fig"],
171179
"path": path1,
172180
"opts": simple_figure_with_bytes["opts"],
@@ -303,27 +311,19 @@ async def test_calc_fig_argument_passthrough(
303311
# Extract the generator that was passed as first argument
304312
_, kwargs = mock_write_fig_from_object.call_args # not sure.
305313

306-
generator = kwargs["fig_dicts"]
314+
fig_dict = kwargs["fig_dicts"]
307315
assert kwargs["cancel_on_error"] is True
308316
assert kwargs["_write"] is False
309317

310-
# Convert generator to list to inspect its contents
311-
generated_args_list = [v async for v in generator]
312-
assert len(generated_args_list) == 1, (
313-
"Expected generator to yield exactly one item"
314-
)
315-
316-
generated_args = generated_args_list[0]
317-
318318
# Validate that the generated arguments match what we passed to write_fig
319-
assert "fig" in generated_args, "Generated args should contain 'fig'"
320-
assert "opts" in generated_args, "Generated args should contain 'opts'"
321-
assert "topojson" in generated_args, "Generated args should contain 'topojson'"
319+
assert "fig" in fig_dict, "Generated args should contain 'fig'"
320+
assert "opts" in fig_dict, "Generated args should contain 'opts'"
321+
assert "topojson" in fig_dict, "Generated args should contain 'topojson'"
322322

323323
# Check that the values match
324-
assert generated_args["fig"] == fig, "Figure should match"
325-
assert generated_args["opts"] == opts, "Options should match"
326-
assert generated_args["topojson"] == topojson, "Topojson should match"
324+
assert fig_dict["fig"] == fig, "Figure should match"
325+
assert fig_dict["opts"] == opts, "Options should match"
326+
assert fig_dict["topojson"] == topojson, "Topojson should match"
327327

328328

329329
async def test_kaleido_instantiate_no_hang():
@@ -374,7 +374,8 @@ async def test_all_methods_non_context(simple_figure_with_bytes, tmp_path):
374374
expected_bytes = simple_figure_with_bytes["bytes"]
375375

376376
# Test without context manager
377-
k = await Kaleido()
377+
k: Kaleido = Kaleido()
378+
await k # could do it on one line but it tricks typer
378379
try:
379380
# Test calc_fig
380381
calc_bytes = await k.calc_fig(fig, opts=opts)

0 commit comments

Comments
 (0)