Example #1
0
def test_push_section():
    h('''create hCable1, hCable2''')
    h.push_section("hCable1")
    assert (h.secname() == "hCable1")
    h.pop_section()
    h.push_section("hCable2")
    assert (h.secname() == "hCable2")
    h.pop_section()
    h.delete_section(sec=h.hCable1)
    h.delete_section(sec=h.hCable2)

    sections = [h.Section(name="pCable%d" % i) for i in range(2)]
    sections.append(h.Section())  # Anonymous in the past
    for sec in sections:
        name_in_hoc = h.secname(sec=sec)
        h.push_section(name_in_hoc)
        assert (h.secname() == name_in_hoc)
        h.pop_section()
    s = sections[-1]
    h.delete_section(sec=s)  # but not yet freed (though the name is now "")
    # not [no longer] a section pointer
    expect_hocerr(h.push_section,
                  (int(s.hoc_internal_name().replace("__nrnsec_", ""), 0), ))
    # not a sectionname
    expect_hocerr(h.push_section, ("not_a_sectionname", ))
Example #2
0
def test_push_section():
    h("""create hCable1, hCable2""")
    h.push_section("hCable1")
    assert h.secname() == "hCable1"
    h.pop_section()
    h.push_section("hCable2")
    assert h.secname() == "hCable2"
    h.pop_section()
    h.delete_section(sec=h.hCable1)
    h.delete_section(sec=h.hCable2)

    sections = [h.Section(name="pCable%d" % i) for i in range(2)]
    sections.append(h.Section())  # Anonymous in the past
    for sec in sections:
        name_in_hoc = h.secname(sec=sec)
        h.push_section(name_in_hoc)
        assert h.secname() == name_in_hoc
        h.pop_section()
    s = sections[-1]
    h.delete_section(sec=s)  # but not yet freed (though the name is now "")
    # not [no longer] a section pointer
    expect_err(
        "s.hoc_internal_name()"
    )  # this is what is generating the error in the next statement.
    expect_err('h.push_section(int(s.hoc_internal_name().replace("__nrnsec_", ""), 0))')

    # not a sectionname
    expect_hocerr(h.push_section, ("not_a_sectionname",))
Example #3
0
def test_nonvint_block_supervisor():
    # making sure we can import
    from neuron import nonvint_block_supervisor
    # and can still use threads (no registered callbacks)
    pc = h.ParallelContext()
    pc.nthread(2)
    h.finitialize()
    # but if there is a callback it will fail with threads
    nonvint_block_supervisor.register([None for _ in range(11)])
    expect_hocerr(h.finitialize, (-65, ))
    # but can be cleared
    nonvint_block_supervisor.clear()
    h.finitialize()
    pc.nthread(1)
Example #4
0
def test_simple_sim():
    h("""create soma""")
    h.load_file("stdrun.hoc")
    h.soma.L = 5.6419
    h.soma.diam = 5.6419
    expect_hocerr(h.ion_register, ("na", 2))
    assert h.ion_charge("na_ion") == 1.0
    expect_hocerr(h.ion_register, ("ca", 3))
    assert h.ion_charge("ca_ion") == 2.0
    h.soma.insert("hh")
    ic = h.IClamp(h.soma(0.5))
    ic.delay = 0.5
    ic.dur = 0.1
    ic.amp = 0.3

    v = h.Vector()
    v.record(h.soma(0.5)._ref_v, sec=h.soma)
    tv = h.Vector()
    tv.record(h._ref_t, sec=h.soma)
    h.run()
    assert v[0] == -65.0
Example #5
0
def test_py_alltoall_dict_err():
    pc = h.ParallelContext()
    src = {i: (100 + i) for i in range(2)}
    expect_hocerr(pc.py_alltoall, src, ("hocobj_call error",))
