2929from lerobot .common .errors import DeviceAlreadyConnectedError , DeviceNotConnectedError
3030
3131# NOTE(Steven): Consider improving the assert coverage
32+ TEST_ARTIFACTS_DIR = os .path .join (os .path .dirname (os .path .dirname (__file__ )), "artifacts" , "cameras" )
33+ DEFAULT_PNG_FILE_PATH = os .path .join (TEST_ARTIFACTS_DIR , "fakecam_sd_160x120.png" )
34+ TEST_IMAGE_PATHS = [
35+ os .path .join (TEST_ARTIFACTS_DIR , "fakecam_sd_160x120.png" ),
36+ os .path .join (TEST_ARTIFACTS_DIR , "fakecam_hd_320x180.png" ),
37+ os .path .join (TEST_ARTIFACTS_DIR , "fakecam_fullhd_480x270.png" ),
38+ os .path .join (TEST_ARTIFACTS_DIR , "fakecam_square_128x128.png" ),
39+ ]
3240
3341
3442def test_base_class_implementation ():
@@ -38,7 +46,7 @@ def test_base_class_implementation():
3846
3947
4048def test_connect ():
41- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
49+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
4250 camera = OpenCVCamera (config )
4351
4452 camera .connect (do_warmup_read = False )
@@ -47,7 +55,7 @@ def test_connect():
4755
4856
4957def test_connect_already_connected ():
50- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
58+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
5159 camera = OpenCVCamera (config )
5260 camera .connect (do_warmup_read = False )
5361
@@ -65,7 +73,7 @@ def test_connect_invalid_camera_path():
6573
6674def test_invalid_width_connect ():
6775 config = OpenCVCameraConfig (
68- index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" ,
76+ index_or_path = DEFAULT_PNG_FILE_PATH ,
6977 width = 99999 , # Invalid width to trigger error
7078 height = 480 ,
7179 )
@@ -75,15 +83,7 @@ def test_invalid_width_connect():
7583 camera .connect (do_warmup_read = False )
7684
7785
78- @pytest .mark .parametrize (
79- "index_or_path" ,
80- [
81- "tests/artifacts/cameras/fakecam_sd_640x480.png" ,
82- "tests/artifacts/cameras/fakecam_hd_1280x720.png" ,
83- "tests/artifacts/cameras/fakecam_fullhd_1920x1080.png" ,
84- "tests/artifacts/cameras/fakecam_square_512x512.png" ,
85- ],
86- )
86+ @pytest .mark .parametrize ("index_or_path" , TEST_IMAGE_PATHS )
8787def test_read (index_or_path ):
8888 config = OpenCVCameraConfig (index_or_path = index_or_path )
8989 camera = OpenCVCamera (config )
@@ -95,15 +95,15 @@ def test_read(index_or_path):
9595
9696
9797def test_read_before_connect ():
98- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
98+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
9999 camera = OpenCVCamera (config )
100100
101101 with pytest .raises (DeviceNotConnectedError ):
102102 _ = camera .read ()
103103
104104
105105def test_disconnect ():
106- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
106+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
107107 camera = OpenCVCamera (config )
108108 camera .connect (do_warmup_read = False )
109109
@@ -113,22 +113,14 @@ def test_disconnect():
113113
114114
115115def test_disconnect_before_connect ():
116- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
116+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
117117 camera = OpenCVCamera (config )
118118
119119 with pytest .raises (DeviceNotConnectedError ):
120120 _ = camera .disconnect ()
121121
122122
123- @pytest .mark .parametrize (
124- "index_or_path" ,
125- [
126- "tests/artifacts/cameras/fakecam_sd_640x480.png" ,
127- "tests/artifacts/cameras/fakecam_hd_1280x720.png" ,
128- "tests/artifacts/cameras/fakecam_fullhd_1920x1080.png" ,
129- "tests/artifacts/cameras/fakecam_square_512x512.png" ,
130- ],
131- )
123+ @pytest .mark .parametrize ("index_or_path" , TEST_IMAGE_PATHS )
132124def test_async_read (index_or_path ):
133125 config = OpenCVCameraConfig (index_or_path = index_or_path )
134126 camera = OpenCVCamera (config )
@@ -143,7 +135,7 @@ def test_async_read(index_or_path):
143135
144136
145137def test_async_read_timeout ():
146- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
138+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
147139 camera = OpenCVCamera (config )
148140 camera .connect (do_warmup_read = False )
149141
@@ -154,22 +146,14 @@ def test_async_read_timeout():
154146
155147
156148def test_async_read_before_connect ():
157- config = OpenCVCameraConfig (index_or_path = "tests/artifacts/cameras/fakecam_sd_640x480.png" )
149+ config = OpenCVCameraConfig (index_or_path = DEFAULT_PNG_FILE_PATH )
158150 camera = OpenCVCamera (config )
159151
160152 with pytest .raises (DeviceNotConnectedError ):
161153 _ = camera .async_read ()
162154
163155
164- @pytest .mark .parametrize (
165- "index_or_path" ,
166- [
167- "tests/artifacts/cameras/fakecam_sd_640x480.png" ,
168- "tests/artifacts/cameras/fakecam_hd_1280x720.png" ,
169- "tests/artifacts/cameras/fakecam_fullhd_1920x1080.png" ,
170- "tests/artifacts/cameras/fakecam_square_512x512.png" ,
171- ],
172- )
156+ @pytest .mark .parametrize ("index_or_path" , TEST_IMAGE_PATHS )
173157@pytest .mark .parametrize (
174158 "rotation" ,
175159 [
0 commit comments