Skip to content

Commit 9d793c1

Browse files
authored
Merge pull request #1516 from shoshber/uniquecrashfile
FIX/WIP unique crash files
2 parents 0d0d73a + 5f8e109 commit 9d793c1

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

nipype/pipeline/plugins/base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import shutil
1414
from socket import gethostname
1515
import sys
16+
import uuid
1617
from time import strftime, sleep, time
1718
from traceback import format_exception, format_exc
1819
from warnings import warn
@@ -57,9 +58,10 @@ def report_crash(node, traceback=None, hostname=None):
5758
exc_traceback)
5859
timeofcrash = strftime('%Y%m%d-%H%M%S')
5960
login_name = getpass.getuser()
60-
crashfile = 'crash-%s-%s-%s.pklz' % (timeofcrash,
61-
login_name,
62-
name)
61+
crashfile = 'crash-%s-%s-%s-%s.pklz' % (timeofcrash,
62+
login_name,
63+
name,
64+
str(uuid.uuid4()))
6365
crashdir = node.config['execution']['crashdump_dir']
6466
if crashdir is None:
6567
crashdir = os.getcwd()

nipype/pipeline/plugins/tests/test_base.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,39 @@
44
"""
55
import numpy as np
66
import scipy.sparse as ssp
7+
import re
8+
9+
import mock
710

811
from nipype.testing import (assert_raises, assert_equal, assert_true,
9-
assert_false, skipif)
12+
assert_false, skipif, assert_regexp_matches)
1013
import nipype.pipeline.plugins.base as pb
1114

12-
1315
def test_scipy_sparse():
1416
foo = ssp.lil_matrix(np.eye(3, k=1))
1517
goo = foo.getrowview(0)
1618
goo[goo.nonzero()] = 0
1719
yield assert_equal, foo[0, 1], 0
1820

21+
def test_report_crash():
22+
with mock.patch('pickle.dump', mock.MagicMock()) as mock_pickle_dump:
23+
with mock.patch('nipype.pipeline.plugins.base.format_exception', mock.MagicMock()): # see iss 1517
24+
mock_pickle_dump.return_value = True
25+
mock_node = mock.MagicMock(name='mock_node')
26+
mock_node._id = 'an_id'
27+
mock_node.config = {
28+
'execution' : {
29+
'crashdump_dir' : '.'
30+
}
31+
}
32+
33+
actual_crashfile = pb.report_crash(mock_node)
34+
35+
expected_crashfile = re.compile('.*/crash-.*-an_id-[0-9a-f\-]*.pklz')
36+
37+
yield assert_regexp_matches, actual_crashfile, expected_crashfile
38+
yield assert_true, mock_pickle_dump.call_count == 1
39+
1940
'''
2041
Can use the following code to test that a mapnode crash continues successfully
2142
Need to put this into a nose-test with a timeout

0 commit comments

Comments
 (0)