forked from tangger/lerobot
fix(tests): kill thread when camera async_read tests fail
This commit is contained in:
@@ -126,12 +126,15 @@ def test_async_read(index_or_path):
|
|||||||
camera = OpenCVCamera(config)
|
camera = OpenCVCamera(config)
|
||||||
camera.connect(do_warmup_read=False)
|
camera.connect(do_warmup_read=False)
|
||||||
|
|
||||||
img = camera.async_read()
|
try:
|
||||||
|
img = camera.async_read()
|
||||||
|
|
||||||
assert camera.thread is not None
|
assert camera.thread is not None
|
||||||
assert camera.thread.is_alive()
|
assert camera.thread.is_alive()
|
||||||
assert isinstance(img, np.ndarray)
|
assert isinstance(img, np.ndarray)
|
||||||
camera.disconnect() # To stop/join the thread. Otherwise get warnings when the test ends
|
finally:
|
||||||
|
if camera.is_connected:
|
||||||
|
camera.disconnect() # To stop/join the thread. Otherwise get warnings when the test ends
|
||||||
|
|
||||||
|
|
||||||
def test_async_read_timeout():
|
def test_async_read_timeout():
|
||||||
@@ -139,10 +142,12 @@ def test_async_read_timeout():
|
|||||||
camera = OpenCVCamera(config)
|
camera = OpenCVCamera(config)
|
||||||
camera.connect(do_warmup_read=False)
|
camera.connect(do_warmup_read=False)
|
||||||
|
|
||||||
with pytest.raises(TimeoutError):
|
try:
|
||||||
camera.async_read(timeout_ms=0)
|
with pytest.raises(TimeoutError):
|
||||||
|
camera.async_read(timeout_ms=0)
|
||||||
camera.disconnect()
|
finally:
|
||||||
|
if camera.is_connected:
|
||||||
|
camera.disconnect()
|
||||||
|
|
||||||
|
|
||||||
def test_async_read_before_connect():
|
def test_async_read_before_connect():
|
||||||
@@ -183,5 +188,3 @@ def test_all_rotations(rotation, index_or_path):
|
|||||||
assert camera.width == original_width
|
assert camera.width == original_width
|
||||||
assert camera.height == original_height
|
assert camera.height == original_height
|
||||||
assert img.shape[:2] == (original_height, original_width)
|
assert img.shape[:2] == (original_height, original_width)
|
||||||
|
|
||||||
camera.disconnect()
|
|
||||||
|
|||||||
@@ -136,12 +136,15 @@ def test_async_read(mock_enable_device):
|
|||||||
camera = RealSenseCamera(config)
|
camera = RealSenseCamera(config)
|
||||||
camera.connect(do_warmup_read=False)
|
camera.connect(do_warmup_read=False)
|
||||||
|
|
||||||
img = camera.async_read()
|
try:
|
||||||
|
img = camera.async_read()
|
||||||
|
|
||||||
assert camera.thread is not None
|
assert camera.thread is not None
|
||||||
assert camera.thread.is_alive()
|
assert camera.thread.is_alive()
|
||||||
assert isinstance(img, np.ndarray)
|
assert isinstance(img, np.ndarray)
|
||||||
camera.disconnect() # To stop/join the thread. Otherwise get warnings when the test ends
|
finally:
|
||||||
|
if camera.is_connected:
|
||||||
|
camera.disconnect() # To stop/join the thread. Otherwise get warnings when the test ends
|
||||||
|
|
||||||
|
|
||||||
@patch("pyrealsense2.config.enable_device", side_effect=mock_rs_config_enable_device_from_file)
|
@patch("pyrealsense2.config.enable_device", side_effect=mock_rs_config_enable_device_from_file)
|
||||||
@@ -150,10 +153,12 @@ def test_async_read_timeout(mock_enable_device):
|
|||||||
camera = RealSenseCamera(config)
|
camera = RealSenseCamera(config)
|
||||||
camera.connect(do_warmup_read=False)
|
camera.connect(do_warmup_read=False)
|
||||||
|
|
||||||
with pytest.raises(TimeoutError):
|
try:
|
||||||
camera.async_read(timeout_ms=0)
|
with pytest.raises(TimeoutError):
|
||||||
|
camera.async_read(timeout_ms=0)
|
||||||
camera.disconnect()
|
finally:
|
||||||
|
if camera.is_connected:
|
||||||
|
camera.disconnect()
|
||||||
|
|
||||||
|
|
||||||
def test_async_read_before_connect():
|
def test_async_read_before_connect():
|
||||||
|
|||||||
Reference in New Issue
Block a user