Skip to content

Commit 2e50f46

Browse files
committed
TST: Add test for draw_gantt_chart
1 parent 2cf2d37 commit 2e50f46

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

nipype/pipeline/plugins/tests/test_callback.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,36 @@ def test_callback_exception(tmpdir, plugin, stop_on_first_crash):
6060

6161
sleep(0.5) # Wait for callback to be called (python 2.7)
6262
assert so.statuses == [("f_node", "start"), ("f_node", "exception")]
63+
64+
65+
@pytest.mark.parametrize("plugin", ["Linear", "MultiProc", "LegacyMultiProc"])
66+
def test_callback_gantt(tmpdir, plugin):
67+
import logging
68+
import logging.handlers
69+
70+
from os import path
71+
72+
from nipype.utils.profiler import log_nodes_cb
73+
from nipype.utils.draw_gantt_chart import generate_gantt_chart
74+
75+
log_filename = 'callback.log'
76+
logger = logging.getLogger('callback')
77+
logger.setLevel(logging.DEBUG)
78+
handler = logging.FileHandler(log_filename)
79+
logger.addHandler(handler)
80+
81+
#create workflow
82+
wf = pe.Workflow(name="test", base_dir=tmpdir.strpath)
83+
f_node = pe.Node(
84+
niu.Function(function=func, input_names=[], output_names=[]), name="f_node"
85+
)
86+
wf.add_nodes([f_node])
87+
wf.config["execution"] = {"crashdump_dir": wf.base_dir, "poll_sleep_duration": 2}
88+
89+
plugin_args = {"status_callback": log_nodes_cb}
90+
if plugin != "Linear":
91+
plugin_args['n_procs'] = 8
92+
wf.run(plugin=plugin, plugin_args=plugin_args)
93+
94+
generate_gantt_chart('callback.log', 1 if plugin == "Linear" else 8)
95+
assert path.exists('callback.log.html')

nipype/utils/draw_gantt_chart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,14 @@ def calculate_resource_timeseries(events, resource):
153153
all_res = 0.0
154154

155155
# Iterate through the events
156+
nan = {"Unknown", "N/A"}
156157
for _, event in sorted(events.items()):
157158
if event["event"] == "start":
158-
if resource in event and event[resource] != "Unknown":
159+
if resource in event and event[resource] not in nan:
159160
all_res += float(event[resource])
160161
current_time = event["start"]
161162
elif event["event"] == "finish":
162-
if resource in event and event[resource] != "Unknown":
163+
if resource in event and event[resource] not in nan:
163164
all_res -= float(event[resource])
164165
current_time = event["finish"]
165166
res[current_time] = all_res

0 commit comments

Comments
 (0)