13
13
from trame_rca .utils import (
14
14
RcaEncoder ,
15
15
RcaRenderScheduler ,
16
- get_encode_fn ,
17
- encode_np_img_to_format_with_meta ,
18
- render_to_image ,
16
+ VtkImageExtract ,
19
17
time_now_ms ,
20
- vtk_img_to_numpy_array ,
21
18
)
22
19
23
20
from vtkmodules .vtkFiltersSources import vtkConeSource
@@ -55,15 +52,11 @@ def a_threed_view():
55
52
56
53
@pytest .mark .parametrize ("img_format" , ["jpeg" , "png" , "avif" , "webp" ])
57
54
def test_a_view_can_be_encoded_to_format (a_threed_view , tmpdir , img_format ):
58
- encode_fn = get_encode_fn (RcaEncoder (img_format ))
59
- img = encode_fn (
60
- * vtk_img_to_numpy_array (render_to_image (a_threed_view )),
61
- img_format ,
62
- 100 ,
55
+ img , * _ = RcaEncoder (img_format ).encode (
56
+ * VtkImageExtract (a_threed_view ).img_cols_rows , 100
63
57
)
64
- dest_file = Path (tmpdir ).joinpath (f"test_img.{ img_format } " )
65
- with open (dest_file , "wb" ) as f :
66
- f .write (img )
58
+ dest_file = Path (tmpdir ) / f"test_img.{ img_format } "
59
+ dest_file .write_bytes (img )
67
60
68
61
assert dest_file .is_file ()
69
62
im = Image .open (dest_file )
@@ -72,18 +65,18 @@ def test_a_view_can_be_encoded_to_format(a_threed_view, tmpdir, img_format):
72
65
73
66
@pytest .mark .parametrize ("img_format" , ["jpeg" , "png" , "avif" , "webp" ])
74
67
def test_np_encode_can_be_done_using_multiprocess (a_threed_view , img_format ):
75
- array , cols , rows = vtk_img_to_numpy_array (render_to_image (a_threed_view ))
68
+ encoder = RcaEncoder (img_format )
69
+ array , cols , rows = VtkImageExtract (a_threed_view ).img_cols_rows
76
70
now_ms = time_now_ms ()
77
- encode_fn = get_encode_fn (RcaEncoder (img_format ))
78
71
79
72
with Pool (1 ) as p :
80
73
encoded , meta , ret_now_ms = p .apply (
81
- encode_np_img_to_format_with_meta ,
82
- args = (encode_fn , array , img_format , cols , rows , 100 , now_ms ),
74
+ encoder . encode ,
75
+ args = (array , cols , rows , 100 ),
83
76
)
84
77
assert meta
85
- assert meta ["st" ] = = now_ms
86
- assert ret_now_ms = = now_ms
78
+ assert meta ["st" ] > = now_ms
79
+ assert ret_now_ms > = now_ms
87
80
assert encoded
88
81
89
82
@@ -186,7 +179,7 @@ async def test_groups_close_request_render_together(
186
179
await scheduler .close ()
187
180
188
181
189
- @pytest .mark .parametrize ("server_path" , ["examples/00_cone/app .py" ])
182
+ @pytest .mark .parametrize ("server_path" , ["examples/vtk_cone_simple .py" ])
190
183
def test_rca_view_is_interactive (server ):
191
184
with SB () as sb :
192
185
assert server .port
0 commit comments