Initial commit: aplicatie de cantarire si etichetare
Aplicatie Flask + SQLite pentru productie alimentara: cantarirea componentelor unui produs finit si tiparirea etichetei prin QZ Tray. - produse finite (retete) formate din componente cantarite - designer vizual de etichete (mm/px, zona sigura, campuri variabile, cod QR cu continut din mai multe bucati) - legare produs finit -> sablon de eticheta - navigare pe doua taburi: Cantarire / Setari - administrare: componente, produse finite, sabloane, campuri, istoric - backup, resetare baza de date, checklist de pregatire, /healthz - CLI de administrare si serviciu systemd pentru productie - vendor/syncpulse-scale-bridge (GPL-3.0-or-later) pentru citirea cantarului
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""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()
|
||||
Reference in New Issue
Block a user