Skip to content

Commit

Permalink
tests: fixing various tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Jan 27, 2025
1 parent bc5c61f commit 7602294
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 50 deletions.
3 changes: 1 addition & 2 deletions src/aind_data_schema/core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"subject",
"data_description",
"procedures",
"session",
"instrument",
"processing",
"acquisition",
Expand Down Expand Up @@ -227,7 +226,7 @@ def validate_expected_files_by_modality(self):
if file not in requirement_dict:
requirement_dict[file] = (abbreviation, file_requirement)
else:
(prev_modality, prev_requirement) = requirement_dict[file]
(_, prev_requirement) = requirement_dict[file]

if (file_requirement == FileRequirement.REQUIRED) or (
file_requirement == FileRequirement.OPTIONAL
Expand Down
16 changes: 0 additions & 16 deletions tests/test_data_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,6 @@ def test_model_constructors(self):
assert Modality.from_abbreviation("ecephys") == Modality.ECEPHYS
assert Organization().name_map["Allen Institute for Neural Dynamics"] == Organization.AIND

def test_name_label_error(self):
"""Tests an error is raised if label and name are None"""

with self.assertRaises(ValidationError) as e:
DataDescription(
modalities=[Modality.SPIM],
subject_id="1234",
data_level="raw",
creation_time=datetime.datetime(2020, 10, 10, 10, 10, 10),
institution=Organization.AIND,
funding_source=[Funding(funder=Organization.NINDS, grant_number="grant001")],
investigators=[Person(name="Jane Smith")],
)
self.assertTrue("Value error, Either label or name must be set" in repr(e.exception))

def test_round_trip(self):
"""make sure we can round trip from json"""

Expand Down Expand Up @@ -378,7 +363,6 @@ def test_from_data_description(self):

dd1 = DerivedDataDescription.from_data_description(d1, process_name=process_name)
# check that the original name is in the derived name
print(dd1.name)
self.assertTrue("1234_2020-10-10T101010_spikesorter_" in dd1.name)
# check that the subject ID is retained
self.assertEqual("1234", dd1.subject_id)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Scale3dTransform,
Translation3dTransform,
)
from aind_data_schema.components.devices import Calibration
from aind_data_schema.components.devices import Calibration, Objective
from aind_data_schema.core import acquisition as acq
from aind_data_schema.core.processing import Registration
from aind_data_schema.core.instrument import Instrument
Expand Down
17 changes: 11 additions & 6 deletions tests/test_inst_acq_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,17 @@
instrument_id="323_EPHYS1_20231003",
modification_date=date(2023, 10, 3),
modalities=[Modality.ECEPHYS],
ephys_assemblies=[ephys_assemblyA, ephys_assemblyB],
cameras=[camassm1, camassm2],
laser_assemblies=[laser_assembly],
daqs=[basestation, harp],
stick_microscopes=[microscope],
mouse_platform=running_wheel,
components=[
ephys_assemblyA,
ephys_assemblyB,
camassm1,
camassm2,
laser_assembly,
basestation,
harp,
microscope,
running_wheel,
],
calibrations=[red_laser_calibration, blue_laser_calibration],
)

Expand Down
78 changes: 53 additions & 25 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pydantic import ValidationError
from pydantic import __version__ as pyd_version

from aind_data_schema.components.devices import EphysAssembly, EphysProbe, Manipulator, MousePlatform
from aind_data_schema.components.devices import Device, EphysAssembly, EphysProbe, LickSensorType, Manipulator, MotorizedStage, MousePlatform, Objective, RewardDelivery, RewardSpout, SpoutSide
from aind_data_schema.components.identifiers import Person
from aind_data_schema.core.acquisition import Acquisition
from aind_data_schema.core.data_description import DataDescription, Funding
Expand Down Expand Up @@ -205,26 +205,6 @@ def test_validate_smartspim_metadata(self):
str(context.exception),
)

# Tests excluded metadata getting included
surgery1 = Surgery.model_construct(procedures=[nano_inj, ionto_inj])
with self.assertRaises(ValidationError) as context:
Metadata(
name="ecephys_655019_2023-04-03_18-17-09",
location="bucket",
data_description=DataDescription.model_construct(
creation_time=time(12, 12, 12),
modalities=[Modality.SPIM],
),
subject=Subject.model_construct(),
session=Session.model_construct(),
procedures=Procedures.model_construct(subject_procedures=[surgery1]),
acquisition=Acquisition.model_construct(),
)
self.assertIn(
"SPIM metadata includes excluded file: session",
str(context.exception),
)

