Skip to content

Commit

Permalink
tests: more test fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Jan 27, 2025
1 parent c45b5e6 commit 1ff075e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
File renamed without changes.
28 changes: 9 additions & 19 deletions tests/test_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
class ImagingTests(unittest.TestCase):
"""test imaging schemas"""

def test_constructors(self):
"""testing constructors"""
def test_acquisition_constructor(self):
"""testing Acquisition constructor"""
with self.assertRaises(ValidationError):
acq.Acquisition()

Expand Down Expand Up @@ -76,11 +76,11 @@ def test_constructors(self):

self.assertIsNotNone(a)

def test_instrument_constructor(self):
"""testing Instrument constructor"""
with self.assertRaises(ValidationError):
Instrument()

# Generate a valid instrument

objective = Objective(
name="TLX Objective",
numerical_aperture=0.2,
Expand All @@ -102,7 +102,8 @@ def test_constructors(self):

self.assertIsNotNone(i)

# Instrument type Other requires notes
def test_instrument_type_other_requires_notes(self):
"""testing Instrument type Other requires notes"""
with self.assertRaises(ValidationError) as e1:
Instrument(
instrument_id="room_exaSPIM1-1_20231004",
Expand All @@ -114,7 +115,8 @@ def test_constructors(self):

self.assertIn("instrument_id", repr(e1.exception))

# Modality SPIM requirements components
def test_modality_spim_requires_components(self):
"""testing Modality SPIM requires components"""
with self.assertRaises(ValidationError) as e2:
Instrument(
instrument_id="room_exaSPIM1-1_20231004",
Expand All @@ -124,19 +126,7 @@ def test_constructors(self):
manufacturer=Organization.OTHER,
)

expected_exception2 = (
"2 validation errors for Instrument\n"
"modification_date\n"
" Field required [type=missing, input_value={'instrument_type': 'diSP...[],"
" 'light_sources': []}, input_type=dict]\n"
f" For further information visit https://errors.pydantic.dev/{PYD_VERSION}/v/missing\n"
"notes\n"
" Value error, Notes cannot be empty if manufacturer is Other."
" Describe the manufacturer in the notes field."
" [type=value_error, input_value=None, input_type=NoneType]\n"
f" For further information visit https://errors.pydantic.dev/{PYD_VERSION}/v/value_error"
)
self.assertEqual(expected_exception2, repr(e2.exception))
self.assertIn("modality 'SPIM' requires at least one device", repr(e2.exception))

def test_axis(self):
"""test the axis class"""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_inst_acq_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
from aind_data_schema_models.brain_atlas import CCFStructure

EXAMPLES_DIR = Path(__file__).parents[1] / "examples"
EPHYS_INST_JSON = EXAMPLES_DIR / "ephys_inst.json"
EPHYS_INST_JSON = EXAMPLES_DIR / "ephys_instrument.json"
EPHYS_SESSION_JSON = EXAMPLES_DIR / "ephys_session.json"

behavior_computer = "W10DT72941"
Expand Down Expand Up @@ -761,7 +761,7 @@ def read_json(filepath: Path) -> dict:
],
),
]
additional_devices = [d.Device(device_type="Photometry Clock", name="Photometry Clock")]
additional_devices = [d.Device(name="Photometry Clock")]

cls.example_ephys_inst = Instrument.model_validate_json(json.dumps(read_json(EPHYS_INST_JSON)))
cls.example_ephys_session = Session.model_validate_json(json.dumps(read_json(EPHYS_SESSION_JSON)))
Expand Down
33 changes: 20 additions & 13 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@

PYD_VERSION = re.match(r"(\d+.\d+).\d+", pyd_version).group(1)

ephys_assembly = EphysAssembly(
probes=[EphysProbe(probe_model="Neuropixels 1.0", name="Probe A")],
manipulator=Manipulator(
name="Probe manipulator",
manufacturer=Organization.NEW_SCALE_TECHNOLOGIES,
serial_number="4321",
),
name="Ephys_assemblyA",
)


class TestMetadata(unittest.TestCase):
"""Class to test Metadata model"""
Expand Down Expand Up @@ -322,7 +332,12 @@ def test_validate_ecephys_metadata(self):
subject_id="655019",
),
procedures=Procedures.model_construct(subject_procedures=[surgery1]),
instrument=Instrument.model_construct(modalities=modalities),
instrument=Instrument.model_construct(
modalities=modalities,
components=[
ephys_assembly,
],
),
)
self.assertIn(
"ECEPHYS metadata missing required file: subject",
Expand Down Expand Up @@ -350,15 +365,6 @@ def test_validate_ecephys_metadata(self):

def test_validate_instrument_session_compatibility(self):
"""Tests that instrument/session compatibility validator works as expected"""
ephys_assembly = EphysAssembly(
probes=[EphysProbe(probe_model="Neuropixels 1.0", name="Probe A")],
manipulator=Manipulator(
name="Probe manipulator",
manufacturer=Organization.NEW_SCALE_TECHNOLOGIES,
serial_number="4321",
),
name="Ephys_assemblyA",
)

mouse_platform = MousePlatform.model_construct(name="platform1")
inst = Instrument.model_construct(
Expand All @@ -367,7 +373,6 @@ def test_validate_instrument_session_compatibility(self):
modalities=[Modality.ECEPHYS],
components=[ephys_assembly],
)
session = Session.model_construct(instrument_id="123_EPHYS2_20230101", mouse_platform_name="platform2")
with self.assertRaises(ValidationError) as context:
Metadata(
name="655019_2023-04-03_18-17-09",
Expand All @@ -381,9 +386,11 @@ def test_validate_instrument_session_compatibility(self):
procedures=Procedures.model_construct(),
instrument=inst,
processing=Processing.model_construct(),
session=session,
acquisition=Acquisition.model_construct(
instrument_id="123_EPHYS2_20230101",
),
session=Session.model_construct(instrument_id="123_EPHYS2_20230101"),
)
print(str(context.exception))
self.assertIn(
"Instrument ID in session 123_EPHYS2_20230101 does not match the rig's 123_EPHYS1_20220101.",
str(context.exception),
Expand Down

0 comments on commit 1ff075e

Please sign in to comment.