def test_apply_all_properties_with_errors_notifies_parent_presenter_on_allowed_exceptions( self): mock_view = mock.Mock(get_selected_ax_name=lambda: "My Axes: (0, 0)", get_axis=lambda: "x", get_properties=lambda: {}) mock_success_callback, mock_error_callback = mock.Mock(), mock.Mock() presenter = Presenter(self.fig, view=mock_view, success_callback=mock_success_callback, error_callback=mock_error_callback) # Only these exceptions should be caught by the axes tab. for exception in [ AssertionError, IndexError, KeyError, TypeError, ValueError ]: presenter.apply_all_properties = mock.Mock( side_effect=exception("This exception should be caught!")) presenter._apply_all_properties_with_errors() mock_success_callback.assert_not_called() mock_error_callback.assert_called() presenter.apply_all_properties.reset_mock() mock_success_callback.reset_mock() mock_error_callback.reset_mock()
def test_autoscale_changed(self): mock_view = mock.Mock( get_selected_ax_name=lambda: "My Axes: (0, 0)", get_axis=lambda: "x", get_properties=lambda: {}, get_autoscale_enabled=mock.Mock(return_value=True)) presenter = Presenter(self.fig, view=mock_view) mock_view.reset_mock() presenter.autoscale_changed() mock_view.get_autoscale_enabled.assert_called_once_with() mock_view.set_limit_input_enabled.assert_called_once_with(False)
def test_ax_limits_set_correctly(self): mock_view = mock.Mock(get_lower_limit=mock.Mock(return_value=-1.0), get_upper_limit=mock.Mock(return_value=10.0), get_selected_ax_name=lambda: "My Axes: (0, 0)", get_axis=lambda: "x", get_properties=lambda: {}) presenter = Presenter(self.fig, view=mock_view) presenter.get_selected_ax_name = 'x' presenter.axis_changed() self.assertEqual(presenter.current_view_props["xlim"], (-1.0, 10.0))
def test_apply_all_properties_with_errors_notifies_parent_presenter_on_success( self): mock_view = mock.Mock(get_selected_ax_name=lambda: "My Axes: (0, 0)", get_axis=lambda: "x", get_properties=lambda: {}) mock_success_callback, mock_error_callback = mock.Mock(), mock.Mock() presenter = Presenter(self.fig, view=mock_view, success_callback=mock_success_callback, error_callback=mock_error_callback) presenter.apply_all_properties = mock.Mock() presenter._apply_all_properties_with_errors() mock_success_callback.assert_called() mock_error_callback.assert_not_called()
def __init__(self, fig, view=None, parent=None): self.fig = fig if view: self.view = view else: self.view = PlotConfigDialogView(parent) self.view.show() self.tab_widget_presenters = [None, None, None] self.tab_widget_views = [None, None, None] # Axes tab if len(self.fig.get_axes()) > 0: axes_tab = AxesTabWidgetPresenter(self.fig, parent=self.view) self.tab_widget_presenters[0] = axes_tab self.tab_widget_views[0] = (axes_tab.view, "Axes") # Curves tab if curve_in_figure(self.fig): curves_tab = CurvesTabWidgetPresenter(self.fig, parent=self.view) self.tab_widget_presenters[1] = curves_tab self.tab_widget_views[1] = (curves_tab.view, "Curves") # Images tab if image_in_figure(self.fig): images_tab = ImagesTabWidgetPresenter(self.fig, parent=self.view) self.tab_widget_presenters[2] = images_tab self.tab_widget_views[2] = (images_tab.view, "Images") self._add_tab_widget_views() # Signals self.view.ok_button.clicked.connect(self.apply_properties_and_exit) self.view.apply_button.clicked.connect(self.apply_properties) self.view.cancel_button.clicked.connect(self.exit)
def test_apply_properties_correctly_handles_negative_axis_when_changing_to_log_scale( self): fig = figure() ax = fig.add_subplot(111) ax.plot([0, 1], [10, 12], 'rx') ax.set_title("My Axes") mock_view = mock.Mock(get_selected_ax_name=lambda: "My Axes: (0, 0)") presenter = Presenter(fig, view=mock_view) ax_properties = AxProperties.from_ax_object(ax) min_limit = -10 max_limit = 10 ax_properties.xscale = 'Log' ax_properties.xlim = (min_limit, max_limit) ax_properties.yscale = 'Log' ax_properties.ylim = (min_limit, max_limit) presenter.view.get_properties.return_value = ax_properties presenter.apply_properties() self.assertEqual(ax.get_xlim(), (0.01 * max_limit, max_limit)) self.assertEqual(ax.get_ylim(), (0.01 * max_limit, max_limit))
def __init__(self, fig, view=None, parent=None): self.fig = fig if view: self.view = view else: self.view = PlotConfigDialogView(parent) self.view.show() self.tab_widget_presenters = [None, None, None, None] self.tab_widget_views = [None, None, None, None] legend_tab = None # Axes tab if len(self.fig.get_axes()) > 0: axes_tab = AxesTabWidgetPresenter( self.fig, parent=self.view, success_callback=self.success_callback, error_callback=self.error_callback) self.tab_widget_presenters[1] = axes_tab self.tab_widget_views[0] = (axes_tab.view, "Axes") # Legend tab if legend_in_figure(self.fig): legend_tab = LegendTabWidgetPresenter(self.fig, parent_view=self.view, parent_presenter=self) self.tab_widget_presenters[0] = legend_tab self.tab_widget_views[3] = (legend_tab.view, "Legend") # Curves tab if curve_in_figure(self.fig): curves_tab = CurvesTabWidgetPresenter(self.fig, parent_view=self.view, parent_presenter=self, legend_tab=legend_tab) self.tab_widget_presenters[2] = curves_tab self.tab_widget_views[1] = (curves_tab.view, "Curves") # Images tab if image_in_figure(self.fig): images_tab = ImagesTabWidgetPresenter(self.fig, parent=self.view) self.tab_widget_presenters[3] = images_tab self.tab_widget_views[2] = (images_tab.view, "Images") self._add_tab_widget_views() # Signals self.view.ok_button.clicked.connect(self.apply_properties_and_exit) self.view.apply_button.clicked.connect(self.apply_properties) self.view.cancel_button.clicked.connect(self.exit) self.view.help_button.clicked.connect(self.open_help_window) self.error_state = False