MCPcopy Create free account
hub / github.com/plotly/plotly.py / check_image

Function check_image

tests/test_optional/test_kaleido/test_kaleido.py:40–56  ·  view source on GitHub ↗
(path_or_buffer, size=(700, 500), format="PNG")

Source from the content-addressed store, hash-verified

38
39
40def check_image(path_or_buffer, size=(700, 500), format="PNG"):
41 if format == "PDF":
42 img = PdfReader(path_or_buffer)
43 # TODO: There is a conversion factor needed here
44 # In Kaleido v0 the conversion factor is 0.75
45 factor = 0.75
46 expected_size = tuple(int(s * factor) for s in size)
47 actual_size = tuple(int(s) for s in img.pages[0].MediaBox[2:])
48 assert actual_size == expected_size
49 else:
50 if isinstance(path_or_buffer, (str, Path)):
51 with open(path_or_buffer, "rb") as f:
52 img = Image.open(f)
53 else:
54 img = Image.open(path_or_buffer)
55 assert img.size == size
56 assert img.format == format
57
58
59def test_kaleido_engine_to_image_returns_bytes():

Calls 2

intFunction · 0.85
openMethod · 0.45

Tested by

no test coverage detected