Example #6
0
def test_deleted_sec():
    for sec in h.allsec():
        h.delete_section(sec=sec)
    s = h.Section()
    s.insert("hh")
    seg = s(0.5)
    ic = h.IClamp(seg)
    mech = seg.hh
    rvlist = [rv for rv in mech]
    vref = seg._ref_v
    gnabarref = mech._ref_gnabar
    sec_methods_ok = set([s.cell, s.name, s.hname, s.same, s.hoc_internal_name])
    sec_methods_chk = set(
        [
            getattr(s, n)
            for n in dir(s)
            if "__" not in n
            and type(getattr(s, n)) == type(s.x3d)
            and getattr(s, n) not in sec_methods_ok
        ]
    )
    seg_methods_chk = set(
        [
            getattr(seg, n)
            for n in dir(seg)
            if "__" not in n and type(getattr(seg, n)) == type(seg.area)
        ]
    )
    mech_methods_chk = set(
        [
            getattr(mech, n)
            for n in dir(mech)
            if "__" not in n and type(getattr(mech, n)) == type(mech.segment)
        ]
    )
    rv_methods_chk = set(
        [
            getattr(rvlist[0], n)
            for n in dir(rvlist[0])
            if "__" not in n and type(getattr(rvlist[0], n)) == type(rvlist[0].name)
        ]
    )
    rv_methods_chk.remove(rvlist[0].name)
    h.delete_section(sec=s)

    for methods in [sec_methods_chk, seg_methods_chk, mech_methods_chk, rv_methods_chk]:
        for m in methods:
            # Most would fail because of no args, but expect a check
            # for valid section first.
            words = str(m).split()
            print("m is " + words[4] + "." + words[2])
            expect_err("m()")

    assert str(s) == "<deleted section>"
    assert str(seg) == "<segment of deleted section>"
    assert str(mech) == "<mechanism of deleted section>"
    expect_err("h.sin(0.0, sec=s)")
    expect_err("print(s.L)")
    expect_err("s.L = 100.")
    expect_err("s.nseg")
    expect_err("s.nseg = 5")
    expect_err("print(s.v)")
    expect_err("print(s.orientation())")
    expect_err("s.insert('pas')")
    expect_err("s.insert(h.pas)")
    expect_err("s(.5)")
    expect_err("s(.5).v")
    expect_err("seg.v")
    expect_err("seg._ref_v")
    expect_err("s(.5).v = -65.")
    expect_err("seg.v = -65.")
    expect_err("seg.gnabar_hh")
    expect_err("mech.gnabar")
    expect_err("seg.gnabar_hh = .1")
    expect_err("mech.gnabar = .1")
    expect_err("rvlist[0][0]")
    expect_err("rvlist[0][0] = .1")
    expect_err("for sg in s: pass")
    expect_err("for m in seg: pass")
    expect_err("for r in mech: pass")

    assert s == s
    # See https://github.com/neuronsimulator/nrn/issues/1343
    if sys.version_info >= (3, 8):
        expect_err("dir(s)")
        expect_err("dir(seg)")
        expect_err("dir(mech)")
    assert type(dir(rvlist[0])) == list
    expect_err("help(s)")
    expect_err("help(seg)")
    expect_err("help(mech)")
    help(rvlist[0])  # not an error since it does not access s

    dend = h.Section()
    expect_err("dend.connect(s)")
    expect_err("dend.connect(seg)")

    # Note vref and gnabarref if used may cause segfault or other indeterminate result

    assert ic.get_segment() == None
    assert ic.has_loc() == 0.0
    expect_err("ic.get_loc()")
    expect_err("ic.amp")
    expect_err("ic.amp = .001")
    ic.loc(dend(0.5))
    assert ic.get_segment() == dend(0.5)

    imp = h.Impedance()
    expect_err("imp.loc(seg)")
    expect_err("h.distance(0, seg)")
    expect_hocerr(imp.loc, (seg,))
    expect_hocerr(h.distance, (0, seg))

    del ic, imp, dend
    locals()

    return s, seg, mech, rvlist, vref, gnabarref
Example #7
0
def test_py2nrnstring():
    print(uni)

    # I don't think h.getstr() can be made to work from python
    # so can't test unicode on stdin read by hoc.
    h("strdef s")
    h('s = "hello"')
    checking("h('getstr(s)')")
    h("getstr(s)")
    "goodbye"
    assert h.s == "hello"

    checking("h(uni + ' = 1')")
    assert h(uni + " = 1") == 0

    # Allowed! The s format for PyArg_ParseTuple specifies that
    # Unicode objects are converted to C strings using 'utf-8' encoding.
    # If this conversion fails, a UnicodeError is raised.
    checking("""h('s = "%s"'%uni)""")
    assert h('s = "%s"' % uni) == 1
    assert h.s == uni

    checking('h.printf("%s", uni)')
    expect_hocerr(h.printf, ("%s", uni))

    checking("hasattr(h, uni)")
    expect_hocerr(hasattr, (h, uni))

    expect_err("h.à = 1")

    expect_err("a = h.à")

    expect_err('a = h.ref("à")')

    ns = h.NetStim()
    # nonsense but it does test the unicode error message
    checking('h.setpointer(ns._ref_start, "à", ns)')
    expect_hocerr(h.setpointer, (ns._ref_start, "à", ns))
    del ns

    # No error for these two (unless cell is involved)!
    checking("s = h.Section(name=uni)")
    s = h.Section(name=uni)
    assert s.name() == uni
    checking("s = h.Section(uni)")
    s = h.Section(uni)
    assert s.name() == uni

    expect_err('h.Section(name="apical", cell=Foo(uni))')

    soma = h.Section()
    expect_err("a = soma.à")

    expect_err("soma.à = 1")

    expect_err("a = soma(.5).à")

    expect_err("soma(.5).à = 1")

    soma.insert("hh")
    expect_err("a = soma(.5).hh.à")

    expect_err("soma(.5).hh.à = 1")