51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""动态模拟后端测试"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
from line_laser_modbus.config import SerialConfig
|
|
from line_laser_modbus.models import DeviceStatus, ModeCommand
|
|
|
|
from line_laser_hmi.backend import DynamicSimulatedBackend, build_client
|
|
|
|
|
|
def test_build_client_uses_dynamic_simulator():
|
|
"""模拟模式应注入动态模拟后端"""
|
|
|
|
client = build_client(SerialConfig(port="SIM"), simulate=True)
|
|
assert isinstance(client._backend, DynamicSimulatedBackend)
|
|
|
|
|
|
def test_current_pose_changes_over_time():
|
|
"""连续读取当前位姿应随时间变化"""
|
|
|
|
client = build_client(SerialConfig(port="SIM"), simulate=True)
|
|
client.connect()
|
|
first = client.read_current_pose()
|
|
time.sleep(0.05)
|
|
second = client.read_current_pose()
|
|
client.close()
|
|
assert first.as_tuple() != second.as_tuple()
|
|
|
|
|
|
def test_write_mode_updates_status():
|
|
"""写入模式命令应联动刷新模拟设备状态字"""
|
|
|
|
client = build_client(SerialConfig(port="SIM"), simulate=True)
|
|
client.connect()
|
|
client.write_mode(ModeCommand.ONLINE_TRACKING)
|
|
assert client.read_status() is DeviceStatus.TRACKING_OK
|
|
client.trigger_emergency_stop()
|
|
assert client.read_status() is DeviceStatus.EMERGENCY_TRIGGERED
|
|
client.close()
|
|
|
|
|
|
def test_available_cache_count_is_readable():
|
|
"""模拟后端应暴露 V1.4 的 0xD002 可用缓存数量"""
|
|
|
|
client = build_client(SerialConfig(port="SIM"), simulate=True)
|
|
client.connect()
|
|
assert client.read_available_cache_count() == 1
|
|
client.close()
|