1
+ #!/usr/bin/env python
1
2
# -*- coding: utf-8 -*-
2
- # test_profiler.py
3
- #
4
- # Author: Daniel Clark, 2016
5
-
3
+ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
4
+ # vi: set ft=python sts=4 ts=4 sw=4 et:
6
5
"""
7
6
Module to unit test the resource_monitor in nipype
8
7
"""
17
16
from nipype .interfaces import utility as niu
18
17
19
18
20
- # UseResources inputspec
21
19
class UseResourcesInputSpec (CommandLineInputSpec ):
22
20
mem_gb = traits .Float (desc = 'Number of GB of RAM to use' ,
23
21
argstr = '-g %f' , mandatory = True )
24
22
n_procs = traits .Int (desc = 'Number of threads to use' ,
25
23
argstr = '-p %d' , mandatory = True )
26
24
27
25
28
- # UseResources interface
29
26
class UseResources (CommandLine ):
30
- '''
27
+ """
31
28
use_resources cmd interface
32
- '''
29
+ """
33
30
from nipype import __path__
34
31
# Init attributes
35
32
input_spec = UseResourcesInputSpec
@@ -48,10 +45,10 @@ class UseResources(CommandLine):
48
45
@pytest .mark .skipif (run_profile is False , reason = 'resources monitor is disabled' )
49
46
@pytest .mark .parametrize ("mem_gb,n_procs" , [(0.5 , 3 ), (2.2 , 8 ), (0.8 , 4 ), (1.5 , 1 )])
50
47
def test_cmdline_profiling (tmpdir , mem_gb , n_procs ):
51
- '''
48
+ """
52
49
Test runtime profiler correctly records workflow RAM/CPUs consumption
53
50
of a CommandLine-derived interface
54
- '''
51
+ """
55
52
from nipype import config
56
53
config .set ('execution' , 'resource_monitor_frequency' , '0.2' ) # Force sampling fast
57
54
@@ -67,10 +64,10 @@ def test_cmdline_profiling(tmpdir, mem_gb, n_procs):
67
64
@pytest .mark .skipif (run_profile is False , reason = 'resources monitor is disabled' )
68
65
@pytest .mark .parametrize ("mem_gb,n_procs" , [(0.5 , 3 ), (2.2 , 8 ), (0.8 , 4 ), (1.5 , 1 )])
69
66
def test_function_profiling (tmpdir , mem_gb , n_procs ):
70
- '''
67
+ """
71
68
Test runtime profiler correctly records workflow RAM/CPUs consumption
72
69
of a Function interface
73
- '''
70
+ """
74
71
from nipype import config
75
72
config .set ('execution' , 'resource_monitor_frequency' , '0.2' ) # Force sampling fast
76
73
@@ -80,5 +77,5 @@ def test_function_profiling(tmpdir, mem_gb, n_procs):
80
77
iface .inputs .n_procs = n_procs
81
78
result = iface .run ()
82
79
83
- # assert abs(mem_gb - result.runtime.mem_peak_gb) < 0.3, 'estimated memory error above .3GB'
80
+ assert abs (mem_gb - result .runtime .mem_peak_gb ) < 0.3 , 'estimated memory error above .3GB'
84
81
assert int (result .runtime .cpu_percent / 100 + 0.2 ) >= n_procs
0 commit comments