bff6d70b17
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
64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
VENDOR = ROOT / "vendor" / "syncpulse-scale-bridge"
|
|
for path in (str(ROOT), str(VENDOR)):
|
|
if path not in sys.path:
|
|
sys.path.insert(0, path)
|
|
|
|
from cantarire import probe # noqa: E402
|
|
from scale_bridge.serialio import open_real # noqa: E402
|
|
from scale_bridge.simulator import SimulatorBank, frame_for # noqa: E402
|
|
|
|
|
|
def test_decode_recognises_toledo_stream():
|
|
frame = frame_for("toledo_cont", 12.345, True)
|
|
guesses = probe.decode(frame * 4)
|
|
ids = [g["protocol"] for g in guesses]
|
|
assert "toledo_cont" in ids
|
|
best = guesses[0]
|
|
assert best["protocol"] == "toledo_cont"
|
|
assert best["value"] == pytest.approx(12.345, abs=1e-3)
|
|
assert best["unit"] == "kg"
|
|
|
|
|
|
def test_decode_unknown_binary_returns_nothing():
|
|
assert probe.decode(b"\xf0\x01\x02\x03") == []
|
|
|
|
|
|
def test_probe_port_reads_simulated_scale():
|
|
opener = SimulatorBank("toledo_cont").opener(open_real)
|
|
result = probe.probe_port("COM90", 9600, "8N1", 1.2, opener=opener)
|
|
assert result["ok"] is True, result
|
|
assert result["bytes"] > 0
|
|
assert result["frames"]
|
|
assert any(g["protocol"] == "toledo_cont" for g in result["guesses"])
|
|
assert result["settings"].startswith("COM90 9600 8N1")
|
|
|
|
|
|
def test_probe_port_rejects_bad_framing():
|
|
with pytest.raises(probe.ProbeError):
|
|
probe.probe_port("COM90", 9600, "9X9", 1)
|
|
|
|
|
|
def test_probe_port_sweep_reports_hits():
|
|
opener = SimulatorBank("toledo_cont").opener(open_real)
|
|
rows = probe.sweep("COM90", seconds=0.6, framings=("8N1",), bauds=(9600, 4800),
|
|
opener=opener)
|
|
hits = [row for row in rows if row.get("bytes")]
|
|
assert hits
|
|
assert any(g["protocol"] == "toledo_cont" for g in hits[0]["guesses"])
|
|
|
|
|
|
def test_save_capture_uses_one_frame_per_line(tmp_path):
|
|
frames = [{"hex": "01 02 03"}, {"hex": "AA BB"}]
|
|
target = probe.save_capture(tmp_path, "bizerba bc800", frames)
|
|
assert target.exists()
|
|
assert target.read_text(encoding="ascii").splitlines() == ["01 02 03", "AA BB"]
|
|
assert "bizerba-bc800" in target.name
|