24
24
from .transport import Transport
25
25
26
26
__all__ = [
27
- "framebuffer_read " ,
28
- "framebuffer_png_bytes " ,
27
+ "read_framebuffer " ,
28
+ "read_framebuffer_png_bytes " ,
29
29
"save_framebuffer_png" ,
30
- "compare_framebuffer_png" ,
31
30
]
32
31
33
32
34
- async def framebuffer_read (transport : Transport , * , id : str ) -> ResponseMessage :
33
+ async def read_framebuffer (transport : Transport , * , id : str ) -> ResponseMessage :
35
34
"""Issue `framebuffer:read` for the given device id and return raw response."""
36
35
return await transport .request ("framebuffer:read" , {"id" : id })
37
36
@@ -44,9 +43,9 @@ def _extract_png_b64(resp: ResponseMessage) -> str:
44
43
return png_b64
45
44
46
45
47
- async def framebuffer_png_bytes (transport : Transport , * , id : str ) -> bytes :
46
+ async def read_framebuffer_png_bytes (transport : Transport , * , id : str ) -> bytes :
48
47
"""Return decoded PNG bytes for the framebuffer of device `id`."""
49
- resp = await framebuffer_read (transport , id = id )
48
+ resp = await read_framebuffer (transport , id = id )
50
49
return base64 .b64decode (_extract_png_b64 (resp ))
51
50
52
51
@@ -64,30 +63,8 @@ async def save_framebuffer_png(
64
63
"""
65
64
if path .exists () and not overwrite :
66
65
raise WokwiError (f"File already exists and overwrite=False: { path } " )
67
- data = await framebuffer_png_bytes (transport , id = id )
66
+ data = await read_framebuffer_png_bytes (transport , id = id )
68
67
path .parent .mkdir (parents = True , exist_ok = True )
69
68
with open (path , "wb" ) as f :
70
69
f .write (data )
71
70
return path
72
-
73
-
74
- async def compare_framebuffer_png (
75
- transport : Transport , * , id : str , reference : Path , save_mismatch : Path | None = None
76
- ) -> bool :
77
- """Compare the current framebuffer PNG with a reference file.
78
-
79
- Performs a byte-for-byte comparison. If different and `save_mismatch` is
80
- provided, writes the current framebuffer PNG there.
81
-
82
- Returns True if identical, False otherwise.
83
- """
84
- if not reference .exists ():
85
- raise WokwiError (f"Reference image does not exist: { reference } " )
86
- current = await framebuffer_png_bytes (transport , id = id )
87
- ref_bytes = reference .read_bytes ()
88
- if current == ref_bytes :
89
- return True
90
- if save_mismatch :
91
- save_mismatch .parent .mkdir (parents = True , exist_ok = True )
92
- save_mismatch .write_bytes (current )
93
- return False
0 commit comments