|
1 | 1 | """Tests for `imcflibs.imagej.misc` utility functions.""" |
2 | 2 |
|
3 | 3 | 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" |
4 | 53 |
|
5 | 54 |
|
6 | 55 | def test_bytes_to_human_readable_simple(): |
|
0 commit comments