-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HOC push_section(python_section_name) does not work. (#1070)
* from neuron.expect_hocerr import expect_hocerr available for all tests.
- Loading branch information
1 parent
160c8ea
commit e8fa58c
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
from io import StringIO | ||
from neuron import h | ||
pc = h.ParallelContext() | ||
nhost = pc.nhost() | ||
|
||
def expect_hocerr(callable, args, sec=None): | ||
""" | ||
Execute callable(args) and assert that it generated an error. | ||
If sec is not None, executes callable(args, sec=sec) | ||
Skips if nhost > 1 as all hoc_execerror end in MPI_ABORT | ||
Does not work well with nrniv launch since hoc_execerror messages do not | ||
pass through sys.stderr. | ||
""" | ||
|
||
if nhost > 1: | ||
return | ||
|
||
old_stderr = sys.stderr | ||
sys.stderr = my_stderr = StringIO() | ||
err = 0 | ||
try: | ||
if sec: | ||
callable(*args, sec=sec) | ||
else: | ||
callable(*args) | ||
except: | ||
err=1 | ||
errmes = my_stderr.getvalue() | ||
sys.stderr = old_stderr | ||
if errmes: | ||
errmes = errmes.splitlines()[0] | ||
errmes = errmes[(errmes.find(':')+2):] | ||
print("expect_hocerr: %s" % errmes) | ||
if err == 0: | ||
print("expect_hocerr: no err for %s%s" % (str(callable), str(args))) | ||
assert(err) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters