diff --git a/src/openflexure_microscope_server/things/camera/__init__.py b/src/openflexure_microscope_server/things/camera/__init__.py index b43b8dd9..049f2a29 100644 --- a/src/openflexure_microscope_server/things/camera/__init__.py +++ b/src/openflexure_microscope_server/things/camera/__init__.py @@ -323,14 +323,14 @@ class BaseCamera(OFMThing): os.makedirs(output_dir, exist_ok=True) timestamp = time.strftime("%Y%m%d_%H%M%S") - log_path = os.path.join( + datafile_path = os.path.join( output_dir, f"framerate_{timestamp}.json", ) self.logger.info( "Framerate monitor started -> %s", - log_path, + datafile_path, ) self._framerate_monitor_running = True @@ -363,15 +363,15 @@ class BaseCamera(OFMThing): avg_fps, ) - with open(log_path, "w") as f: + with open(datafile_path, "w") as f: json.dump(data, f, indent=2) self.logger.info( "Framerate monitor complete -> %s", - log_path, + datafile_path, ) - return log_path + return datafile_path @lt.property def stream_active(self) -> bool: diff --git a/src/openflexure_microscope_server/things/camera/picamera.py b/src/openflexure_microscope_server/things/camera/picamera.py index 93f536fa..b76d4ed5 100644 --- a/src/openflexure_microscope_server/things/camera/picamera.py +++ b/src/openflexure_microscope_server/things/camera/picamera.py @@ -167,7 +167,6 @@ class StreamingPiCamera2(BaseCamera): self._sensor_info = SUPPORTED_CAMS_SENSOR_INFO[camera_board] self._picamera_lock = RLock() self._picamera = None - self._framerate_monitor_running = False # Load the tuning file for the specified sensor mode. self.default_tuning = tf_utils.load_default_tuning( diff --git a/tests/shared_utils/lt_test_utils.py b/tests/shared_utils/lt_test_utils.py index 19b61723..6e272c1d 100644 --- a/tests/shared_utils/lt_test_utils.py +++ b/tests/shared_utils/lt_test_utils.py @@ -48,7 +48,11 @@ class LabThingsTestEnv: self._test_client: Optional[TestClient] self._things_config = things self._settings_folder = settings_folder - self._application_config = application_config + # Labthings requires an application config for the data_folder + if application_config: + self._application_config = application_config + else: + self._application_config = {"data_folder": tempfile.TemporaryDirectory()} self._tmp_dir_obj: Optional[tempfile.TemporaryDirectory] = None def __enter__(self) -> Self: diff --git a/tests/unit_tests/test_base_camera.py b/tests/unit_tests/test_base_camera.py index c8b64274..aba5b4ea 100644 --- a/tests/unit_tests/test_base_camera.py +++ b/tests/unit_tests/test_base_camera.py @@ -5,8 +5,6 @@ test_simulated_camera.py and for testing the consistency of camera APIs see test_cameras.py. """ -import tempfile - import numpy as np import pytest from PIL import Image @@ -21,8 +19,7 @@ from ..shared_utils.lt_test_utils import LabThingsTestEnv def test_env() -> LabThingsTestEnv: """Yield a test environment with the Simulated Camera and Dummy Stage.""" thing_conf = {"camera": SimulatedCamera, "stage": DummyStage} - app_config = {"data_folder": tempfile.gettempdir()} - with LabThingsTestEnv(things=thing_conf, application_config=app_config) as env: + with LabThingsTestEnv(things=thing_conf) as env: yield env diff --git a/tests/unit_tests/test_metadata.py b/tests/unit_tests/test_metadata.py index 4b158e5a..7c5f87b6 100644 --- a/tests/unit_tests/test_metadata.py +++ b/tests/unit_tests/test_metadata.py @@ -1,7 +1,6 @@ """Tests that captures have the expected metadata.""" import json -import tempfile from datetime import datetime from pathlib import Path @@ -100,8 +99,7 @@ def test_env() -> LabThingsTestEnv: "stage": DummyStage, "bg_channel_deviations_luv": ChannelDeviationLUV, } - app_config = {"data_folder": tempfile.gettempdir()} - with LabThingsTestEnv(things=thing_conf, application_config=app_config) as env: + with LabThingsTestEnv(things=thing_conf) as env: yield env diff --git a/tests/unit_tests/test_simulated_camera.py b/tests/unit_tests/test_simulated_camera.py index 8b76106c..99f486be 100644 --- a/tests/unit_tests/test_simulated_camera.py +++ b/tests/unit_tests/test_simulated_camera.py @@ -1,7 +1,6 @@ """Test the functionality specific to the simulated camera.""" import logging -import tempfile import time import numpy as np @@ -29,9 +28,7 @@ def test_env() -> LabThingsTestEnv: "bg_channel_deviations_luv": ChannelDeviationLUV, } - app_config = {"data_folder": tempfile.gettempdir()} - - with LabThingsTestEnv(things=thing_conf, application_config=app_config) as env: + with LabThingsTestEnv(things=thing_conf) as env: yield env diff --git a/tests/unit_tests/test_stage.py b/tests/unit_tests/test_stage.py index a699b65f..f922ef65 100644 --- a/tests/unit_tests/test_stage.py +++ b/tests/unit_tests/test_stage.py @@ -2,7 +2,6 @@ import itertools import logging -import tempfile import threading import time from dataclasses import dataclass @@ -177,8 +176,7 @@ def test_direction_inversion(dummy_stage): def test_direction_errors_local_and_http(): """Check for expected errors both locally and over http.""" thing_conf = {"camera": SimulatedCamera, "stage": DummyStage} - app_config = {"data_folder": tempfile.gettempdir()} - with LabThingsTestEnv(things=thing_conf, application_config=app_config) as test_env: + with LabThingsTestEnv(things=thing_conf) as test_env: dummy_stage = test_env.get_thing_by_type(DummyStage) stage_client = test_env.get_thing_client("stage")