Skip to content

Commit

Permalink
test cover globals and parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Oct 22, 2024
1 parent ccd84e3 commit e48d6ab
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
16 changes: 16 additions & 0 deletions test/usecases/global/global.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NEURON {
SUFFIX global
GLOBAL gbl
}

ASSIGNED {
gbl
}

FUNCTION get_gbl() {
get_gbl = gbl
}

PROCEDURE set_gbl(value) {
gbl = value
}
11 changes: 11 additions & 0 deletions test/usecases/global/parameter.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
NEURON {
SUFFIX parameter
}

PARAMETER {
gbl = 42.0
}

FUNCTION get_gbl() {
get_gbl = gbl
}
28 changes: 22 additions & 6 deletions test/usecases/global/test_without_instance.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
from neuron import h, gui


def make_accessors(mech_name):
def make_accessors(mech_name, read_only):
get = getattr(h, f"get_gbl_{mech_name}")
set = getattr(h, f"set_gbl_{mech_name}")

if read_only:
return get, None

set = getattr(h, f"set_gbl_{mech_name}")
return get, set


def check_write_read_cycle(mech_name):
get, set = make_accessors(mech_name)
def check_write_read_cycle(mech_name, read_only=False):
get, set = make_accessors(mech_name, read_only)

expected = 278.045
set(expected)
if read_only:
expected = 42.0
else:
expected = 278.045
set(expected)

actual = get()
assert (
Expand All @@ -24,5 +30,15 @@ def test_top_local():
check_write_read_cycle("top_local")


def test_global():
check_write_read_cycle("global")


def test_parameter():
check_write_read_cycle("parameter", True)


if __name__ == "__main__":
test_top_local()
test_global()
test_parameter()

0 comments on commit e48d6ab

Please sign in to comment.