diff --git a/docs/source/images/sans_isis_v2_run_tab_data_table.png b/docs/source/images/sans_isis_v2_run_tab_data_table.png index 4f14f968bb32004771b1321fbe4e0854cceb6167..7ca3d833eab727b1562e18627318cc38143bee34 100644 Binary files a/docs/source/images/sans_isis_v2_run_tab_data_table.png and b/docs/source/images/sans_isis_v2_run_tab_data_table.png differ diff --git a/docs/source/images/sans_isis_v2_whole_gui.png b/docs/source/images/sans_isis_v2_whole_gui.png index 8af01b20c600eb7f8cfb71d43fe73242d9c909a9..0809703e4c6698a0411f6116383f0ae391f35e0d 100644 Binary files a/docs/source/images/sans_isis_v2_whole_gui.png and b/docs/source/images/sans_isis_v2_whole_gui.png differ diff --git a/docs/source/interfaces/ISIS SANS v2.rst b/docs/source/interfaces/ISIS SANS v2.rst index cfa5436abdc8190ad658522af871b4c42a0c03e3..e685d484894a5fbc4ef6268dfca2997956581577 100644 --- a/docs/source/interfaces/ISIS SANS v2.rst +++ b/docs/source/interfaces/ISIS SANS v2.rst @@ -60,10 +60,43 @@ Data Table +-------+--------------------------+-----------------------------------------------------------------------------------------+ | **9** | **Select instrument** | Selects the instrument to use. Note that this setting is used to resolve run numbers. | +-------+--------------------------+-----------------------------------------------------------------------------------------+ -| **10**| **Options** | This column allows the user to provide row specific settings. Currently only | -| | | **WavelengthMin** and **WavelengthMax** can be set here. | +| **10**| **Unused Functionality** | These icons are not used | +-------+--------------------------+-----------------------------------------------------------------------------------------+ +Columns +^^^^^^^ + ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **SampleScatter** | Scatter data file to use. This is the only mandatory field | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **ssp** | Sample scatter period, if not specified all periods will be used (where applicable) | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **SampleTrans** | Transmission data file to use. | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **stp** | Sample scatter period, if not specified all periods will be used (where applicable) | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **SampleDirect** | Direct data file to use | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **sdp** | Sample direct period, if not specified all periods will be used (where applicable) | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **CanScatter** | Scatter datafile for can run | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **csp** | Can scatter period, if not specified all periods will be used (where applicable) | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **CanTrans** | Transmission datafile for can run | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **ctp** | Can transmission period, if not specified all periods will be used (where applicable) | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **CanDirect** | Direct datafile for can run | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **OutputName** | Name of output workspace | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **User File** | User file to use for this row. If specified it will override any options set in the GUI, | +| | otherwise the default file will be used. | ++--------------------------+-------------------------------------------------------------------------------------------------+ +| **Options** | This column allows the user to provide row specific settings. Currently only **WavelengthMin**| +| | and WavelengthMax can be set here. | ++--------------------------+-------------------------------------------------------------------------------------------------+ Save Options ^^^^^^^^^^^^ diff --git a/scripts/SANS/sans/gui_logic/gui_common.py b/scripts/SANS/sans/gui_logic/gui_common.py index b9ab0fe69cae6efbe66c606472aba7ad6c11fafa..1b97b59e83df5fc3d2b254b76cf8c9349cac9224 100644 --- a/scripts/SANS/sans/gui_logic/gui_common.py +++ b/scripts/SANS/sans/gui_logic/gui_common.py @@ -18,8 +18,9 @@ CAN_TRANSMISSION_PERIOD_INDEX = 9 CAN_DIRECT_INDEX = 10 CAN_DIRECT_PERIOD_INDEX = 11 OUTPUT_NAME_INDEX = 12 -OPTIONS_INDEX = 13 -HIDDEN_OPTIONS_INDEX = 14 +USER_FILE_INDEX = 13 +OPTIONS_INDEX = 14 +HIDDEN_OPTIONS_INDEX = 15 OPTIONS_SEPARATOR = "," OPTIONS_EQUAL = "=" diff --git a/scripts/SANS/sans/gui_logic/models/table_model.py b/scripts/SANS/sans/gui_logic/models/table_model.py index 2c4df2ffcba73c2f9df454e3aad103a4c96e787b..ce7563ccd4b8d521378b5b0650ef8f0163086c82 100644 --- a/scripts/SANS/sans/gui_logic/models/table_model.py +++ b/scripts/SANS/sans/gui_logic/models/table_model.py @@ -35,6 +35,12 @@ class TableModel(object): self._validate_file_name(value) self._user_file = value + def get_row_user_file(self, row_index): + if row_index in self._table_entries: + return self._table_entries[row_index].user_file + else: + raise IndexError("The row {} does not exist.".format(row_index)) + @property def batch_file(self): return self._batch_file @@ -63,7 +69,7 @@ class TableIndexModel(object): can_scatter, can_scatter_period, can_transmission, can_transmission_period, can_direct, can_direct_period, - output_name="", options_column_string=""): + output_name="", user_file="", options_column_string=""): super(TableIndexModel, self).__init__() self.index = index self.sample_scatter = sample_scatter @@ -80,7 +86,7 @@ class TableIndexModel(object): self.can_direct = can_direct self.can_direct_period = can_direct_period - self.user_file = "" + self.user_file = user_file self.output_name = output_name # Options column entries diff --git a/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py b/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py index b8d398b4f34bfb2d65fc0a8c9761bd9cbd8200aa..082107b36b75f3212a39bf18324cd5c52b7bcbaa 100644 --- a/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py +++ b/scripts/SANS/sans/gui_logic/presenter/run_tab_presenter.py @@ -30,7 +30,7 @@ from sans.gui_logic.gui_common import (get_reduction_mode_strings_for_gui, CAN_TRANSMISSION_INDEX, CAN_TRANSMISSION_PERIOD_INDEX, CAN_DIRECT_INDEX, CAN_DIRECT_PERIOD_INDEX, OUTPUT_NAME_INDEX, OPTIONS_SEPARATOR, OPTIONS_INDEX, - OPTIONS_EQUAL, HIDDEN_OPTIONS_INDEX) + OPTIONS_EQUAL, HIDDEN_OPTIONS_INDEX, USER_FILE_INDEX) from sans.common.enums import (BatchReductionEntry, OutputMode, SANSInstrument, RangeStepType, SampleShape, FitType) from sans.common.file_information import (SANSFileInformationFactory) from sans.user_file.user_file_reader import UserFileReader @@ -159,7 +159,6 @@ class RunTabPresenter(object): if not user_file_path: return - # 2. Get the full file path user_file_path = FileFinder.getFullPath(user_file_path) if not os.path.exists(user_file_path): @@ -205,7 +204,6 @@ class RunTabPresenter(object): # 2. Read the batch file batch_file_parser = BatchCsvParser(batch_file_path) parsed_rows = batch_file_parser.parse_batch_file() - # 3. Clear the table self._view.clear_table() @@ -795,6 +793,7 @@ class RunTabPresenter(object): can_direct = self._view.get_cell(row=row, column=CAN_DIRECT_INDEX, convert_to=str) can_direct_period = self._view.get_cell(row=row, column=CAN_DIRECT_PERIOD_INDEX, convert_to=str) output_name = self._view.get_cell(row=row, column=OUTPUT_NAME_INDEX, convert_to=str) + user_file = self._view.get_cell(row=row, column=USER_FILE_INDEX, convert_to=str) # Get the options string # We don't have to add the hidden column here, since it only contains information for the SANS @@ -815,6 +814,7 @@ class RunTabPresenter(object): can_direct=can_direct, can_direct_period=can_direct_period, output_name=output_name, + user_file = user_file, options_column_string=options_string) table_model.add_table_entry(row, table_index_model) return table_model @@ -839,18 +839,33 @@ class RunTabPresenter(object): for row in rows: self.sans_logger.information("Generating state for row {}".format(row)) if not self.is_empty_row(row): - try: - state = gui_state_director.create_state(row) - states.update({row: state}) - except ValueError as e: - self.sans_logger.error("There was a bad entry for row {}. Ensure that the path to your files has " - "been added to the Mantid search directories! See here for more " - "details: {}".format(row, str(e))) - raise RuntimeError("There was a bad entry for row {}. Ensure that the path to your files has " - "been added to the Mantid search directories! See here for more " - "details: {}".format(row, str(e))) + row_user_file = table_model.get_row_user_file(row) + if row_user_file: + user_file_path = FileFinder.getFullPath(row_user_file) + if not os.path.exists(user_file_path): + raise RuntimeError("The user path {} does not exist. Make sure a valid user file path" + " has been specified.".format(user_file_path)) + + user_file_reader = UserFileReader(user_file_path) + user_file_items = user_file_reader.read_user_file() + + row_state_model = StateGuiModel(user_file_items) + row_gui_state_director = GuiStateDirector(table_model, row_state_model, self._facility) + self._create_row_state(row_gui_state_director, states, row) + else: + self._create_row_state(gui_state_director, states, row) return states + def _create_row_state(self, director, states, row): + try: + state = director.create_state(row) + states.update({row: state}) + except ValueError as e: + error_msg = "There was a bad entry for row {}. Ensure that the path to your files has been added to the " \ + "Mantid search directories! See here for more details: {}" + self.sans_logger.error(error_msg.format(row, str(e))) + raise RuntimeError(error_msg.format(row, str(e))) + def _populate_row_in_table(self, row): """ Adds a row to the table diff --git a/scripts/SANS/sans/gui_logic/sans_data_processor_gui_algorithm.py b/scripts/SANS/sans/gui_logic/sans_data_processor_gui_algorithm.py index 18df3a5a8eeb347816a1ac630825d6565466c0b2..41620dadfbc3af2da4778615b1986e17c58cc3c7 100644 --- a/scripts/SANS/sans/gui_logic/sans_data_processor_gui_algorithm.py +++ b/scripts/SANS/sans/gui_logic/sans_data_processor_gui_algorithm.py @@ -153,6 +153,14 @@ def create_properties(): default='', prefix='', property_type=str), + algorithm_list_entry(column_name="User File", + algorithm_property="UserFile", + description=('The user file to use, this will override GUI changes for this row.' + ' If left unspecified default will be used'), + show_value=False, + default="", + prefix='', + property_type=str), algorithm_list_entry(column_name="", algorithm_property="RowIndex", description='The row index (which is automatically populated by the GUI)', diff --git a/scripts/SANS/sans/test_helper/mock_objects.py b/scripts/SANS/sans/test_helper/mock_objects.py index c0f441bfd3eb13ff02919ffdd63424b191f6b6e0..5ba6329f0bae99384dafb35de3beab73646992b1 100644 --- a/scripts/SANS/sans/test_helper/mock_objects.py +++ b/scripts/SANS/sans/test_helper/mock_objects.py @@ -6,6 +6,7 @@ from ui.sans_isis.masking_table import MaskingTable from sans.gui_logic.presenter.run_tab_presenter import RunTabPresenter from sans.common.enums import (RangeStepType, OutputMode) from sans.test_helper.test_director import TestDirector +from functools import (partial) import sys if sys.version_info.major == 3: @@ -26,7 +27,7 @@ def create_mock_masking_table(): return view -def get_cell_mock(row, column, convert_to=None): +def get_cell_mock(row, column, convert_to=None, user_file_path = ""): _ = convert_to # noqa if row == 0: # For the first row we return the @@ -39,6 +40,13 @@ def get_cell_mock(row, column, convert_to=None): return "SANS2D00022048" else: return "" + elif row == 1: + if column == 0: + return "SANS2D00022024" + if column == 13: + return user_file_path + else: + return "" else: # For the other rows, we only return sample scatter if column == 0: @@ -64,10 +72,12 @@ def add_listener_mock(listener): mock_listener_list.append(listener) -def create_mock_view(user_file_path, batch_file_path=None): +def create_mock_view(user_file_path, batch_file_path=None, row_user_file_path = ""): + get_cell_mock_with_path = partial(get_cell_mock, user_file_path = row_user_file_path) + view = mock.create_autospec(SANSDataProcessorGui, spec_set=False) view.get_user_file_path = mock.Mock(return_value=user_file_path) - view.get_cell = mock.MagicMock(side_effect=get_cell_mock) + view.get_cell = mock.MagicMock(side_effect=get_cell_mock_with_path) view.get_batch_file_path = mock.MagicMock(return_value=batch_file_path) view.get_number_of_rows = mock.MagicMock(return_value=2) diff --git a/scripts/SANS/sans/test_helper/user_file_test_helper.py b/scripts/SANS/sans/test_helper/user_file_test_helper.py index 6758b99a076209a00d2dd4c3cdeee559960a7b6a..cbc4433c43b5ba2386572c83e3e8a763d5b61552 100644 --- a/scripts/SANS/sans/test_helper/user_file_test_helper.py +++ b/scripts/SANS/sans/test_helper/user_file_test_helper.py @@ -2,80 +2,80 @@ from __future__ import (absolute_import, division, print_function) import tempfile -sample_user_file = ("PRINT for changer\n" - "MASK/CLEAR \n" - "MASK/CLEAR/TIME\n" - "L/WAV 1.5 12.5 0.125/LIN\n" - "L/Q .001,.001, .0126, -.08, .2\n" - "!L/Q .001 .8 .08/log\n" - "L/QXY 0 0.05 .001/lin\n" - "BACK/M1 35000 65000\n" - "BACK/M2 85000 98000\n" - "BACK/MON/TIMES 3500 4500\n" - "BACK/TRANS 123 466\n" - "DET/REAR\n" - "GRAVITY/ON\n" - "!FIT/TRANS/OFF\n" - "FIT/TRANS/LOG 1.5 12.5\n" - "FIT/MONITOR 1000 2000\n" - "mask/rear h0\n" - "mask/rear h190>h191\n" - "mask/rear h167>h172\n" - "mask/rear v0\n" - "mask/rear v191\n" - "mask/front h0\n" - "mask/front h190>h191\n" - "mask/front v0\n" - "mask/front v191\n" - "! dead wire near top\n" - "mask/front h156>h159\n" - "!masking off beamstop arm - 12mm wide @ 19degrees\n" - "!mask/rear/line 12 19\n" - "! spot on rhs beam stop at 11m\n" - "! mask h57>h66+v134>v141\n" - "!\n" - "! mask for Bragg at 12m, 26/03/11, 3 time channels\n" - "mask/time 17500 22000\n" - "!\n" - "L/R 12 15\n" - "L/Q/RCut 200\n" - "L/Q/WCut 8.0\n" - "!PRINT REMOVED RCut=200 WCut=8\n" - "!\n" - "MON/DIRECT=DIRECTM1_15785_12m_31Oct12_v12.dat\n" - "MON/TRANS/SPECTRUM=1/INTERPOLATE\n" - "MON/SPECTRUM=1/INTERPOLATE\n" - "!TRANS/TRANSPEC=3\n" - "TRANS/TRANSPEC=4/SHIFT=-70\n" - "TRANS/RADIUS=7.0\n" - "TRANS/ROI=test.xml, test2.xml\n" - "TRANS/MASK=test3.xml, test4.xml\n" - "!\n" - "set centre 155.45 -169.6\n" - "!\n" - "! 25/10/13 centre gc 22021, fit gdw20 22023\n" - "set scales 0.074 1.0 1.0 1.0 1.0\n" - "! correction to actual sample position, notionally 81mm before shutter\n" - "SAMPLE/OFFSET +53.0\n" - "! Correction to SANS2D encoders in mm\n" - "DET/CORR/REAR/X -16.0\n" - "DET/CORR/REAR/Z 47.0\n" - "DET/CORR/FRONT/X -44.0\n" - "DET/CORR/FRONT/Y -20.0\n" - "DET/CORR/FRONT/Z 47.0\n" - "DET/CORR/FRONT/ROT 0.0\n" - "!\n" - "!! 01/10/13 MASKSANS2d_133F M3 by M1 trans Hellsing, Rennie, Jackson, L1=L2=12m A1=20 and A2=8mm\n" - "L/EVENTSTIME 7000.0,500.0,60000.0\n" - "SAMPLE/PATH/ON\n" - "QRESOL/ON \n" - "QRESOL/DELTAR=11 \n" - "QRESOL/LCOLLIM=12 \n" - "QRESOL/MODERATOR=moderator_rkh_file.txt\n" - "QRESOL/A1=13\n" - "QRESOL/A2=14\n" - "TUBECALIBFILE=TUBE_SANS2D_BOTH_31681_25Sept15.nxs" - ) +base_user_file = ("PRINT for changer\n" + "MASK/CLEAR \n" + "MASK/CLEAR/TIME\n" + "L/WAV 1.5 12.5 0.125/LIN\n" + "L/Q .001,.001, .0126, -.08, .2\n" + "!L/Q .001 .8 .08/log\n" + "L/QXY 0 0.05 .001/lin\n" + "BACK/M1 35000 65000\n" + "BACK/M2 85000 98000\n" + "BACK/MON/TIMES 3500 4500\n" + "BACK/TRANS 123 466\n" + "DET/REAR\n" + "GRAVITY/{}\n" + "!FIT/TRANS/OFF\n" + "FIT/TRANS/LOG 1.5 12.5\n" + "FIT/MONITOR 1000 2000\n" + "mask/rear h0\n" + "mask/rear h190>h191\n" + "mask/rear h167>h172\n" + "mask/rear v0\n" + "mask/rear v191\n" + "mask/front h0\n" + "mask/front h190>h191\n" + "mask/front v0\n" + "mask/front v191\n" + "! dead wire near top\n" + "mask/front h156>h159\n" + "!masking off beamstop arm - 12mm wide @ 19degrees\n" + "!mask/rear/line 12 19\n" + "! spot on rhs beam stop at 11m\n" + "! mask h57>h66+v134>v141\n" + "!\n" + "! mask for Bragg at 12m, 26/03/11, 3 time channels\n" + "mask/time 17500 22000\n" + "!\n" + "L/R 12 15\n" + "L/Q/RCut 200\n" + "L/Q/WCut 8.0\n" + "!PRINT REMOVED RCut=200 WCut=8\n" + "!\n" + "MON/DIRECT=DIRECTM1_15785_12m_31Oct12_v12.dat\n" + "MON/TRANS/SPECTRUM=1/INTERPOLATE\n" + "MON/SPECTRUM=1/INTERPOLATE\n" + "!TRANS/TRANSPEC=3\n" + "TRANS/TRANSPEC=4/SHIFT=-70\n" + "TRANS/RADIUS=7.0\n" + "TRANS/ROI=test.xml, test2.xml\n" + "TRANS/MASK=test3.xml, test4.xml\n" + "!\n" + "set centre 155.45 -169.6\n" + "!\n" + "! 25/10/13 centre gc 22021, fit gdw20 22023\n" + "set scales 0.074 1.0 1.0 1.0 1.0\n" + "! correction to actual sample position, notionally 81mm before shutter\n" + "SAMPLE/OFFSET +53.0\n" + "! Correction to SANS2D encoders in mm\n" + "DET/CORR/REAR/X -16.0\n" + "DET/CORR/REAR/Z 47.0\n" + "DET/CORR/FRONT/X -44.0\n" + "DET/CORR/FRONT/Y -20.0\n" + "DET/CORR/FRONT/Z 47.0\n" + "DET/CORR/FRONT/ROT 0.0\n" + "!\n" + "!! 01/10/13 MASKSANS2d_133F M3 by M1 trans Hellsing, Rennie, Jackson, L1=L2=12m A1=20 and A2=8mm\n" + "L/EVENTSTIME 7000.0,500.0,60000.0\n" + "SAMPLE/PATH/ON\n" + "QRESOL/ON \n" + "QRESOL/DELTAR=11 \n" + "QRESOL/LCOLLIM=12 \n" + "QRESOL/MODERATOR=moderator_rkh_file.txt\n" + "QRESOL/A1=13\n" + "QRESOL/A2=14\n" + "TUBECALIBFILE=TUBE_SANS2D_BOTH_31681_25Sept15.nxs" + ) def create_user_file(user_file_content): @@ -84,3 +84,11 @@ def create_user_file(user_file_content): user_file_path = temp.name temp.close() return user_file_path + + +def make_sample_user_file(gravity ='ON'): + return base_user_file.format(gravity) + + +sample_user_file = make_sample_user_file(gravity ='ON') +sample_user_file_gravity_OFF = make_sample_user_file(gravity ='OFF') diff --git a/scripts/test/SANS/gui_logic/gui_state_director_test.py b/scripts/test/SANS/gui_logic/gui_state_director_test.py index 138f78caaca1a4af4d622240bf1021e9d381661e..73f5a62dc018f946bb1684d7088fcb3d975e46c7 100644 --- a/scripts/test/SANS/gui_logic/gui_state_director_test.py +++ b/scripts/test/SANS/gui_logic/gui_state_director_test.py @@ -3,8 +3,6 @@ from __future__ import (absolute_import, division, print_function) import unittest import os -import mantid - from sans.gui_logic.presenter.gui_state_director import GuiStateDirector from sans.gui_logic.models.table_model import (TableModel, TableIndexModel) from sans.gui_logic.models.state_gui_model import StateGuiModel @@ -18,7 +16,7 @@ class GuiStateDirectorTest(unittest.TestCase): @staticmethod def _get_table_model(option_string=""): table_index_model = TableIndexModel(0, "SANS2D00022024", "", "", "", "", "", "", "", "", - "", "", "", "", option_string) + "", "", "", "", "", option_string) table_model = TableModel() table_model.add_table_entry(0, table_index_model) return table_model @@ -69,5 +67,3 @@ class GuiStateDirectorTest(unittest.TestCase): if __name__ == '__main__': unittest.main() - - diff --git a/scripts/test/SANS/gui_logic/main_presenter_test.py b/scripts/test/SANS/gui_logic/main_presenter_test.py index f3e0e7aaf4e9a12b3a6e8183dc3301ff2b07788e..06f6fa8701a47d022495285ca92b99fd0b8c08f5 100644 --- a/scripts/test/SANS/gui_logic/main_presenter_test.py +++ b/scripts/test/SANS/gui_logic/main_presenter_test.py @@ -21,7 +21,7 @@ class MainPresenterTest(unittest.TestCase): presenter = MainPresenter(SANSFacility.ISIS) self.assertTrue(presenter.get_number_of_white_list_items() == 0) white_list = presenter.get_white_list() - self.assertTrue(presenter.get_number_of_white_list_items() == 16) + self.assertTrue(presenter.get_number_of_white_list_items() == 17) self.assertTrue(white_list[0].algorithm_property == "SampleScatter") self.assertTrue(white_list[1].algorithm_property == "SampleScatterPeriod") self.assertTrue(white_list[2].algorithm_property == "SampleTransmission") @@ -36,15 +36,16 @@ class MainPresenterTest(unittest.TestCase): self.assertTrue(white_list[11].algorithm_property == "CanDirectPeriod") self.assertTrue(white_list[12].algorithm_property == "UseOptimizations") self.assertTrue(white_list[13].algorithm_property == "OutputName") - self.assertTrue(white_list[14].algorithm_property == "RowIndex") - self.assertTrue(white_list[15].algorithm_property == "OutputMode") + self.assertTrue(white_list[14].algorithm_property == "UserFile") + self.assertTrue(white_list[15].algorithm_property == "RowIndex") + self.assertTrue(white_list[16].algorithm_property == "OutputMode") def test_that_black_list_is_correct(self): presenter = MainPresenter(SANSFacility.ISIS) expected = "InputWorkspace,OutputWorkspace,SampleScatter,SampleScatterPeriod,SampleTransmission," \ "SampleTransmissionPeriod,SampleDirect,SampleDirectPeriod,CanScatter,CanScatterPeriod," \ "CanTransmission,CanTransmissionPeriod,CanDirect,CanDirectPeriod," \ - "UseOptimizations,OutputName,RowIndex,OutputMode," + "UseOptimizations,OutputName,UserFile,RowIndex,OutputMode," self.assertTrue(expected == presenter.get_black_list()) def test_that_gets_pre_processing_options_are_valid_and_other_options_are_empty(self): diff --git a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py index db3c7871cb0df517c2d20195a7a21922ac2a7f69..b95ddfbb762b6bfff313d22e8c81d2afad885bb1 100644 --- a/scripts/test/SANS/gui_logic/run_tab_presenter_test.py +++ b/scripts/test/SANS/gui_logic/run_tab_presenter_test.py @@ -10,7 +10,7 @@ from mantid.kernel import PropertyManagerDataService from sans.gui_logic.presenter.run_tab_presenter import RunTabPresenter from sans.common.enums import (SANSFacility, ReductionDimensionality, SaveType, ISISReductionMode, RangeStepType, FitType) -from sans.test_helper.user_file_test_helper import (create_user_file, sample_user_file) +from sans.test_helper.user_file_test_helper import (create_user_file, sample_user_file, sample_user_file_gravity_OFF) from sans.test_helper.mock_objects import (create_mock_view) from sans.test_helper.common import (remove_file, save_to_csv) @@ -104,7 +104,7 @@ class RunTabPresenterTest(unittest.TestCase): # Assert certain function calls self.assertTrue(view.get_user_file_path.call_count == 3) self.assertTrue(view.get_batch_file_path.call_count == 2) # called twice for the sub presenter updates (masking table and settings diagnostic tab) # noqa - self.assertTrue(view.get_cell.call_count == 60) + self.assertTrue(view.get_cell.call_count == 64) self.assertTrue(view.get_number_of_rows.call_count == 6) @@ -201,6 +201,7 @@ class RunTabPresenterTest(unittest.TestCase): # Check some entries self.assertTrue(state0.slice.start_time is None) self.assertTrue(state0.slice.end_time is None) + self.assertTrue(state0.reduction.reduction_dimensionality is ReductionDimensionality.OneDim) # Clean up @@ -227,6 +228,22 @@ class RunTabPresenterTest(unittest.TestCase): # Clean up self._remove_files(user_file_path=user_file_path, batch_file_path=batch_file_path) + def test_that_can_get_states_from_row_user_file(self): + # Arrange + row_user_file_path = create_user_file(sample_user_file_gravity_OFF) + batch_file_path, user_file_path, presenter, _ = self._get_files_and_mock_presenter(BATCH_FILE_TEST_CONTENT_2, row_user_file_path) + + presenter.on_user_file_load() + presenter.on_batch_file_load() + + # Act + state = presenter.get_state_for_row(1) + state0 = presenter.get_state_for_row(0) + + # Assert + self.assertTrue(state.convert_to_q.use_gravity is False) + self.assertTrue(state0.convert_to_q.use_gravity is True) + def test_that_returns_none_when_index_does_not_exist(self): # Arrange batch_file_path = save_to_csv(BATCH_FILE_TEST_CONTENT_2) @@ -357,10 +374,10 @@ class RunTabPresenterTest(unittest.TestCase): PropertyManagerDataService.remove(element) @staticmethod - def _get_files_and_mock_presenter(content): + def _get_files_and_mock_presenter(content, row_user_file_path = ""): batch_file_path = save_to_csv(content) user_file_path = create_user_file(sample_user_file) - view, _, _ = create_mock_view(user_file_path, batch_file_path) + view, _, _ = create_mock_view(user_file_path, batch_file_path, row_user_file_path) # We just use the sample_user_file since it exists. view.get_mask_file = mock.MagicMock(return_value=user_file_path) presenter = RunTabPresenter(SANSFacility.ISIS) diff --git a/scripts/test/SANS/gui_logic/table_model_test.py b/scripts/test/SANS/gui_logic/table_model_test.py index 232b497917111305f0b2e93bb444f2ba9444a5d7..739b2aaaa733098e84f66bac0629c0f2b273aea0 100644 --- a/scripts/test/SANS/gui_logic/table_model_test.py +++ b/scripts/test/SANS/gui_logic/table_model_test.py @@ -2,8 +2,6 @@ from __future__ import (absolute_import, division, print_function) import unittest -import mantid - from sans.gui_logic.models.table_model import (TableModel, TableIndexModel) @@ -31,7 +29,7 @@ class TableModelTest(unittest.TestCase): def test_that_can_set_the_options_column_model(self): table_index_model = TableIndexModel(0, "", "", "", "", "", "", - "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "WavelengthMin=1, WavelengthMax=3, NotRegister2=1") options_column_model = table_index_model.options_column_model options = options_column_model.get_options() @@ -40,10 +38,23 @@ class TableModelTest(unittest.TestCase): self.assertTrue(options["WavelengthMax"] == 3.) def test_that_raises_for_missing_equal(self): - args = [0, "", "", "", "", "", "", "", "", "", "", "", "", "", + args = [0, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "WavelengthMin=1, WavelengthMax=3, NotRegister2"] self.assertRaises(ValueError, TableIndexModel, *args) + def test_that_querying_nonexistent_row_index_raises_IndexError_exception(self): + table_model = TableModel() + args = [0] + self.assertRaises(IndexError, table_model.get_row_user_file, *args) + + def test_that_can_retrieve_user_file_from_table_index_model(self): + table_model = TableModel() + table_index_model = TableIndexModel(2, "", "", "", "", "", "", + "", "", "", "", "", "", "", "User_file_name") + table_model.add_table_entry(2, table_index_model) + user_file = table_model.get_row_user_file(2) + self.assertEqual(user_file,"User_file_name") + def _do_test_file_setting(self, func, prop): # Test that can set to empty string table_model = TableModel() @@ -71,5 +82,6 @@ class TableModelTest(unittest.TestCase): table_model = TableModel() table_model.user_file = value + if __name__ == '__main__': unittest.main()