"""Integrare reala cu pachetul vendorizat `scale_bridge` (cântar simulat).""" from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent VENDOR = ROOT / "vendor" / "syncpulse-scale-bridge" if str(VENDOR) not in sys.path: sys.path.insert(0, str(VENDOR)) from cantarire.scale import ScaleService # noqa: E402 from scale_bridge.config import Config as BridgeConfig # noqa: E402 def test_scale_service_reads_simulated_scale(tmp_path): bridge_config = tmp_path / "bridge.json" config = BridgeConfig(bridge_config) config.save_profile({ "name": "sim-toledo", "label": "Simulator Toledo", "port": "COM90", "protocol": "toledo_cont", "serial": {"port": "COM90", "baudrate": 9600, "bytesize": 8, "parity": "N", "stopbits": 1}, }) service = ScaleService(bridge_config, simulate="toledo_cont") try: assert service.available, service.error names = [p["name"] for p in service.profiles()] assert names == ["sim-toledo"] result = service.read("sim-toledo", max_age_ms=3000, wait_ms=5000) assert result["ok"] is True, result assert result["value"] is not None assert result["unit"] == "kg" assert result["profile"] == "sim-toledo" assert result["port"] == "COM90" assert result["raw_hex"] finally: service.close() def test_scale_service_without_profiles(tmp_path): bridge_config = tmp_path / "bridge.json" BridgeConfig(bridge_config) service = ScaleService(bridge_config) try: result = service.read("") assert result["ok"] is False assert "profil" in result["error"].lower() finally: service.close()