Skip to content

Commit f96872b

Browse files
committed
Attempt tests for save_script_parameters
1 parent eb0a6c4 commit f96872b

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

tests/test_misc.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
11
"""Tests for `imcflibs.imagej.misc` utility functions."""
22

33
from imcflibs.imagej.misc import bytes_to_human_readable
4+
from imcflibs.imagej.misc import save_script_parameters
5+
6+
7+
class ModuleItem:
8+
"""Mock for the org.scijava.module.ModuleItem interface."""
9+
10+
def __init__(self, input_name):
11+
self.input_name = input_name
12+
13+
def getName(self):
14+
return self.input_name
15+
16+
17+
class ScriptInfo:
18+
"""Mock for the org.scijava.script.ScriptInfo class."""
19+
20+
def __init__(self, input_names):
21+
self.input_names = [ModuleItem(x) for x in input_names]
22+
23+
def inputs(self):
24+
return self.input_names
25+
26+
27+
class ScriptModule:
28+
"""Mock for the org.scijava.script.ScriptModule class."""
29+
30+
def __init__(self, input_names, inputs: dict):
31+
self.info = ScriptInfo(input_names)
32+
self.inputs = inputs
33+
34+
def getInfo(self):
35+
return self.info
36+
37+
def getInputs(self):
38+
return self.inputs
39+
40+
41+
def test_save_script_parameters(tmpdir, mocker):
42+
"""Tests for imcflibs.imagej.misc.save_script_parameters."""
43+
base = tmpdir.mkdir("base")
44+
m_is_password_style = mocker.patch("imcflibs.imagej.misc._is_password_style")
45+
m_is_password_style.return_value = False
46+
47+
script_module = ScriptModule(["AAA", "BBB"], {"AAA": "aaa", "BBB": "bbb"})
48+
script_globals = {"org.scijava.script.ScriptModule": script_module}
49+
save_script_parameters(script_globals, destination=base)
50+
with open(base / "script_parameters.txt", "r") as f:
51+
contents = f.read()
52+
assert contents == "AAA: aaa\nBBB: bbb\n"
453

554

655
def test_bytes_to_human_readable_simple():

0 commit comments

Comments
 (0)