# Tests missing injection materials
surgery2 = Surgery.model_construct(procedures=[nano_inj])
with self.assertRaises(ValidationError) as context:
Expand Down Expand Up @@ -252,10 +232,56 @@ def test_multi_modal_metadata(self):
surgery1 = Surgery.model_construct(procedures=[nano_inj, ionto_inj])

mouse_platform = MousePlatform.model_construct(name="platform1")

objective = Objective(
name="TLX Objective",
numerical_aperture=0.2,
magnification=3.6,
immersion="multi",
manufacturer=Organization.THORLABS,
model="TL4X-SAP",
notes="Thorlabs TL4X-SAP with LifeCanvas dipping cap and correction optics.",
)

reward_delivery = RewardDelivery(
reward_spouts=[
RewardSpout(
name="Left spout",
side=SpoutSide.LEFT,
spout_diameter=1.2,
solenoid_valve=Device(name="Solenoid Left"),
lick_sensor=Device(
name="Janelia_Lick_Detector Left",
manufacturer=Organization.JANELIA,
),
lick_sensor_type=LickSensorType("Capacitive"),
),
RewardSpout(
name="Right spout",
side=SpoutSide.RIGHT,
spout_diameter=1.2,
solenoid_valve=Device(name="Solenoid Right"),
lick_sensor=Device(
name="Janelia_Lick_Detector Right",
manufacturer=Organization.JANELIA,
),
lick_sensor_type=LickSensorType("Capacitive"),
),
],
stage_type=MotorizedStage(
name="NewScaleMotor for LickSpouts",
serial_number="xxxx", # grabbing from GUI/SettingFiles
manufacturer=Organization.NEW_SCALE_TECHNOLOGIES,
travel=15.0, # unit is mm
firmware=("https://github.com/AllenNeuralDynamics/python-newscale,branch: axes-on-target,commit #7c17497"),
),
)

inst = Instrument.model_construct(
instrument_id="123_EPHYS1_20220101",
mouse_platform=mouse_platform,
modalities=[Modality.BEHAVIOR, Modality.SPIM],
components=[objective, reward_delivery],
)
session = Session.model_construct(instrument_id="123_EPHYS1_20220101", mouse_platform_name="platform1")

Expand Down Expand Up @@ -284,17 +310,18 @@ def test_validate_ecephys_metadata(self):

# Tests missing metadata
surgery1 = Surgery.model_construct(procedures=[nano_inj, ionto_inj])
modalities = [Modality.ECEPHYS]
with self.assertRaises(ValidationError) as context:
Metadata(
name="655019_2023-04-03_18-17-09",
location="bucket",
data_description=DataDescription.model_construct(
creation_time=time(12, 12, 12),
modalities=[Modality.ECEPHYS],
modalities=modalities,
subject_id="655019",
),
procedures=Procedures.model_construct(subject_procedures=[surgery1]),
instrument=Instrument.model_construct(),
instrument=Instrument.model_construct(modalities=modalities),
)
self.assertIn(
"ECEPHYS metadata missing required file: subject",
Expand All @@ -303,17 +330,18 @@ def test_validate_ecephys_metadata(self):

# Tests missing injection materials
surgery2 = Surgery.model_construct(procedures=[nano_inj])
modalities = [Modality.ECEPHYS]
with self.assertRaises(ValidationError) as context:
Metadata(
name="ecephys_655019_2023-04-03_18-17-09",
location="bucket",
data_description=DataDescription.model_construct(
creation_time=time(12, 12, 12),
modalities=[Modality.ECEPHYS],
modalities=modalities,
),
subject=Subject.model_construct(),
procedures=Procedures.model_construct(subject_procedures=[surgery2]),
instrument=Instrument.model_construct(),
instrument=Instrument.model_construct(modalities=modalities),
processing=Processing.model_construct(),
session=Session.model_construct(),
)
Expand Down

0 comments on commit 7602294

Please sign in to comment.