File: test_version_macros.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 (43 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download | duplicates (2)
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
from neuron.tests.utils.strtobool import strtobool
import os
from neuron import coreneuron, h


def test_version_macros():
    """
    Use the special version_macros.mod mechanism to test the
    NRN_VERSION_X(maj, min, pat) preprocessor macros in VERBATIM blocks.
    """
    # Get the CMake PACKAGE_VERSION variable, which should always be in
    # major.minor.patch format. This should be baked into C++ as part of the main
    # NEURON build, not as part of nrnivmodl.
    ver = tuple(int(x) for x in h.nrnversion(0).split(".", 2))

    pc = h.ParallelContext()
    s = h.Section()
    s.insert("VersionMacros")
    coreneuron.enable = bool(
        strtobool(os.environ.get("NRN_CORENEURON_ENABLE", "false"))
    )
    coreneuron.verbose = True
    h.CVode().cache_efficient(True)
    h.finitialize()
    pc.set_maxstep(10)
    pc.psolve(0.1)

    def t(name):
        vals = [getattr(seg.VersionMacros, name + "_result") for seg in s]
        assert len(vals) == 1
        return bool(vals[0])

    assert t("eq8_2_0") == (ver == (8, 2, 0))
    assert t("ne9_0_1") == (ver != (9, 0, 1))
    assert t("gt9_0_0") == (ver > (9, 0, 0))
    assert t("lt42_1_2") == (ver < (42, 1, 2))
    assert t("gteq10_4_7") == (ver >= (10, 4, 7))
    assert t("lteq8_1_0") == (ver <= (8, 1, 0))
    assert t("explicit_gteq8_2_0") == (ver >= (8, 2, 0))


if __name__ == "__main__":
    test_version_macros()