def setUpClass(cls): # Mock axes tab view mock_axes_view = Mock( get_selected_ax_name=lambda: '(0, 0)', get_properties=lambda: AxProperties(new_ax_view_props)) cls.ax_view_patch = patch(AX_VIEW, lambda x: mock_axes_view) cls.ax_view_mock = cls.ax_view_patch.start() # Mock curves tab view cls.curve_view_mock = Mock( get_selected_curve_name=lambda: 'old label', get_selected_ax_name=lambda: '(0, 0)', get_properties=lambda: CurveProperties(new_curve_view_props)) cls.curve_view_patch = patch(CURVE_VIEW, lambda x: cls.curve_view_mock) cls.curve_view_patch.start() cls.ax = _run_apply_properties_on_figure_with_curve() cls.new_curve = cls.ax.containers[0] # Mock images tab view cls.img_view_mock = Mock( get_selected_image_name=lambda: '(0, 0) - old label', get_properties=lambda: ImageProperties(new_image_props)) cls.img_view_patch = patch(IMAGE_VIEW, lambda x: cls.img_view_mock) cls.img_view_patch.start() cls.img_ax = _run_apply_properties_on_figure_with_image() cls.new_img = cls.img_ax.images[0]
def update_view(self): """Update the properties in the view from the selected axes""" ax_props = self.get_selected_ax_properties() self.view.set_title(ax_props.title) self.view.set_xlower_limit(ax_props.xlim[0]) self.view.set_xupper_limit(ax_props.xlim[1]) self.view.set_xlabel(ax_props.xlabel) self.view.set_xscale(ax_props.xscale) self.view.set_ylower_limit(ax_props.ylim[0]) self.view.set_yupper_limit(ax_props.ylim[1]) self.view.set_ylabel(ax_props.ylabel) self.view.set_yscale(ax_props.yscale) self.current_view_props = AxProperties.from_view(self.view)
def setUpClass(cls): # Mock axes tab view mock_axes_view = Mock( get_selected_ax_name=lambda: '(0, 0)', get_properties=lambda: AxProperties(new_ax_view_props)) cls.ax_view_patch = patch(AX_VIEW, lambda x: mock_axes_view) cls.ax_view_mock = cls.ax_view_patch.start() # Mock curves tab view cls.curve_view_mock = Mock( get_selected_ax_name=lambda: '(0, 0)', select_curve_list=Mock(selectedItems=lambda: []), get_properties=lambda: CurveProperties(new_curve_view_props)) cls.curve_view_patch = patch(CURVE_VIEW, lambda x: cls.curve_view_mock) cls.curve_view_patch.start() cls.ax = _run_apply_properties_on_figure_with_curve( cls.curve_view_mock) cls.new_curve = cls.ax.containers[0] # Mock images tab view if LooseVersion(matplotlib.__version__) > LooseVersion("3.1.3"): cls.img_view_mock = Mock( get_selected_image_name=lambda: '(0, 0) - child0', get_properties=lambda: ImageProperties(new_image_props)) else: cls.img_view_mock = Mock( get_selected_image_name=lambda: '(0, 0) - image0', get_properties=lambda: ImageProperties(new_image_props)) cls.img_view_patch = patch(IMAGE_VIEW, lambda x: cls.img_view_mock) cls.img_view_patch.start() cls.img_ax = _run_apply_properties_on_figure_with_image() cls.new_img = cls.img_ax.images[0] # Mock legend tab view cls.legend_view_mock = Mock( get_properties=lambda: LegendProperties(new_legend_props)) cls.legend_view_patch = patch(LEGEND_VIEW, lambda x: cls.legend_view_mock) cls.legend_view_patch.start() cls.legend_ax = _run_apply_properties_on_figure_with_legend( cls.curve_view_mock) cls.new_legend = cls.legend_ax.get_legend()
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 get_properties(self): return AxProperties.from_view(self)
def get_selected_ax_properties(self): """Get axes properties from selected axes""" return AxProperties.from_ax_object(self.get_selected_ax())