Esempio n. 1
0
 def test_hide_overplot_line(self, remove_line_mock):
     slice_presenter = SlicePlotterPresenter()
     cache_mock = mock.MagicMock()
     key = 5
     type(cache_mock).overplot_lines = {key: 'line'}
     slice_presenter._slice_cache['workspace'] = cache_mock
     slice_presenter.hide_overplot_line('workspace', key)
     self.assertTrue(key not in cache_mock.overplot_lines)
     remove_line_mock.assert_called_once_with('line')
 def test_hide_overplot_line(self, remove_line_mock):
     slice_presenter = SlicePlotterPresenter()
     cache_mock = mock.MagicMock()
     key = 5
     type(cache_mock).overplot_lines = {key: 'line'}
     slice_presenter._slice_cache['workspace'] = cache_mock
     slice_presenter.hide_overplot_line('workspace', key)
     self.assertTrue(key not in cache_mock.overplot_lines)
     remove_line_mock.assert_called_once_with('line')
Esempio n. 3
0
 def test_slice_psd(self, get_spp):
     get_spp.return_value = SlicePlotterPresenter()
     workspace = self.create_pixel_workspace('test_slice_psd_cli')
     result = Slice(workspace)
     signal = result.get_signal()
     self.assertEqual(type(result), HistogramWorkspace)
     self.assertEqual(60, signal[0][9])
     self.assertEqual(110, signal[3][7])
     self.assertEqual(105, signal[5][6])
 def test_plot_slice_success(self, compute_slice_mock, sample_temp_mock, get_workspace_handle_mock,
                             create_slice_mock, plot_cached_slice_mock):
     workspace_mock = mock.MagicMock()
     name = mock.PropertyMock(return_value='workspace')
     type(workspace_mock).name = name
     slice_mock = mock.MagicMock()
     slice_name = mock.PropertyMock(return_value='__workspace')
     type(slice_mock).name = slice_name
     get_workspace_handle_mock.return_value = workspace_mock
     sample_temp_mock.return_value = 5
     compute_slice_mock.return_value = slice_mock
     x_axis = Axis('x', 0, 1, 0.1)
     y_axis = Axis('y', 0, 1, 0.1)
     slice_presenter = SlicePlotterPresenter()
     slice_presenter.plot_slice('workspace', x_axis, y_axis, 7, 8, False, DEFAULT_CMAP)
     self.assertTrue('workspace' in slice_presenter._slice_cache)
     create_slice_mock.assert_called_once()
     plot_cached_slice_mock.assert_called_once()
Esempio n. 5
0
    def __init__(self, in_mantidplot=False):
        QMainWindow.__init__(self)
        load_ui(__file__, 'mainwindow.ui', self)
        self.init_ui()

        self.tabs = [self.wgtSlice, self.wgtCut, self.wgtPowder]
        self.tabs_to_show = {TAB_2D: [TAB_POWDER],
                             TAB_EVENT: [TAB_SLICE, TAB_CUT],
                             TAB_HISTO: [],
                             TAB_NONPSD: [TAB_SLICE, TAB_CUT]}

        self.buttons_to_enable = {TAB_2D: [self.btnAdd, self.btnSubtract],
                                  TAB_EVENT: [self.btnMerge],
                                  TAB_HISTO: [self.btnPlot, self.btnOverplot],
                                  TAB_NONPSD: [self.btnAdd, self.btnSubtract]}
        if in_mantidplot:
            self.buttons_to_enable[TAB_HISTO] += [self.btnSaveToADS]

        self.workspace_presenter = self.wgtWorkspacemanager.get_presenter()
        self.dataloader_presenter = self.data_loading.get_presenter()
        self.slice_plotter_presenter = SlicePlotterPresenter()
        slice_widget_presenter = self.wgtSlice.get_presenter()
        slice_widget_presenter.set_slice_plotter_presenter(self.slice_plotter_presenter)
        self.powder_presenter = self.wgtPowder.get_presenter()
        self.cut_plotter_presenter = CutPlotterPresenter()
        self.cut_widget_presenter = self.wgtCut.get_presenter()
        self.cut_widget_presenter.set_cut_plotter_presenter(self.cut_plotter_presenter)
        self._presenter = MainPresenter(self, self.workspace_presenter, self.dataloader_presenter,
                                        slice_widget_presenter, self.powder_presenter, self.cut_widget_presenter,
                                        self.slice_plotter_presenter, self.cut_plotter_presenter)

        self.wgtWorkspacemanager.tab_changed.connect(self.ws_tab_changed)
        self.setup_save()
        self.btnSave.clicked.connect(self.button_save)
        self.btnAdd.clicked.connect(self.button_add)
        self.btnRename.clicked.connect(self.button_rename)
        self.btnSubtract.clicked.connect(self.button_subtract)
        self.btnDelete.clicked.connect(self.button_delete)
        self.btnMerge.clicked.connect(self.button_merge)
        self.btnPlot.clicked.connect(self.button_plot)
        self.btnOverplot.clicked.connect(self.button_overplot)
        self.btnSaveToADS.clicked.connect(self.button_savetoads)
        self.btnHistory.hide()
        self.ws_tab_changed(0)

        self.wgtCut.error_occurred.connect(self.show_error)
        self.wgtSlice.error_occurred.connect(self.show_error)
        self.wgtWorkspacemanager.error_occurred.connect(self.show_error)
        self.wgtPowder.error_occurred.connect(self.show_error)
        self.data_loading.error_occurred.connect(self.show_error)
        self.wgtCut.busy.connect(self.show_busy)
        self.wgtSlice.busy.connect(self.show_busy)
        self.wgtWorkspacemanager.busy.connect(self.show_busy)
        self.wgtPowder.busy.connect(self.show_busy)
        self.data_loading.busy.connect(self.show_busy)
        self.action_quit.triggered.connect(self.close)
