コード例 #1
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        self.data = MuonLoadData()
        self.view = LoadRunWidgetView(parent=self.obj)
        self.model = LoadRunWidgetModel(self.data)
        self.presenter = LoadRunWidgetPresenter(self.view, self.model)

        self.model.load_workspace_from_filename = mock.Mock(
            return_value=([1, 2, 3], "currentRun.nxs", 1234))
        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(
            'Muon.GUI.Common.load_run_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()
        self.load_utils_patcher.exception_message_for_failed_files.return_value = ''
コード例 #2
0
    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) for i, filename in enumerate(files)]

        model = LoadRunWidgetModel(MuonLoadData())
        load_utils_mock.load_workspace_from_filename = mock.Mock()
        load_utils_mock.load_workspace_from_filename.side_effect = load_return_vals

        model.loadData(files)
        model.execute()
        self.assertEqual(len(model.loaded_runs), 3)
        model.clear_loaded_data()
        self.assertEqual(model.loaded_workspaces, [])
        self.assertEqual(model.loaded_filenames, [])
        self.assertEqual(model.loaded_runs, [])
コード例 #3
0
    def setUp(self):
        self._qapp = mock_widget.mockQapp()
        # Store an empty widget to parent all the views, and ensure they are deleted correctly
        self.obj = QtGui.QWidget()

        self.data = MuonLoadData()
        self.view = LoadRunWidgetView(parent=self.obj)
        self.model = LoadRunWidgetModel(self.data)
        self.presenter = LoadRunWidgetPresenter(self.view, self.model)
        self.presenter.enable_multiple_files(False)
        self.presenter.set_current_instrument("EMU")

        patcher = mock.patch(
            'Muon.GUI.Common.load_run_widget.model.load_utils')
        self.addCleanup(patcher.stop)
        self.load_utils_patcher = patcher.start()
        self.load_utils_patcher.exception_message_for_failed_files.return_value = ''
コード例 #4
0
    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) for i, filename in enumerate(files)]

        model = LoadRunWidgetModel(MuonLoadData())
        load_utils_mock.load_workspace_from_filename = mock.MagicMock()

        load_utils_mock.load_workspace_from_filename.side_effect = iter(IteratorWithException(load_return_vals, [1]))

        model.loadData(files)
        with self.assertRaises(ValueError):
            model.execute()
        self.assertEqual(len(model.loaded_workspaces), 2)
        self.assertEqual(model.loaded_filenames[0], files[0])
        self.assertEqual(model.loaded_filenames[1], files[2])
        self.assertEqual(model.loaded_runs[0], 19489)
        self.assertEqual(model.loaded_runs[1], 19491)
コード例 #5
0
    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) for i, filename in enumerate(files)]

        model = LoadRunWidgetModel(MuonLoadData())
        load_utils_mock.load_workspace_from_filename = mock.MagicMock()
        load_utils_mock.load_workspace_from_filename.side_effect = load_return_vals

        model.loadData(files)
        model.execute()
        self.assertEqual(len(model.loaded_workspaces), len(model.loaded_runs))
        self.assertEqual(len(model.loaded_workspaces), len(model.loaded_filenames))
        self.assertEqual(len(model.loaded_workspaces), 3)
        self.assertEqual(model.loaded_runs[0], 19489)
        self.assertEqual(model.loaded_runs[1], 19490)
        self.assertEqual(model.loaded_runs[2], 19491)
コード例 #6
0
 def test_executing_load_without_filenames_does_nothing(self):
     model = LoadRunWidgetModel(MuonLoadData())
     model.execute()
     self.assertEqual(model.loaded_workspaces, [])
     self.assertEqual(model.loaded_filenames, [])
     self.assertEqual(model.loaded_runs, [])
コード例 #7
0
 def test_model_initialized_with_empty_lists_of_loaded_data(self):
     model = LoadRunWidgetModel(MuonLoadData())
     self.assertEqual(model.loaded_workspaces, [])
     self.assertEqual(model.loaded_filenames, [])
     self.assertEqual(model.loaded_runs, [])