From 5be8b0ecab182bf2d636399815a84840314e38b3 Mon Sep 17 00:00:00 2001 From: jaknapper Date: Wed, 13 May 2026 18:07:29 +0100 Subject: [PATCH] Update tests, including picamera --- picamera_coverage.zip | Bin 54038 -> 54038 bytes .../things/camera/__init__.py | 16 +++++++++------ .../picamera2/test_acquisition.py | 19 +++++------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/picamera_coverage.zip b/picamera_coverage.zip index a29f518f023a9183533f48a1cac72e3307fe8dd0..16fdc31272ab91c56235a78e16b3236122b9f616 100644 GIT binary patch delta 507 zcmbQXjCtBJW}yIYW)=|!5V$#EZOr`q^ZPamsWgaOXW;+I|Av1je;dCH-w8ffK2F~2 zn;ixA@=g}(>q$+waJtPDBmDN|#ea3Y|Lp$0-*P>HH;04a{a!sQiTDlC%m?xt-!m|1 zJgEOKH%Hbk_waf~28Mqd85y!N7z}b44%D%=*k>_F9B43YkiNt4M_+>B0LTRl2@DJj z%m*0q7}(-}b5CaP52?>!Wo6`S3}9vY_1$c@(8wgo+&D4KB+)Fz z!qD8rBF)mw#4^<+$!PM03(gvr#%ZR;W@(9uX(k4#hAF0ImT76p#wKZrmZ^!x24-fd zh8C74iAiRYFI=#h+~X%Yx#!|xJEJ5ML*qn~6eELFQv-{Xlw_k6^E6`v^HgJV3uB{H hQ$zFAB=b}Q1EtykZ$>5&X4D9s+XI*g}IFDI=_9%sNc_4KmT9(t?UhKW-JZg+t2?wMO@a8f66X#(_0J(s{fPtZb zF@eFHp?UpZ*2zEmLSmv=Ss6JSO<0+JeK*^zV?0~3ON5ajpMinFfrXEuxr%XPTqB#o z0|o^K2_CZzj5io!Y;_rKh&9wkI4}t_FmI4#U{G$5elee6?(<`3MVK@mH1IYUvSnwQ z8aPO+Oy1U?#>2(L!pJGc)Rbz&^HImHDQcO})ObrrKEG<*b&65l) zjS^E*3=PsOj180142;ZDOihiGO($QtU^BVLPjqt6#lv>VrpA`3mT6{|$!5t0$%%%> wDaNTOX354DW@bhvsm5tWhDN652C2qMwE^CYOd`yvku|yZk_E!WXD@jI0E}^$UH||9 diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index fe24bdc2..b43b8dd9 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -8,7 +8,6 @@ See repository root for licensing information. from __future__ import annotations -import asyncio import io import json import os @@ -338,11 +337,9 @@ class BaseCamera(OFMThing): # This runs as an async task, which we wait to complete try: - total_time, frames, samples = ( - self._thing_server_interface.call_async_task( - self._monitor_framerate, - duration, - ) + total_time, frames, samples = self._thing_server_interface.call_async_task( + self._monitor_framerate, + duration, ) finally: @@ -359,6 +356,13 @@ class BaseCamera(OFMThing): "samples": samples, } + self.logger.info( + ("Framerate monitor results: duration=%.2fs, frames=%d, avg_fps=%.2f"), + total_time, + frames, + avg_fps, + ) + with open(log_path, "w") as f: json.dump(data, f, indent=2) diff --git a/tests/hardware_specific_tests/picamera2/test_acquisition.py b/tests/hardware_specific_tests/picamera2/test_acquisition.py index 3609bdd7..7ac49e3a 100644 --- a/tests/hardware_specific_tests/picamera2/test_acquisition.py +++ b/tests/hardware_specific_tests/picamera2/test_acquisition.py @@ -1,7 +1,6 @@ """Test data collection from the Raspberry Picamera.""" import json -import time from pathlib import Path import numpy as np @@ -35,19 +34,12 @@ def test_jpeg_and_array(picamera_client): assert array_main.shape[1::-1] == jpeg_capture.size -def test_record_framerate_async(picamera_client): - """Check that asynchronous framerate monitoring creates a valid JSON log.""" - returned_dir = Path(picamera_client.record_framerate_async(duration=1.0)) +def test_record_framerate(picamera_client): + """Check that framerate monitoring creates a valid JSON log with good data.""" + log_file = Path(picamera_client.record_framerate(duration=1.0)) - # Wait slightly longer than recording duration for async task completion - time.sleep(1.5) - - log_files = list(returned_dir.glob("framerate_*.json")) - - # Ensure exactly one log file was created - assert len(log_files) == 1 - - log_file = log_files[0] + assert log_file.exists() + assert log_file.is_file() # Ensure file is not empty assert log_file.stat().st_size > 0 @@ -74,7 +66,6 @@ def test_record_framerate_async(picamera_client): sample = samples[0] - # Each sample row equivalent assert "timestamp" in sample assert "frame_count" in sample assert "frame_size_bytes" in sample