File: test_nrniv-launch.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 (34 lines) | stat: -rw-r--r-- 652 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
from sys import platform

if platform == "win32":  # skip the test.
    # Cannot get subprocess.run to feed stdin to nrniv
    quit()

import subprocess


def srun(cmd, inp):
    print(cmd, inp)
    cp = subprocess.run(
        cmd, shell=True, input=inp, capture_output=True, text=True, timeout=5
    )
    return cp.returncode, cp.stderr, cp.stdout


r = srun(
    'nrniv -isatty -c "a=5" -',
    r"""
func square() {
  return $1*$1
}
print "a = ", a
print "square(a)=", square(a)
quit()
""",
)

assert r[0] == 0
print(r[2])
assert "square(a)=25" in r[2]
if platform != "darwin":  # Mac does not print the "oc>" prompt
    assert "oc>quit()" in r[2]