Esempio n. 6
0
 def test_plot_slice_success(self, compute_slice_mock, sample_temp_mock,
                             get_workspace_handle_mock, create_slice_mock,
                             plot_cached_slice_mock):
     workspace_mock = mock.MagicMock()
     name = mock.PropertyMock(return_value='workspace')
     type(workspace_mock).name = name
     slice_mock = mock.MagicMock()
     slice_name = mock.PropertyMock(return_value='__workspace')
     type(slice_mock).name = slice_name
     get_workspace_handle_mock.return_value = workspace_mock
     sample_temp_mock.return_value = 5
     compute_slice_mock.return_value = slice_mock
     x_axis = Axis('x', 0, 1, 0.1)
     y_axis = Axis('y', 0, 1, 0.1)
     slice_presenter = SlicePlotterPresenter()
     slice_presenter.plot_slice('workspace', x_axis, y_axis, 7, 8, False,
                                DEFAULT_CMAP)
     self.assertTrue('workspace' in slice_presenter._slice_cache)
     create_slice_mock.assert_called_once()
     plot_cached_slice_mock.assert_called_once()
Esempio n. 7
0
    def test_add_overplot_line(self, compute_powder_mock, compute_recoil_mock,
                               plot_line_mock):
        slice_presenter = SlicePlotterPresenter()
        compute_recoil_mock.return_value = ('compute', 'recoil')
        compute_powder_mock.return_value = ('compute', 'powder')
        plot_line_mock.return_value = 'plot'
        recoil_key = 5
        powder_key = 6
        cache_mock = mock.MagicMock()
        slice_presenter._slice_cache['workspace'] = cache_mock
        type(cache_mock).overplot_lines = mock.MagicMock()

        slice_presenter.add_overplot_line('workspace', recoil_key, True)
        compute_recoil_mock.assert_called_once()
        cache_mock.overplot_lines.__setitem__.assert_called_with(
            recoil_key, 'plot')
        plot_line_mock.assert_called_with('compute', 'recoil', recoil_key,
                                          True, cache_mock)
        slice_presenter.add_overplot_line('workspace', powder_key, False)
        compute_powder_mock.assert_called_once()
        cache_mock.overplot_lines.__setitem__.assert_called_with(
            powder_key, 'plot')
        plot_line_mock.assert_called_with('compute', 'powder', powder_key,
                                          False, cache_mock)
    def test_add_overplot_line(self, compute_powder_mock, compute_recoil_mock, plot_line_mock):
        slice_presenter = SlicePlotterPresenter()
        compute_recoil_mock.return_value = ([1], [2])
        compute_powder_mock.return_value = ([3], [4])
        plot_line_mock.return_value = 'plot'
        recoil_key = 5
        powder_key = 6
        cache_mock = mock.MagicMock()
        slice_presenter._slice_cache['workspace'] = cache_mock
        type(cache_mock).overplot_lines = mock.MagicMock()
        cache_mock.energy_axis.e_unit = 'cm-1'

        slice_presenter.add_overplot_line('workspace', recoil_key, True)
        compute_recoil_mock.assert_called_once()
        cache_mock.overplot_lines.__setitem__.assert_called_with(recoil_key, 'plot')
        import numpy as np
        plot_line_mock.assert_called_with([1], np.array([2]) * 8.065544, recoil_key, True, cache_mock)
        slice_presenter.add_overplot_line('workspace', powder_key, False)
        compute_powder_mock.assert_called_once()
        cache_mock.overplot_lines.__setitem__.assert_called_with(powder_key, 'plot')
        plot_line_mock.assert_called_with([3], np.array([4]) * 8.065544, powder_key, False, cache_mock)
 def test_validate_intensity_end_less_than_intensity_start_fail(self):
     slice_presenter = SlicePlotterPresenter()
     with self.assertRaises(ValueError):
         slice_presenter.validate_intensity('8', '7')
 def test_validate_intensity_erroneous_type_fail(self):
     slice_presenter = SlicePlotterPresenter()
     with self.assertRaises(ValueError):
         slice_presenter.validate_intensity('j', '8')
 def test_validate_intensity_success(self):
     slice_presenter = SlicePlotterPresenter()
     start, end = slice_presenter.validate_intensity('7', '8')
     self.assertEqual(start, 7.0)
     self.assertEqual(end, 8.0)
 def test_register_master_success(self):
     slice_presenter = SlicePlotterPresenter()
     main_presenter = mock.create_autospec(MainPresenterInterface)
     slice_presenter.register_master(main_presenter)
     main_presenter.subscribe_to_workspace_selection_monitor.assert_called_once_with(slice_presenter)
Esempio n. 13
0
 def test_validate_intensity_end_less_than_intensity_start_fail(self):
     slice_presenter = SlicePlotterPresenter()
     with self.assertRaises(ValueError):
         slice_presenter.validate_intensity('8', '7')
Esempio n. 14
0
 def test_validate_intensity_erroneous_type_fail(self):
     slice_presenter = SlicePlotterPresenter()
     with self.assertRaises(ValueError):
         slice_presenter.validate_intensity('j', '8')
Esempio n. 15
0
 def test_validate_intensity_success(self):
     slice_presenter = SlicePlotterPresenter()
     start, end = slice_presenter.validate_intensity('7', '8')
     self.assertEqual(start, 7.0)
     self.assertEqual(end, 8.0)
Esempio n. 16
0
 def test_register_master_success(self):
     slice_presenter = SlicePlotterPresenter()
     main_presenter = mock.create_autospec(MainPresenterInterface)
     slice_presenter.register_master(main_presenter)
     main_presenter.subscribe_to_workspace_selection_monitor.assert_called_once_with(
         slice_presenter)