Skip to content

Commit 7583847

Browse files
committed
test coverage
1 parent f6eaecf commit 7583847

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

src/aind_data_schema/rig.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def validate_device_names(cls, values): # noqa: C901
149149

150150
return values
151151

152-
def validate_modality(cls, v): # noqa: C901
152+
@root_validator
153+
def validate_modality(cls, v):
153154
"""Validator to ensure all expected fields are present, based on given modality"""
154155

155156
modalities = v.get("modalities")

tests/test_imaging.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
from pydantic import ValidationError
77

8-
from aind_data_schema.device import Calibration
8+
from aind_data_schema.device import Calibration, DAQChannel
99
from aind_data_schema.imaging import acquisition as acq
1010
from aind_data_schema.imaging import instrument as inst
1111
from aind_data_schema.imaging import mri_session as ms
1212
from aind_data_schema.imaging import tile
1313
from aind_data_schema.manufacturers import Manufacturer
1414
from aind_data_schema.processing import Registration
1515
from aind_data_schema.utils.units import PowerValue
16+
from aind_data_schema.rig import NeuropixelsBasestation
1617

1718

1819
class ImagingTests(unittest.TestCase):
@@ -187,6 +188,51 @@ def test_registration(self):
187188

188189
assert t is not None
189190

191+
def test_validators(self):
192+
193+
with self.assertRaises(ValidationError):
194+
inst.Instrument(
195+
instrument_type="diSPIM",
196+
modification_date=datetime.datetime.now(),
197+
manufacturer=Manufacturer.LIFECANVAS,
198+
objectives=[],
199+
detectors=[],
200+
light_sources=[],
201+
daqs=[
202+
NeuropixelsBasestation(
203+
basestation_firmware_version="1",
204+
bsc_firmware_version="2",
205+
slot=0,
206+
manufacturer=Manufacturer.IMEC,
207+
ports=[],
208+
computer_name="foo",
209+
channels=[
210+
DAQChannel(
211+
channel_name="123",
212+
device_name="Laser A",
213+
channel_type="Analog Output",
214+
),
215+
DAQChannel(
216+
channel_name="321",
217+
device_name="Probe A",
218+
channel_type="Analog Output",
219+
),
220+
DAQChannel(
221+
channel_name="234",
222+
device_name="Camera A",
223+
channel_type="Digital Output",
224+
),
225+
DAQChannel(
226+
channel_name="2354",
227+
device_name="Disc A",
228+
channel_type="Digital Output",
229+
),
230+
],
231+
),
232+
]
233+
)
234+
235+
190236

191237
if __name__ == "__main__":
192238
unittest.main()

tests/test_rig.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,48 @@ def test_validator(self):
248248
mouse_platform=Disc(name="Disc A", radius=1),
249249
)
250250

251+
with self.assertRaises(ValidationError):
252+
253+
daqs = [
254+
NeuropixelsBasestation(
255+
basestation_firmware_version="1",
256+
bsc_firmware_version="2",
257+
slot=0,
258+
manufacturer=Manufacturer.IMEC,
259+
ports=[],
260+
computer_name="foo",
261+
channels=[
262+
DAQChannel(
263+
channel_name="123",
264+
device_name="Laser A",
265+
channel_type="Analog Output",
266+
),
267+
DAQChannel(
268+
channel_name="321",
269+
device_name="Probe A",
270+
channel_type="Analog Output",
271+
),
272+
DAQChannel(
273+
channel_name="234",
274+
device_name="Camera A",
275+
channel_type="Digital Output",
276+
),
277+
DAQChannel(
278+
channel_name="2354",
279+
device_name="Disc A",
280+
channel_type="Digital Output",
281+
),
282+
],
283+
)
284+
]
285+
286+
Rig(
287+
rig_id="1234",
288+
modification_date=datetime.datetime.now(),
289+
modalities=[Modality.ECEPHYS, Modality.FIB],
290+
daqs=daqs,
291+
)
292+
251293

252294
if __name__ == "__main__":
253295
unittest.main()

0 commit comments

Comments
 (0)