File size: 1,040 Bytes
15b8951
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import asyncio
import numpy as np
from vlm.webconsole.common.frame_source import FrameSource


def test_mock_mode_when_no_ip():
    src = FrameSource(robot_ip=None)
    assert src.is_mock is True
    assert src.is_connected is False


def test_mock_start_provides_frame():
    src = FrameSource(robot_ip="")
    asyncio.run(src.start())
    frame = src.get_latest_frame()
    assert isinstance(frame, np.ndarray)
    assert frame.ndim == 3 and frame.shape[2] == 3


def test_real_mode_no_frame_before_start():
    src = FrameSource(robot_ip="192.168.1.10")
    assert src.is_mock is False
    assert src.get_latest_frame() is None
    assert src.is_connected is False


def test_failed_connection_does_not_crash():
    # IP kh么ng n峄慽 膽瓢峄 (ho岷穋 thi岷縰 go2 sdk) -> start() kh么ng raise,
    # v岷玭 c贸 frame th么ng b谩o, badge disconnected.
    src = FrameSource(robot_ip="10.255.255.1")
    asyncio.run(src.start())
    assert src.is_connected is False
    frame = src.get_latest_frame()
    assert isinstance(frame, np.ndarray)