Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
69 lines
2.8 KiB
Python
69 lines
2.8 KiB
Python
"""Synthetic operation routing; no acquisition or motor commands."""
|
|
|
|
import unittest
|
|
from unittest.mock import Mock, patch
|
|
|
|
import test_config_editor
|
|
from runtime.sample_data import validate
|
|
|
|
|
|
class SampleDataTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.base = test_config_editor.ConfigEditorTests()
|
|
self.base.setUp()
|
|
self.service, self.device = self.base.service, self.base.device
|
|
self.device.link.rpc = Mock(
|
|
return_value={"capture_id": "sample_" + "1" * 32, "state": "armed", "received": 0}
|
|
)
|
|
|
|
def tearDown(self):
|
|
self.base.tearDown()
|
|
|
|
def call(self, name, p):
|
|
c = self.base.command(action="vesc.samples." + name)
|
|
c["parameters"] = p
|
|
return self.service.execute(c)
|
|
|
|
def test_start_is_explicit_and_uses_existing_owner_without_motor_command(self):
|
|
self.assertEqual(self.device.link.rpc.call_count, 0)
|
|
p = {"mode": 4, "count": 500, "decimation": 2, "timeout_s": 30, "raw": False}
|
|
with patch.object(self.device.link, "query", wraps=self.base.query) as query:
|
|
result = self.call("start", p)
|
|
self.assertEqual(result["state"], "complete", result)
|
|
self.device.link.rpc.assert_called_once_with("sample_start", **p)
|
|
self.assertEqual([c.args[0] for c in query.call_args_list], [0])
|
|
self.assertEqual(self.base.writes, [])
|
|
|
|
def test_no_automatic_capture_on_status_and_pages_do_not_persist(self):
|
|
self.device.link.rpc.return_value = {"state": "complete", "rows": ["PRIVATE_SAMPLE_DATA"]}
|
|
result = self.call("read", {"capture_id": "sample_" + "1" * 32, "offset": 0})
|
|
self.assertEqual(result["state"], "complete", result)
|
|
self.device.link.rpc.assert_called_once_with(
|
|
"sample_read", capture_id="sample_" + "1" * 32, offset=0
|
|
)
|
|
for p in self.service.root.glob("op_*.json"):
|
|
self.assertNotIn("PRIVATE_SAMPLE_DATA", p.read_text())
|
|
|
|
def test_bad_parameters_never_reach_native(self):
|
|
base = {"mode": 1, "count": 2, "decimation": 1, "timeout_s": 30, "raw": False}
|
|
for key, value in [
|
|
("mode", 0),
|
|
("mode", 8),
|
|
("count", True),
|
|
("count", 2001),
|
|
("decimation", 0),
|
|
("timeout_s", 121),
|
|
("raw", True),
|
|
]:
|
|
with self.assertRaises(ValueError):
|
|
validate("vesc.samples.start", {**base, key: value})
|
|
self.assertEqual(self.device.link.rpc.call_count, 0)
|
|
|
|
def test_native_busy_is_rejection_not_usb_failure(self):
|
|
self.device.link.rpc.return_value = {"accepted": False, "reason": "Capture active"}
|
|
result = self.call(
|
|
"start", {"mode": 1, "count": 2, "decimation": 1, "timeout_s": 30, "raw": False}
|
|
)
|
|
self.assertEqual(result["state"], "error")
|
|
self.assertIsNotNone(self.device.link)
|