Skip to content

Commit 38bb2ea

Browse files
committed
enh: add tests
1 parent 70681f7 commit 38bb2ea

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

templateflow/conf/tests/test_conf.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,29 @@ def test_layout(monkeypatch, tmp_path):
9090
assert lines[0] == "TemplateFlow Layout"
9191
assert lines[1] == " - Home: %s" % tfc.TF_HOME
9292
assert lines[2].startswith(" - Templates:")
93+
94+
95+
def test_layout_errors(monkeypatch):
96+
"""Check regression of #71."""
97+
import sys
98+
import builtins
99+
from importlib import __import__ as oldimport
100+
101+
@tfc.requires_layout
102+
def myfunc():
103+
return "okay"
104+
105+
def mock_import(name, globals=None, locals=None, fromlist=tuple(), level=0):
106+
if name == "bids":
107+
raise ModuleNotFoundError
108+
return oldimport(name, globals=globals, locals=locals, fromlist=fromlist, level=level)
109+
110+
with monkeypatch.context() as m:
111+
m.setattr(tfc, "TF_LAYOUT", None)
112+
with pytest.raises(RuntimeError):
113+
myfunc()
114+
115+
m.delitem(sys.modules, "bids")
116+
m.setattr(builtins, "__import__", mock_import)
117+
with pytest.raises(ImportError):
118+
myfunc()

0 commit comments

Comments
 (0)