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

refs #23023 fix suffix not being overwritten

parent 336cd677
No related branches found
No related tags found
No related merge requests found
...@@ -39,8 +39,7 @@ class CoLoadModel(lutils.LModel): ...@@ -39,8 +39,7 @@ class CoLoadModel(lutils.LModel):
def add_runs(self, l, r, suffix): def add_runs(self, l, r, suffix):
# prevent new suffix being appended to old one # prevent new suffix being appended to old one
l = l[:l.rfind("_")] if l.endswith(")") else l out = lutils.replace_workspace_name_suffix(l, suffix)
out = "{}_({})".format(l, suffix)
mantid.Plus(l, r, OutputWorkspace=out) mantid.Plus(l, r, OutputWorkspace=out)
return out return out
......
...@@ -121,6 +121,11 @@ def get_filename(path, run): ...@@ -121,6 +121,11 @@ def get_filename(path, run):
return None return None
def replace_workspace_name_suffix(name, suffix):
detector, run_type, end = name.split("_", 3)[:3]
return "_".join([detector, run_type, end, suffix])
def flatten_run_data(*workspaces): def flatten_run_data(*workspaces):
out = [] out = []
for ws in workspaces: for ws in workspaces:
......
...@@ -13,7 +13,7 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -13,7 +13,7 @@ class LoadUtilsTest(unittest.TestCase):
self.bad_path = r"test\path\to\ral012345.rooth2042" self.bad_path = r"test\path\to\ral012345.rooth2042"
self.test_run = 5 self.test_run = 5
self.test_ws_name = "1_Delayed_rooth2020_{}".format(self.test_run) self.test_ws_name = "1_Delayed_rooth2020_{}".format(self.test_run)
self.var_ws_name = "{}_Total_rooth2020_{}" self.var_ws_name = "{}_Delayed_rooth2020_{}"
self.test_ws_names = [ self.test_ws_names = [
self.var_ws_name.format( self.var_ws_name.format(
x, self.test_run) for x in range( x, self.test_run) for x in range(
...@@ -69,6 +69,13 @@ class LoadUtilsTest(unittest.TestCase): ...@@ -69,6 +69,13 @@ class LoadUtilsTest(unittest.TestCase):
workspaces.append(name) workspaces.append(name)
assert lutils.flatten_run_data(workspaces) == [self.test_ws_names] assert lutils.flatten_run_data(workspaces) == [self.test_ws_names]
def test_replace_workspace_name_suffix(self):
tests = {self.test_ws_name: "suffix", "_".join(
[self.test_ws_name, "test"]): "suffix"}
for w, suffix in iteritems(tests):
assert lutils.replace_workspace_name_suffix(
w, suffix) == self.var_ws_name.format(1, suffix)
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