def test_unit_checking(): # dummy Variable class class S(object): def __init__(self, unit): self.unit = unit # inconsistent unit for a differential equation eqs = Equations('dv/dt = -v : volt') group = SimpleGroup({'v': S(volt)}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) eqs = Equations('dv/dt = -v / tau: volt') group = SimpleGroup(namespace={'tau': 5 * mV}, variables={'v': S(volt)}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) group = SimpleGroup(namespace={'I': 3 * second}, variables={'v': S(volt)}) eqs = Equations('dv/dt = -(v + I) / (5 * ms): volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) eqs = Equations('''dv/dt = -(v + I) / (5 * ms): volt I : second''') group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) # inconsistent unit for a subexpression eqs = Equations('''dv/dt = -v / (5 * ms) : volt I = 2 * v : amp''') group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group))
def test_unit_checking(): # dummy Variable class class S(object): def __init__(self, dimensions): self.dim = get_dimensions(dimensions) # inconsistent unit for a differential equation eqs = Equations('dv/dt = -v : volt') group = SimpleGroup({'v': S(volt)}) with pytest.raises(DimensionMismatchError): eqs.check_units(group, {}) eqs = Equations('dv/dt = -v / tau: volt') group = SimpleGroup(namespace={'tau': 5 * mV}, variables={'v': S(volt)}) with pytest.raises(DimensionMismatchError): eqs.check_units(group, {}) group = SimpleGroup(namespace={'I': 3 * second}, variables={'v': S(volt)}) eqs = Equations('dv/dt = -(v + I) / (5 * ms): volt') with pytest.raises(DimensionMismatchError): eqs.check_units(group, {}) eqs = Equations("""dv/dt = -(v + I) / (5 * ms): volt I : second""") group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) with pytest.raises(DimensionMismatchError): eqs.check_units(group, {}) # inconsistent unit for a subexpression eqs = Equations("""dv/dt = -v / (5 * ms) : volt I = 2 * v : amp""") group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) with pytest.raises(DimensionMismatchError): eqs.check_units(group, {})
def test_unit_checking(): # dummy Variable class class S(object): def __init__(self, unit): self.unit = unit # Let's create a namespace with a user-defined namespace that we can # updater later on namespace = create_namespace({}) # inconsistent unit for a differential equation eqs = Equations('dv/dt = -v : volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) eqs = Equations('dv/dt = -v / tau: volt') namespace['tau'] = 5*mV assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) namespace['I'] = 3*second eqs = Equations('dv/dt = -(v + I) / (5 * ms): volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) eqs = Equations('''dv/dt = -(v + I) / (5 * ms): volt I : second''') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt), 'I': S(second)})) # inconsistent unit for a static equation eqs = Equations('''dv/dt = -v / (5 * ms) : volt I = 2 * v : amp''') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt), 'I': S(amp)}))
def test_unit_checking(): # dummy Variable class class S(object): def __init__(self, unit): self.unit = unit # inconsistent unit for a differential equation eqs = Equations('dv/dt = -v : volt') group = SimpleGroup({'v': S(volt)}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) eqs = Equations('dv/dt = -v / tau: volt') group = SimpleGroup(namespace={'tau': 5*mV}, variables={'v': S(volt)}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) group = SimpleGroup(namespace={'I': 3*second}, variables={'v': S(volt)}) eqs = Equations('dv/dt = -(v + I) / (5 * ms): volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) eqs = Equations('''dv/dt = -(v + I) / (5 * ms): volt I : second''') group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group)) # inconsistent unit for a subexpression eqs = Equations('''dv/dt = -v / (5 * ms) : volt I = 2 * v : amp''') group = SimpleGroup(variables={'v': S(volt), 'I': S(second)}, namespace={}) assert_raises(DimensionMismatchError, lambda: eqs.check_units(group))
def test_unit_checking(): # dummy Variable class class S(object): def __init__(self, unit): self.unit = unit # Let's create a namespace with a user-defined namespace that we can # updater later on namespace = create_namespace({}) # inconsistent unit for a differential equation eqs = Equations('dv/dt = -v : volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) eqs = Equations('dv/dt = -v / tau: volt') namespace['tau'] = 5 * mV assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) namespace['I'] = 3 * second eqs = Equations('dv/dt = -(v + I) / (5 * ms): volt') assert_raises(DimensionMismatchError, lambda: eqs.check_units(namespace, {'v': S(volt)})) eqs = Equations('''dv/dt = -(v + I) / (5 * ms): volt I : second''') assert_raises( DimensionMismatchError, lambda: eqs.check_units(namespace, { 'v': S(volt), 'I': S(second) })) # inconsistent unit for a static equation eqs = Equations('''dv/dt = -v / (5 * ms) : volt I = 2 * v : amp''') assert_raises( DimensionMismatchError, lambda: eqs.check_units(namespace, { 'v': S(volt), 'I': S(amp) }))