File: test_zptrlist.py

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (76 lines) | stat: -rw-r--r-- 1,871 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from neuron import h


def test_random_play():  # for coverage of ptrlist changes #1815
    cv = h.CVode()
    cv.active(0)
    cv.cache_efficient(0)
    h.secondorder = 0
    s = h.Section()
    s.L = 10
    s.diam = 10
    ic = h.IClamp(s(0.5))
    ic.delay = 0
    ic.dur = 10
    ic.amp = 0
    r = h.Random()
    r.Random123(1, 0, 0)
    r.uniform(0.0, 0.001)
    r.play(ic._ref_amp)
    v_vec = h.Vector()
    v_vec.record(s(0.5)._ref_v, sec=s)
    h.dt = 0.025
    h.finitialize(0)
    for _ in range(3):
        h.fadvance()
    std = h.Vector(
        [0.0, 0.00046940111168614074, 0.004571699024450762, 0.01086603263672303]
    )
    assert v_vec.c().sub(std).abs().sum() < 1e-15


def test_hoc_list():  # for coverage of ptrlist changes in ivoc/oc_list.cpp
    lst = h.List()
    lst.append(h.Vector().append(0))
    lst.append(h.Vector().append(1))
    lst.insrt(1, h.Vector().append(2))
    assert [v.x[0] for v in lst] == [0.0, 2.0, 1.0]


def test_rvp():  # for coverage of ptrlist changes in nrniv/shape.cpp
    d = [h.Section(name="d_" + str(i)) for i in range(3)]
    for i in range(1, 3):
        d[i].connect(d[i - 1](1))
    for s in d:
        s.L = 10
        s.diam = 1
        s.insert("pas")
    rvp = h.RangeVarPlot("v", d[0](0), d[2](1))
    assert rvp.left() == 0.0
    assert rvp.right() == 30.0
    sl = h.SectionList()
    rvp.list(sl)
    sz = sum([1 for _ in sl])
    assert sz == 3


def test_finithnd():
    # ptrlist #1815 coverage of nrniv/finithnd.cpp
    import sys, io

    def foo():
        pass

    fih = h.FInitializeHandler(foo)
    oldstdout = sys.stdout
    sys.stdout = mystdout = io.StringIO()
    fih.allprint()
    sys.stdout = oldstdout
    assert "Type 1 FInitializeHandler statements" in mystdout.getvalue()


if __name__ == "__main__":
    test_random_play()
    test_hoc_list()
    test_rvp()
    test_finithnd()