def setUp(self): # Store an empty widget to parent all the views, and ensure they are deleted correctly self.obj = QWidget() setup_context_for_tests(self) self.data_context.instrument = 'EMU' self.view = LoadRunWidgetView(parent=self.obj) self.model = LoadRunWidgetModel(self.loaded_data, self.context) self.presenter = LoadRunWidgetPresenter(self.view, self.model) self.model.load_workspace_from_filename = mock.Mock( return_value=([1, 2, 3], "currentRun.nxs", 1234, False)) self.view.warning_popup = mock.Mock() self.view.disable_load_buttons = mock.Mock() self.view.enable_load_buttons = mock.Mock() self.presenter.set_current_instrument("EMU") fileUtils.get_current_run_filename = mock.Mock( return_value="EMU0001234.nxs") patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils' ) self.addCleanup(patcher.stop) self.load_utils_patcher = patcher.start() self.load_utils_patcher.exception_message_for_failed_files.return_value = ''
def setUp(self): # Store an empty widget to parent all the views, and ensure they are deleted correctly self.obj = QWidget() ConfigService['default.instrument'] = 'MUSR' setup_context_for_tests(self) self.context.instrument = 'MUSR' self.load_file_view = BrowseFileWidgetView(self.obj) self.load_run_view = LoadRunWidgetView(self.obj) self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context) self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context) self.view = LoadWidgetView(parent=self.obj, load_file_view=self.load_file_view, load_run_view=self.load_run_view) self.presenter = LoadWidgetPresenter( self.view, LoadWidgetModel(self.loaded_data, self.context)) self.presenter.set_load_file_widget( BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model)) self.presenter.set_load_run_widget( LoadRunWidgetPresenter(self.load_run_view, self.load_run_model)) self.presenter.load_file_widget._view.warning_popup = mock.MagicMock() self.presenter.load_run_widget._view.warning_popup = mock.MagicMock() self.view.multiple_loading_check.setCheckState(1) self.presenter.handle_multiple_files_option_changed() self.runs = [15196, 15197] self.workspaces = [self.create_fake_workspace(1) for _ in self.runs] self.filenames = FileFinder.findRuns( 'MUSR00015196.nxs, MUSR00015197.nxs')
def setUp(self): # Store an empty widget to parent all the views, and ensure they are deleted correctly self.obj = QWidget() setup_context_for_tests(self) self.context.instrument = 'EMU' self.load_file_view = BrowseFileWidgetView(self.obj) self.load_run_view = LoadRunWidgetView(self.obj) self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context) self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context) self.presenter = LoadWidgetPresenter( LoadWidgetView(parent=self.obj, load_file_view=self.load_file_view, load_run_view=self.load_run_view), LoadWidgetModel(self.loaded_data, self.context)) self.presenter.set_load_file_widget( BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model)) self.presenter.set_load_run_widget( LoadRunWidgetPresenter(self.load_run_view, self.load_run_model)) self.filepath = FileFinder.findRuns('MUSR00022725.nxs')[0] self.load_patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename' ) self.addCleanup(self.load_patcher.stop) self.load_mock = self.load_patcher.start() self.load_run_patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename' ) self.addCleanup(self.load_run_patcher.stop) self.load_run_mock = self.load_run_patcher.start() self.mock_workspace = self.create_fake_workspace(1) self.mock_loading_from_browse(self.mock_workspace, r"C:\dir1\dir2\dir3\EMU0001234.nxs", 1234) file_utils.get_current_run_filename = mock.Mock( return_value=r"C:\dir1\dir2\dir3\EMU0001234.nxs") self.presenter.load_file_widget._view.warning_popup = mock.MagicMock() self.presenter.load_run_widget._view.warning_popup = mock.MagicMock() self.popup_patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.thread_model.warning') self.addCleanup(self.popup_patcher.stop) self.popup_mock = self.popup_patcher.start() def setGroupAndPairsToEmptyList(grouping_context): grouping_context._groups = [] grouping_context._pairs = [] self.group_context.reset_group_and_pairs_to_default = mock.MagicMock( side_effect=setGroupAndPairsToEmptyList(self.group_context))
def setUp(self): # Store an empty widget to parent all the views, and ensure they are deleted correctly self.obj = QWidget() self.popup_patcher = mock.patch('mantidqtinterfaces.Muon.GUI.Common.thread_model.warning') self.addCleanup(self.popup_patcher.stop) self.popup_mock = self.popup_patcher.start() self.load_patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.load_file_widget.model.load_utils.load_workspace_from_filename') self.addCleanup(self.load_patcher.stop) self.load_mock = self.load_patcher.start() self.load_run_patcher = mock.patch( 'mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils.load_workspace_from_filename') self.addCleanup(self.load_run_patcher.stop) self.load_run_mock = self.load_run_patcher.start() setup_context_for_tests(self) self.data_context.instrument = 'EMU' self.load_file_view = BrowseFileWidgetView(self.obj) self.load_run_view = LoadRunWidgetView(self.obj) self.load_file_model = BrowseFileWidgetModel(self.loaded_data, self.context) self.load_run_model = LoadRunWidgetModel(self.loaded_data, self.context) self.model = LoadWidgetModel(self.loaded_data, self.context) self.view = LoadWidgetView(parent=self.obj, load_run_view=self.load_run_view, load_file_view=self.load_file_view) self.presenter = LoadWidgetPresenter(view=self.view, model=self.model) self.presenter.set_load_file_widget(BrowseFileWidgetPresenter(self.load_file_view, self.load_file_model)) self.presenter.set_load_run_widget(LoadRunWidgetPresenter(self.load_run_view, self.load_run_model)) self.presenter.load_run_widget.set_current_instrument('EMU') self.presenter.load_file_widget._view.warning_popup = mock.MagicMock() self.presenter.load_run_widget._view.warning_popup = mock.MagicMock() self.load_file_view.show_file_browser_and_return_selection = mock.Mock( return_value=["C:\\dir1\\EMU0001234.nxs"]) self.workspace_mock = self.create_fake_workspace(1) self.load_mock.return_value = (self.workspace_mock, 1234, "C:\\dir1\\EMU0001234.nxs", False) self.load_run_mock.return_value = (self.workspace_mock, 1234, "C:\\dir1\\EMU0001234.nxs", False) self.presenter.load_file_widget.on_browse_button_clicked() self.context.update_current_data = mock.MagicMock(return_value=([], [])) self.wait_for_thread(self.presenter.load_file_widget._load_thread) file_utils.get_current_run_filename = mock.Mock(return_value="EMU0001234.nxs")
def setUp(self): # Store an empty widget to parent all the views, and ensure they are deleted correctly self.obj = QWidget() setup_context_for_tests(self) self.data_context.instrument = 'EMU' self.view = LoadRunWidgetView(parent=self.obj) self.model = LoadRunWidgetModel(self.loaded_data, self.context) self.presenter = LoadRunWidgetPresenter(self.view, self.model) self.presenter.set_current_instrument("EMU") patcher = mock.patch('mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils') self.addCleanup(patcher.stop) self.load_utils_patcher = patcher.start() self.load_utils_patcher.exception_message_for_failed_files.return_value = ''
def __init__(self, loaded_data, context, parent): # set up the views self.load_file_view = BrowseFileWidgetView(parent) self.load_run_view = LoadRunWidgetView(parent) self.load_widget_view = LoadWidgetView( parent=parent, load_file_view=self.load_file_view, load_run_view=self.load_run_view) self.load_widget = LoadWidgetPresenter( self.load_widget_view, LoadWidgetModel(loaded_data, context)) self.file_widget = BrowseFileWidgetPresenter( self.load_file_view, BrowseFileWidgetModel(loaded_data, context)) self.run_widget = LoadRunWidgetPresenter( self.load_run_view, LoadRunWidgetModel(loaded_data, context)) self.load_widget.set_load_file_widget(self.file_widget) self.load_widget.set_load_run_widget(self.run_widget) self.load_widget.set_current_instrument( context.data_context.instrument) context.update_view_from_model_notifier.add_subscriber( self.load_widget.update_view_from_model_observer)
def setUp(self): setup_context_for_tests(self) self.data_context.instrument = 'EMU' self.model = LoadRunWidgetModel(self.loaded_data, self.context)
class LoadRunWidgetModelTest(unittest.TestCase): def setUp(self): setup_context_for_tests(self) self.data_context.instrument = 'EMU' self.model = LoadRunWidgetModel(self.loaded_data, self.context) def test_model_initialized_with_empty_lists_of_loaded_data(self): self.assertEqual(self.model.loaded_workspaces, []) self.assertEqual(self.model.loaded_filenames, []) self.assertEqual(self.model.loaded_runs, []) def test_executing_load_without_filenames_does_nothing(self): self.model.execute() self.assertEqual(self.model.loaded_workspaces, []) self.assertEqual(self.model.loaded_filenames, []) self.assertEqual(self.model.loaded_runs, []) @mock.patch('mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils') def test_execute_successfully_loads_valid_files(self, load_utils_mock): # Mock the load algorithm files = [r'EMU00019489.nxs', r'EMU00019490.nxs', r'EMU00019491.nxs'] load_return_vals = [([1, 2, 3], 19489 + i, filename, False) for i, filename in enumerate(files)] load_utils_mock.load_workspace_from_filename = mock.MagicMock() load_utils_mock.load_workspace_from_filename.side_effect = load_return_vals self.model.loadData(files) self.model.execute() self.assertEqual(len(self.model.loaded_workspaces), len(self.model.loaded_runs)) self.assertEqual(len(self.model.loaded_workspaces), len(self.model.loaded_filenames)) self.assertEqual(len(self.model.loaded_workspaces), 3) self.assertEqual(self.model.loaded_runs[0], [19489]) self.assertEqual(self.model.loaded_runs[1], [19490]) self.assertEqual(self.model.loaded_runs[2], [19491]) @mock.patch('mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils') def test_model_is_cleared_correctly(self, load_utils_mock): files = [r'EMU00019489.nxs', r'EMU00019490.nxs', r'EMU00019491.nxs'] load_return_vals = [([1, 2, 3], filename, 19489 + i, False) for i, filename in enumerate(files)] load_utils_mock.load_workspace_from_filename = mock.Mock() load_utils_mock.load_workspace_from_filename.side_effect = load_return_vals self.model.loadData(files) self.model.execute() self.assertEqual(len(self.model.loaded_runs), 3) self.model.clear_loaded_data() self.assertEqual(self.model.loaded_workspaces, []) self.assertEqual(self.model.loaded_filenames, []) self.assertEqual(self.model.loaded_runs, []) @mock.patch('mantidqtinterfaces.Muon.GUI.Common.load_run_widget.load_run_model.load_utils') def test_execute_throws_if_one_file_does_not_load_correctly_but_still_loads_other_files(self, load_utils_mock): files = [r'EMU00019489.nxs', r'EMU00019490.nxs', r'EMU00019491.nxs'] load_return_vals = [([1, 2, 3], 19489 + i, filename, False) for i, filename in enumerate(files)] load_utils_mock.load_workspace_from_filename = mock.MagicMock() load_utils_mock.load_workspace_from_filename.side_effect = iter(IteratorWithException(load_return_vals, [1])) self.model.loadData(files) with self.assertRaises(ValueError): self.model.execute() self.assertEqual(len(self.model.loaded_workspaces), 2) self.assertEqual(self.model.loaded_filenames[0], files[0]) self.assertEqual(self.model.loaded_filenames[1], files[2]) self.assertEqual(self.model.loaded_runs[0], [19489]) self.assertEqual(self.model.loaded_runs[1], [19491])