Skip to content

Commit a9f06fd

Browse files
committed
Update device_type in metadata and add tests for DeviceTypeMixin
1 parent 3b29a5d commit a9f06fd

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

tests/data/metadata/2025-12-02T13-45-23/Metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
},
1212
"camera": {
13-
"device_type": "SpinnakerCamera",
13+
"device_type": "DummyCamera",
1414
"serial_number": "00000",
1515
"exposure_time": 1000.0,
1616
"gain": 0.0,
@@ -19,7 +19,7 @@
1919
},
2020
"feeder": {
2121
"Feeder1": {
22-
"device_type": "HarpOutputExpander",
22+
"device_type": "DummyFeeder",
2323
"port_name": "COM6",
2424
"pellet_delivery_retry_count": 2,
2525
"pellet_delivery_timeout": 1.0,

tests/test_unit/schema/test_base.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import os
44
from enum import StrEnum
5-
from typing import ClassVar, Literal
5+
from typing import ClassVar, Literal, get_args, get_origin
66

7+
import pytest
78
from pydantic import Field
89

910
from swc.aeon.io.api import load
@@ -18,7 +19,6 @@
1819
class DummyHarpDevice(HarpDevice):
1920
"""A dummy Harp device."""
2021

21-
device_type: Literal["DummyHarpDevice"] = "DummyHarpDevice"
2222
who_am_i: ClassVar[int] = 0000
2323

2424
@data_reader
@@ -106,3 +106,19 @@ def test_dataset_read_metadata(test_data_dir):
106106
"""Test that dataset Metadata is loaded successfully."""
107107
metadata = load(test_data_dir, Metadata(DummyDataset))
108108
assert len(metadata) > 0
109+
110+
111+
@pytest.mark.parametrize(
112+
("device_instance", "expected_device_type"),
113+
[
114+
(DummyHarpDevice(port_name="COM3"), "DummyHarpDevice"),
115+
(DummyCamera(serial_number="12345"), "DummyCamera"),
116+
],
117+
)
118+
def test_device_type_mixin(device_instance, expected_device_type):
119+
"""Test that DeviceTypeMixin correctly sets device_type to the subclass name."""
120+
assert device_instance.device_type == expected_device_type
121+
# Check that the device_type annotation is Literal[expected_device_type]
122+
annotation = type(device_instance).__annotations__["device_type"]
123+
assert get_origin(annotation) == Literal
124+
assert get_args(annotation) == (expected_device_type,)

0 commit comments

Comments
 (0)