Exemple #1
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)]

        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])
Exemple #2
0
    def test_execute_throws_if_one_file_does_not_load_correctly_but_still_loads_other_files(
            self):
        files = [r'EMU00019489.nxs', r'EMU00019490.nxs', r'EMU00019491.nxs']
        load_return_vals = [([1 + i], 19489 + i, filename)
                            for i, filename in enumerate(files)]

        # Mock load to throw on a particular index
        self.load_utils_patcher.load_workspace_from_filename = mock.Mock()
        self.load_utils_patcher.load_workspace_from_filename.side_effect = iter(
            IteratorWithException(load_return_vals, [1]))
        self.model.loadData(files)
        with self.assertRaises(ValueError):
            self.model.execute()

        six.assertCountEqual(self, self.model.loaded_filenames,
                             [files[i] for i in [0, 2]])
        six.assertCountEqual(self, self.model.loaded_runs, [19489, 19491])