Share waveform data and plot navigation and retain processing results

This commit is contained in:
2026-09-27 02:47:24 +03:00
parent 513e79b127
commit caf30f2ed6
5 changed files with 534 additions and 31 deletions

View File

@@ -36,14 +36,81 @@ class ProcessingQtTests(unittest.TestCase):
self.assertIsNone(self.panel._job)
self.assertIsNotNone(self.panel.curve, self.panel.status.text())
def test_all_methods_are_available_and_parameter_changes_clear_result(self):
for method in ("polynomial", "linear", "pchip", "spline"):
def test_all_methods_accumulate_and_parameter_changes_keep_results(self):
for index, method in enumerate(("polynomial", "linear", "pchip", "spline")):
self.panel.method.setCurrentIndex(self.panel.method.findData(method))
self.calculate()
self.assertEqual(method, self.panel.curve.request.method)
self.panel.count.setValue(self.panel.count.value() + 1)
self.assertIsNone(self.panel.curve)
self.assertFalse(self.panel.export_button.isEnabled())
self.assertEqual(index + 1, len(self.panel.curves))
self.assertTrue(self.panel.export_button.isEnabled())
specs, data = self.panel.overlay()
self.assertEqual(4, len(specs))
self.assertEqual(4, len(data))
self.assertEqual(4, len({spec[3] for spec in specs}))
self.panel.clear()
self.assertEqual((), self.panel.curves)
self.assertIsNone(self.panel.curve)
def test_repeated_request_does_not_duplicate_curve(self):
self.calculate()
self.calculate()
self.assertEqual(1, len(self.panel.curves))
def test_repeated_fft_workers_keep_gui_owned_signal_emitters(self):
self.panel.set_snapshot(replace(self.snapshot, axis=Axis("Frequency", "Hz"), source="FFT"))
for _ in range(5):
for method in ("linear", "pchip", "spline", "polynomial"):
self.panel.method.setCurrentIndex(self.panel.method.findData(method))
self.panel.calculate()
self.assertIs(self.panel, self.panel._job.signals.parent())
deadline = time.monotonic() + 5
while self.panel._job is not None and time.monotonic() < deadline:
self.app.processEvents()
time.sleep(.002)
self.assertIsNone(self.panel._job)
self.assertEqual(method, self.panel.curve.request.method)
self.assertEqual(4, len(self.panel.curves))
def test_switching_channel_preserves_results_and_invalidates_only_changed_source(self):
snapshot = replace(self.snapshot, series=self.snapshot.series +
(Series("b", "B", [(0, 2), (1, 3), (2, 2)]),))
self.panel.set_snapshot(snapshot)
self.calculate()
first = self.panel.curve
self.panel.channel.setCurrentIndex(1)
self.panel.set_snapshot(snapshot)
self.assertEqual((first,), self.panel.curves)
self.calculate()
second = self.panel.curve
self.assertEqual((first, second), self.panel.curves)
second_spec = self.panel.overlay()[0][1]
self.panel.set_snapshot(replace(snapshot, series=(
Series("a", "A", [(0, 5), (1, 6)]), snapshot.series[1])))
self.assertEqual((second,), self.panel.curves)
self.assertEqual(second_spec, self.panel.overlay()[0][0])
def test_navigation_during_second_calculation_preserves_both_results(self):
self.panel.preserve_on_view_change = True
self.calculate()
first = self.panel.curve
self.panel.method.setCurrentIndex(self.panel.method.findData("linear"))
with patch("set_devices.qt_ports.plot_processing.QThreadPool"):
self.panel.calculate()
job = self.panel._job
self.panel.set_snapshot(replace(self.snapshot, x_range=(0, 1)))
self.panel._finished(job.signature, process(job.signature), "")
self.assertEqual(2, len(self.panel.curves))
self.assertIs(first, self.panel.curves[0])
def test_failed_calculation_keeps_previous_curve(self):
self.calculate()
previous = self.panel.curve
self.panel.count.setValue(123)
with patch("set_devices.qt_ports.plot_processing.QThreadPool"):
self.panel.calculate()
self.panel._finished(self.panel._job.signature, None, "test error")
self.assertEqual((previous,), self.panel.curves)
def test_source_units_and_blocking_invalidate_result(self):
for changed in (replace(self.snapshot, axis=Axis("Frequency", "Hz")),