def __init__(self, parent, context): self._figure_options = QuickEditWidget(parent) self._plotting_view = PlottingCanvasView(parent) self._plotting_view.add_widget(self._figure_options.widget) self._model = PlottingCanvasModel(context) self._presenter = PlottingCanvasPresenter(self._plotting_view, self._model, self._figure_options)
def __init__(self, parent, context, plot_model, figure_options=None): if figure_options: self._figure_options = figure_options else: self._figure_options = QuickEditWidget(context, parent) self._plotting_view = PlottingCanvasView(self._figure_options.widget, context.settings, parent) self._model = PlottingCanvasModel(plot_model) self._presenter = PlottingCanvasPresenter(self._plotting_view, self._model, self._figure_options, context)
class PlottingCanvasModelTest(unittest.TestCase): def setUp(self): self.util = mock.Mock() self.model = PlottingCanvasModel(self.util) def test_create_workspace_plot_information_calls_get_plot_axis_correctly( self): self.util._get_workspace_plot_axis = mock.MagicMock(return_value=1) self.util._is_guess_workspace = mock.MagicMock(return_value=True) test_ws_names = ["MUSR62260; Group; fwd", "MUSR62260; Group; fwd"] test_axis = [0, 0] self.model._axes_workspace_map = 0 self.model.create_workspace_plot_information(test_ws_names, test_axis, errors=False) self.util._get_workspace_plot_axis.assert_any_call(test_ws_names[0], 0) self.util._get_workspace_plot_axis.assert_any_call(test_ws_names[1], 0) def test_create_workspace_plot_information_calls_create_plot_information_correctly( self): self.model._is_tiled = True axis = 2 self.util._get_workspace_plot_axis = mock.MagicMock(return_value=2) self.model.create_plot_information = mock.MagicMock() self.util._is_guess_workspace = mock.MagicMock(return_value=False) test_ws_names = ["MUSR62260; Group; fwd", "MUSR62260; Group; fwd"] test_indies = [0, 0] self.model.create_workspace_plot_information(test_ws_names, test_indies, errors=False) self.model.create_plot_information.assert_any_call( test_ws_names[0], test_indies[0], axis, False) self.model.create_plot_information.assert_any_call( test_ws_names[1], test_indies[1], axis, False)
def setUp(self): self.context = mock.Mock() self.model = PlottingCanvasModel(self.context) self.context.data_context.instrument = "MUSR"
class PlottingCanvasModelTest(unittest.TestCase): def setUp(self): self.context = mock.Mock() self.model = PlottingCanvasModel(self.context) self.context.data_context.instrument = "MUSR" def test_create_workspace_plot_information_calls_get_plot_axis_correctly( self): self.model._get_workspace_plot_axis = mock.MagicMock(return_value=1) test_ws_names = ["MUSR62260; Group; fwd", "MUSR62260; Group; fwd"] test_indies = [0, 0] self.model.create_workspace_plot_information(test_ws_names, test_indies, errors=False) self.model._get_workspace_plot_axis.assert_any_call(test_ws_names[0]) self.model._get_workspace_plot_axis.assert_any_call(test_ws_names[1]) def test_create_workspace_plot_information_calls_create_plot_information_correctly( self): self.model._is_tiled = True axis = 2 self.model._get_workspace_plot_axis = mock.MagicMock(return_value=2) self.model.create_plot_information = mock.MagicMock() test_ws_names = ["MUSR62260; Group; fwd", "MUSR62260; Group; fwd"] test_indies = [0, 0] self.model.create_workspace_plot_information(test_ws_names, test_indies, errors=False) self.model.create_plot_information.assert_any_call( test_ws_names[0], test_indies[0], axis, False) self.model.create_plot_information.assert_any_call( test_ws_names[1], test_indies[1], axis, False) def test_get_workspace_plot_axis_returns_correct_axis_for_tiled_plot(self): self.model._is_tiled = True self.model._tiled_by = "Group/Pair" self.model._axes_workspace_map = {"bkwd": 0, "fwd": 1, "top": 2} test_ws_name = "MUSR62260; Group; fwd" expected_axis = 1 axis = self.model._get_workspace_plot_axis(test_ws_name) self.assertEqual(axis, expected_axis) def test_get_workspace_plot_axis_handles_bad_input_workspace_name(self): self.model._is_tiled = True self.model._tiled_by = "Group/Pair" self.model._axes_workspace_map = {"bkwd": 0, "fwd": 1, "top": 2} test_ws_name = "MUSR62260; Group; bottom" expected_axis = 0 axis = self.model._get_workspace_plot_axis(test_ws_name) self.assertEqual(axis, expected_axis) def test_create_workspace_label_returns_expected_label_for_run_workspace( self): run_workspace_name = 'MUSR62260; Group; bottom; Asymmetry; MA' self.model._is_tiled = False expected_label = 'MUSR62260;bottom' label = self.model._create_workspace_label(run_workspace_name, 0) self.assertEqual(label, expected_label) def test_create_workspace_label_returns_expected_label_for_fit_workspace( self): fit_workspace_name = 'MUSR62260; Group; bottom; Asymmetry; MA; Fitted; GausOsc; Workspace' self.model._is_tiled = False expected_calc_label = 'MUSR62260;bottom;GausOsc;Calc' expected_diff_label = 'MUSR62260;bottom;GausOsc;Diff' label_calc = self.model._create_workspace_label(fit_workspace_name, 1) label_diff = self.model._create_workspace_label(fit_workspace_name, 2) self.assertEqual(label_calc, expected_calc_label) self.assertEqual(label_diff, expected_diff_label) def test_create_workspace_label_returns_expected_label_tiled_by_group( self): run_workspace_name = 'MUSR62260; Group; bottom; Asymmetry; MA' self.model._is_tiled = True self.model._tiled_by = "Group/Pair" expected_label = '62260' label = self.model._create_workspace_label(run_workspace_name, 0) self.assertEqual(label, expected_label) def test_create_workspace_label_returns_expected_label_tiled_by_run(self): run_workspace_name = 'MUSR62260; Group; bottom; Asymmetry; MA' self.model._is_tiled = True self.model._tiled_by = 'Run' expected_label = 'bottom' label = self.model._create_workspace_label(run_workspace_name, 0) self.assertEqual(label, expected_label)
def setUp(self): self.util = mock.Mock() self.model = PlottingCanvasModel(self.util)