Skip to content
Snippets Groups Projects
Commit a8d9504d authored by Ewan Cook's avatar Ewan Cook
Browse files

refs #23023 add more units tests

parent 1b783798
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,5 @@ class CoLoadModel(lutils.LModel): ...@@ -45,6 +45,5 @@ class CoLoadModel(lutils.LModel):
def co_load_run(self, workspace): def co_load_run(self, workspace):
to_add = [self.add_runs(l, r) for l, r in zip(*lutils.flatten_run_data( to_add = [self.add_runs(l, r) for l, r in zip(*lutils.flatten_run_data(
self.workspace, workspace))] self.workspace, workspace))]
print(lutils.hyphenise(self.co_runs), self.co_runs)
self.workspace = lutils.group_by_detector( self.workspace = lutils.group_by_detector(
lutils.hyphenise(self.co_runs), to_add) lutils.hyphenise(self.co_runs), to_add)
...@@ -114,16 +114,15 @@ def flatten_run_data(*workspaces): ...@@ -114,16 +114,15 @@ def flatten_run_data(*workspaces):
def hyphenise(vals): def hyphenise(vals):
if not len(vals):
return ""
vals = [str(s) for s in sorted(list(set(vals)))]
diffs = [int(vals[i + 1]) - int(vals[i]) for i in range(len(vals) - 1)]
a = b = vals[0]
out = [] out = []
for i, d in enumerate(diffs): if vals:
if d != 1: vals = [str(s) for s in sorted(list(set(vals)))]
out.append("-".join([a, b]) if a != b else a) diffs = [int(vals[i + 1]) - int(vals[i]) for i in range(len(vals) - 1)]
a = vals[i + 1] a = b = vals[0]
b = vals[i + 1] for i, d in enumerate(diffs):
out.append("-".join([a, b]) if a != b else vals[-1]) if d != 1:
out.append("-".join([a, b]) if a != b else a)
a = vals[i + 1]
b = vals[i + 1]
out.append("-".join([a, b]) if a != b else vals[-1])
return ", ".join(out) return ", ".join(out)
...@@ -2,14 +2,21 @@ import unittest ...@@ -2,14 +2,21 @@ import unittest
from Muon.GUI.ElementalAnalysis.LoadWidget import load_utils as lutils from Muon.GUI.ElementalAnalysis.LoadWidget import load_utils as lutils
import mantid.simpleapi as mantid
from six import iteritems from six import iteritems
class LoadUtilsTest(unittest.TestCase): class LoadUtilsTest(unittest.TestCase):
def setUp(self): def setUp(self):
self.test_path = "test\path\to\ral012345.rooth2020.dat" self.test_path = r"test\path\to\ral012345.rooth2020.dat"
self.bad_path = r"test\path\to\ral012345.rooth2042"
self.test_ws_name = "1_Delayed_rooth2020" self.test_ws_name = "1_Delayed_rooth2020"
self.bad_path = "test\path\to\ral012345.rooth2042" self.var_ws_name = "{}_Total_rooth2020"
self.test_ws_names = [self.var_ws_name.format(x) for x in range(1, 9)]
self.test_workspaces = [mantid.CreateSampleWorkspace(
OutputWorkspace=s) for s in self.test_ws_names]
self.test_run = 5
def test_pad_run(self): def test_pad_run(self):
tests = {123: "00123", 0: "00000", 12345: "12345", 123456: "123456"} tests = {123: "00123", 0: "00000", 12345: "12345", 123456: "123456"}
...@@ -20,14 +27,10 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -20,14 +27,10 @@ class LoadUtilsTest(unittest.TestCase):
assert lutils.get_detector_num_from_ws(self.test_ws_name) == 1 assert lutils.get_detector_num_from_ws(self.test_ws_name) == 1
def test_get_detectors_num(self): def test_get_detectors_num(self):
nums = [lutils.get_detectors_num(x) assert lutils.get_detectors_num(self.test_path) == 1
for x in [self.test_path, self.bad_path]]
assert nums == [1, 1]
def test_get_end_num(self): def test_get_end_num(self):
endings = [ assert lutils.get_end_num(self.test_path) == "rooth2020"
lutils.get_end_num(x) for x in [self.test_path, self.bad_path]]
assert endings == ["rooth2020", "rooth2042"]
def test_get_run_type(self): def test_get_run_type(self):
assert lutils.get_run_type(self.test_path) == "Delayed" assert lutils.get_run_type(self.test_path) == "Delayed"
...@@ -43,6 +46,24 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -43,6 +46,24 @@ class LoadUtilsTest(unittest.TestCase):
for out, arg in iteritems(tests): for out, arg in iteritems(tests):
assert lutils.hyphenise(arg) == out assert lutils.hyphenise(arg) == out
def test_group_by_detector(self):
output, workspaces = [], []
for x in range(1, 5):
ws = self.var_ws_name.format(x)
workspaces.append(ws)
mantid.CreateSampleWorkspace(OutputWorkspace=ws).getName()
output.append("{}; Detector {}".format(self.test_run, x))
assert lutils.group_by_detector(self.test_run, workspaces) == output
def test_flatten_run_data(self):
workspaces = []
for x in range(0, len(self.test_workspaces), 2):
name = str(x)
mantid.GroupWorkspaces(
self.test_workspaces[x:x + 2], OutputWorkspace=name)
workspaces.append(name)
assert lutils.flatten_run_data(workspaces) == [self.test_ws_names]
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment