@@ -19,3 +19,90 @@ def test_nipype_info():
1919def test_git_hash ():
2020 # removing the first "g" from gitversion
2121 get_nipype_gitversion ()[1 :] == get_info ()["commit_hash" ]
22+
23+
24+ def _check_no_et ():
25+ import os
26+ from unittest .mock import patch
27+
28+ et = os .getenv ("NIPYPE_NO_ET" ) is None
29+
30+ with patch .dict ("os.environ" , {"NIPYPE_NO_ET" : "1" }):
31+ from nipype .interfaces .base import BaseInterface
32+
33+ ver_data = BaseInterface ._etelemetry_version_data
34+
35+ if et and ver_data is None :
36+ raise ValueError (
37+ "etelemetry enabled and version data missing - double hits likely"
38+ )
39+
40+ return et
41+
42+
43+ def test_no_et (tmp_path ):
44+ from unittest .mock import patch
45+ from nipype .pipeline import engine as pe
46+ from nipype .interfaces import utility as niu
47+ from nipype .interfaces .base import BaseInterface
48+
49+ # Pytest doesn't trigger this, so let's pretend it's there
50+ with patch .object (BaseInterface , "_etelemetry_version_data" , {}):
51+
52+ # Direct function call - environment not set
53+ f = niu .Function (function = _check_no_et )
54+ res = f .run ()
55+ assert res .outputs .out is True
56+
57+ # Basic node - environment not set
58+ n = pe .Node (
59+ niu .Function (function = _check_no_et ), name = "n" , base_dir = str (tmp_path )
60+ )
61+ res = n .run ()
62+ assert res .outputs .out is True
63+
64+ # Linear run - environment not set
65+ wf1 = pe .Workflow (name = "wf1" , base_dir = str (tmp_path ))
66+ wf1 .add_nodes ([pe .Node (niu .Function (function = _check_no_et ), name = "n" )])
67+ res = wf1 .run ()
68+ assert next (iter (res .nodes )).result .outputs .out is True
69+
70+ # MultiProc run - environment initialized with NIPYPE_NO_ET
71+ wf2 = pe .Workflow (name = "wf2" , base_dir = str (tmp_path ))
72+ wf2 .add_nodes ([pe .Node (niu .Function (function = _check_no_et ), name = "n" )])
73+ res = wf2 .run (plugin = "MultiProc" , plugin_args = {"n_procs" : 1 })
74+ assert next (iter (res .nodes )).result .outputs .out is False
75+
76+ # LegacyMultiProc run - environment initialized with NIPYPE_NO_ET
77+ wf3 = pe .Workflow (name = "wf3" , base_dir = str (tmp_path ))
78+ wf3 .add_nodes ([pe .Node (niu .Function (function = _check_no_et ), name = "n" )])
79+ res = wf3 .run (plugin = "LegacyMultiProc" , plugin_args = {"n_procs" : 1 })
80+ assert next (iter (res .nodes )).result .outputs .out is False
81+
82+ # run_without_submitting - environment not set
83+ wf4 = pe .Workflow (name = "wf4" , base_dir = str (tmp_path ))
84+ wf4 .add_nodes (
85+ [
86+ pe .Node (
87+ niu .Function (function = _check_no_et ),
88+ run_without_submitting = True ,
89+ name = "n" ,
90+ )
91+ ]
92+ )
93+ res = wf4 .run (plugin = "MultiProc" , plugin_args = {"n_procs" : 1 })
94+ assert next (iter (res .nodes )).result .outputs .out is True
95+
96+ # LegacyMultiProc run - environment initialized with NIPYPE_NO_ET
97+ wf5 = pe .Workflow (name = "wf5" , base_dir = str (tmp_path ))
98+ wf5 .add_nodes (
99+ [
100+ pe .Node (
101+ niu .Function (function = _check_no_et ),
102+ run_without_submitting = True ,
103+ name = "n" ,
104+ )
105+ ]
106+ )
107+ res = wf5 .run (plugin = "LegacyMultiProc" , plugin_args = {"n_procs" : 1 })
108+ assert next (iter (res .nodes )).result .outputs .out is True
0 commit comments