import quantities as pq
import sciunit
from sciunit.errors import ObservationError, ParametersError
from neuronunit.tests import APWidthTest
# Display the parameters schema for this test
APWidthTest.params_schema
{'dt': {'type': 'time', 'required': False}, 'tmax': {'type': 'time', 'min': 0, 'required': False}}
# Try to instantiate the test using a parameter (tmax) that has the wrong units.
# This should show an error message
try:
test = APWidthTest({'mean':3.2*pq.ms, 'std':1.4*pq.ms}, name="My Test", tmax=3*pq.mV) # Should fail due to incorrect units
raise Exception("Test should not have been allowed with incorrect parameter units")
except ParametersError as e:
print(e)
{'params': [{'3.0 mV': ['Must have dimensions of time.']}]}
# Now do it correctly. There should be no error message.
try:
test = APWidthTest({'mean':3.2*pq.ms, 'std':1.4*pq.ms}, name="My Test", tmax=3*pq.s) # Should validate successfully
except ParametersError as e:
print(e)
raise Exception("Test should have been allowed with correct parameter units")
from sciunit.validators import ParametersValidator
# Get the units type (e.g. "time") from the parameters schema
units_type = APWidthTest.params_schema['dt']['type']
# Get the actual units for this units type
ParametersValidator.units_map[units_type]
's'