Unverified Commit 3d91ea20 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony Committed by GitHub
Browse files

Merge pull request #30386 from mantidproject/bug_drill_backward_compatibility

Backward compatibility in DrILL file loading
parents 3bf66ad3 899dae9a
......@@ -20,7 +20,6 @@ from .DrillAlgorithmPool import DrillAlgorithmPool
from .DrillTask import DrillTask
from .DrillParameterController import DrillParameter, DrillParameterController
from .DrillRundexIO import DrillRundexIO
from .DrillSample import DrillSample
class DrillModel(QObject):
......@@ -760,16 +759,14 @@ class DrillModel(QObject):
return self.columns, tooltips
def addSample(self, index, params=None):
def addSample(self, index, sample):
"""
Add an empty sample.
Add a sample to the model.
Args:
index (int): sample index; if -1 the sample is added to the end
sample (DrillSample): sample
"""
sample = DrillSample()
if params:
sample.setParameters(params)
if (index == -1):
self.samples.append(sample)
else:
......
......@@ -10,6 +10,7 @@ import json
from mantid.kernel import *
from .configurations import RundexSettings
from .DrillSample import DrillSample
class DrillRundexIO:
......@@ -96,7 +97,13 @@ class DrillRundexIO:
# samples
if ((RundexSettings.SAMPLES_JSON_KEY in json_data)
and (json_data[RundexSettings.SAMPLES_JSON_KEY])):
for sample in json_data[RundexSettings.SAMPLES_JSON_KEY]:
for sampleJson in json_data[RundexSettings.SAMPLES_JSON_KEY]:
# for backward compatibility
if "CustomOptions" in sampleJson:
sampleJson.update(sampleJson["CustomOptions"])
del sampleJson["CustomOptions"]
sample = DrillSample()
sample.setParameters(sampleJson)
drill.addSample(-1, sample)
else:
logger.warning("No sample found when importing {0}."
......
......@@ -9,6 +9,7 @@ from qtpy.QtWidgets import QFileDialog, QMessageBox
from ..view.DrillSettingsDialog import DrillSettingsDialog
from ..model.DrillModel import DrillModel
from ..model.DrillSample import DrillSample
from .DrillContextMenuPresenter import DrillContextMenuPresenter
......@@ -44,7 +45,8 @@ class DrillPresenter:
self.view.acquisitionModeChanged.connect(self.acquisitionModeChanged)
self.view.cycleAndExperimentChanged.connect(
self.model.setCycleAndExperiment)
self.view.rowAdded.connect(self.model.addSample)
self.view.rowAdded.connect(
lambda position : self.model.addSample(position, DrillSample()))
self.view.rowDeleted.connect(self.model.deleteSample)
self.view.dataChanged.connect(self.onDataChanged)
self.view.groupSelectedRows.connect(self.onGroupSelectedRows)
......@@ -440,7 +442,7 @@ class DrillPresenter:
self.view.set_table(columns, tooltips)
if not samples:
self.view.add_row_after()
self.model.addSample(-1)
self.model.addSample(-1, DrillSample())
else:
for i in range(len(samples)):
self.view.add_row_after()
......
......@@ -9,6 +9,7 @@ set(TEST_PY_FILES
DrillTest.py
DrillParameterControllerTest.py
DrillSettingsDialogTest.py
DrillSampleTest.py
)
check_tests_valid(${CMAKE_CURRENT_SOURCE_DIR} ${TEST_PY_FILES})
......
......@@ -577,9 +577,9 @@ class DrillModelTest(unittest.TestCase):
def test_addSample(self):
self.assertEqual(self.model.samples, [])
self.model.addSample(0)
self.model.addSample(0, mock.Mock())
self.assertEqual(len(self.model.samples), 1)
self.model.addSample(0)
self.model.addSample(0, mock.Mock())
self.assertEqual(len(self.model.samples), 2)
def test_deleteSample(self):
......
......@@ -31,27 +31,119 @@ class DrillRundexIOTest(unittest.TestCase):
def test_getFilename(self):
self.assertEqual(self.model.getFilename(), self.filename)
def test_load(self):
@mock.patch("Interface.ui.drill.model.DrillRundexIO.DrillSample")
def test_loadRundexV1(self, mSample):
self.mJson.load.return_value = {
"Instrument": "i1",
"AcquisitionMode": "a1",
"CycleNumber": "cycle",
"ExperimentID": "exp",
"VisualSettings": {},
"GlobalSettings": {},
"Samples": [{"param1": "value1"}],
"SamplesGroups": {"A": 0},
"MasterSamples": {"A": 0}
"VisualSettings": {
"FoldedColumns": [
"c1",
"c2",
"c3"
],
"HiddenColumns": [
"c4",
"c5"
],
"ColumnsOrder": [
"c1",
"c2",
"c3",
"c4",
"c5"
]
},
"GlobalSettings": {
"param1": True,
"param2": "value1",
"param3": 0.1,
"param4": [0.1, 0.2, 0.3],
"param5": [],
},
"Samples": [
{
"param6": "value1",
"param7": "value2",
"CustomOptions": {
"param1": False
}
}
]
}
self.model.load()
self.mOpen.assert_called_once_with("test")
self.mJson.load.assert_called_once()
mD = self.mDrillModel
mD.setCycleAndExperiment.assert_called_once_with("cycle", "exp")
mD.setVisualSettings.assert_called_once()
sample = mSample.return_value
sample.setParameters.assert_called_once_with(
{
"param6": "value1",
"param7": "value2",
"param1": False
}
)
mD.addSample.assert_called_once_with(-1, sample)
@mock.patch("Interface.ui.drill.model.DrillRundexIO.DrillSample")
def test_loadRundexV2(self, mSample):
self.mJson.load.return_value = {
"Instrument": "i1",
"AcquisitionMode": "a1",
"CycleNumber": "cycle",
"ExperimentID": "exp",
"VisualSettings": {
"FoldedColumns": [
"c1",
"c2",
"c3"
],
"HiddenColumns": [
"c4",
"c5"
],
"ColumnsOrder": [
"c1",
"c2",
"c3",
"c4",
"c5"
]
},
"GlobalSettings": {
"param1": True,
"param2": "value1",
"param3": 0.1,
"param4": [0.1, 0.2, 0.3],
"param5": [],
},
"Samples": [
{
"param6": "value1",
"param7": "value2",
"param1": False
}
]
}
self.model.load()
self.mOpen.assert_called_once_with("test")
self.mJson.load.assert_called_once()
mD = self.mDrillModel
mD.setCycleAndExperiment.assert_called_once_with("cycle", "exp")
mD.setVisualSettings.assert_called_once_with({})
mD.addSample.assert_called_once_with(-1, {"param1": "value1"})
mD.setSamplesGroups.assert_called_once_with({"A": 0})
mD.setMasterSamples.assert_called_once_with({"A": 0})
mD.setVisualSettings.assert_called_once()
sample = mSample.return_value
sample.setParameters.assert_called_once_with(
{
"param6": "value1",
"param7": "value2",
"param1": False
}
)
mD.addSample.assert_called_once_with(-1, sample)
def test_save(self):
mD = self.mDrillModel
......
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source
# & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
from Interface.ui.drill.model.DrillSample import DrillSample
class DrillSampleTest(unittest.TestCase):
def setUp(self):
self.sample = DrillSample()
def test_init(self):
self.assertDictEqual(self.sample._parameters, {})
def test_setParameters(self):
params = {
"SampleRuns": "7909+7925,7893,7877",
"SampleTransmissionRuns": "7860",
"AbsorberRuns": "7847+8209,7837+8187,7827+8165",
"BeamRuns": "7846,7836,7826",
"ContainerRuns": "8367,8349,8331",
"TransmissionBeamRuns": "7815+7825+7872+7944-7953",
"OutputWorkspace": "GM110",
"MaskFiles": "maskBeamLowQ,maskBeamMiddleQ,maskBeamHighQ",
"ContainerTransmissionRuns": "8313",
"ReferenceFiles": "007845_Sample,007845_Sample,007835_Sample",
"SampleThickness": "0.2"
}
self.sample.setParameters(params)
self.assertDictEqual(self.sample._parameters, params)
def test_getParameters(self):
self.sample._parameters = {"p1": "v1", "p2": "v2"}
self.assertDictEqual(self.sample.getParameters(),
{"p1": "v1", "p2": "v2"})
def test_changeParameter(self):
self.sample._parameters = {"p1": "v1", "p2": "v2"}
self.sample.changeParameter("p1", "v1'")
self.assertDictEqual(self.sample._parameters,
{"p1": "v1'", "p2": "v2"})
self.sample.changeParameter("p2", "")
self.assertDictEqual(self.sample._parameters,
{"p1": "v1'"})
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment