Example #1
0
    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()
Example #2
0
 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)
Example #3
0
    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))
Example #4
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 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 _generate_presenter(self):
     mock_view = mock.Mock(get_selected_ax_name=lambda: "My Axes: (0, 0)")
     return Presenter(self.fig, view=mock_view)
Example #7
0
 def _generate_presenter(self):
     mock_view = mock.Mock(get_selected_ax_name=lambda: "My Axes: (0, 0)",
                           get_axis=lambda: "x",
                           get_properties=lambda: {})
     return Presenter(self.fig, view=mock_view)