def __init__(self, parent=None): view = QuickEditView(None, parent) self._presenter = QuickEditPresenter(view)
def setUp(self): self.view = mock.create_autospec(QuickEditView) self.pres = QuickEditPresenter(self.view) self.slot = mock.Mock()
class QuickEditWidget(object): def __init__(self, parent=None): view = QuickEditView(None, parent) self._presenter = QuickEditPresenter(view) @property def widget(self): return self._presenter.widget """ connect statements""" def connect_autoscale_changed(self, slot): self._presenter.connect_autoscale_changed(slot) def connect_errors_changed(self, slot): self._presenter.connect_errors_changed(slot) def connect_x_range_changed(self, slot): self._presenter.connect_x_range_changed(slot) def connect_y_range_changed(self, slot): self._presenter.connect_y_range_changed(slot) def connect_plot_selection(self, slot): self._presenter.connect_plot_selection(slot) # add subplot def add_subplot(self, name): self._presenter.add_subplot(name) def rm_subplot(self, name): self._presenter.rm_subplot(name) def get_subplots(self): return self._presenter.all() def get_selection(self): name = self._presenter.widget.current_selection() if name == "All": return self.get_subplots() return [name] def set_plot_x_range(self, range): self._presenter.set_plot_x_range(range) def set_plot_y_range(self, y_range): self._presenter.set_plot_y_range(y_range) def set_errors(self, state): self._presenter.set_errors(state) def set_mock(self, mock_presenter): self._presenter = mock_presenter
def __init__(self, parent=None): view = QuickEditView(None, parent) self._presenter = QuickEditPresenter(view)
class QuickEditPresenterTest(unittest.TestCase): def setUp(self): self.view = mock.create_autospec(QuickEditView) self.pres = QuickEditPresenter(self.view) self.slot = mock.Mock() def test_add_subplot(self): name = "new plot" self.pres.add_subplot(name) self.assertEqual(self.view.add_subplot.call_count, 1) self.assertEqual(self.view.find_index.call_count, 1) self.assertEqual(self.view.set_index.call_count, 1) def test_connect_autoscale(self): self.pres.connect_autoscale_changed(self.slot) self.view.connect_autoscale_changed.assert_called_with(self.slot) def test_connect_errors(self): self.pres.connect_errors_changed(self.slot) self.view.connect_errors_changed.assert_called_with(self.slot) def test_connect_x_range(self): self.pres.connect_x_range_changed(self.slot) self.view.connect_x_range_changed.assert_called_with(self.slot) def test_connect_y_range(self): self.pres.connect_y_range_changed(self.slot) self.view.connect_y_range_changed.assert_called_with(self.slot) def test_connect_plot_selection(self): self.pres.connect_plot_selection(self.slot) self.view.connect_plot_selection.assert_called_with(self.slot) def test_all(self): names = ["all", "one", "two"] def plots(index): return names[index] self.view.number_of_plots = mock.MagicMock(return_value=len(names)) self.view.plot_at_index = mock.MagicMock(side_effect=plots) output = self.pres.all() # should miss out all for k in range(len(output)): self.assertEqual(names[k + 1], output[k]) def test_set_plot_x_range(self): self.pres.set_plot_x_range([0, 1]) self.view.set_plot_x_range.assert_called_with([0, 1]) def test_set_plot_y_range(self): self.pres.set_plot_y_range([0, 1]) self.view.set_plot_y_range.assert_called_with([0, 1]) def test_set_errors_TT(self): self.view.get_errors = mock.MagicMock(return_value=True) self.pres.set_errors(True) self.assertEqual(self.view.set_errors.call_count, 0) def test_set_errors_TF(self): self.view.get_errors = mock.MagicMock(return_value=True) self.pres.set_errors(False) self.assertEqual(self.view.set_errors.call_count, 1) self.view.set_errors.assert_called_with(False) def test_set_errors_FT(self): self.view.get_errors = mock.MagicMock(return_value=False) self.pres.set_errors(True) self.assertEqual(self.view.set_errors.call_count, 1) self.view.set_errors.assert_called_with(True) def test_set_errors_FF(self): self.view.get_errors = mock.MagicMock(return_value=False) self.pres.set_errors(False) self.assertEqual(self.view.set_errors.call_count, 0) def test_rmSubplot(self): self.pres.rm_subplot("test") self.assertEqual(self.view.rm_subplot.call_count, 1) self.assertEqual(self.view.find_index.call_count, 2) self.assertEqual(self.view.set_index.call_count, 1)
class QuickEditWidget(object): def __init__(self, parent=None): view = QuickEditView(None, parent) self._presenter = QuickEditPresenter(view) @property def widget(self): return self._presenter.widget """ connect statements""" def connect_autoscale_changed(self, slot): self._presenter.connect_autoscale_changed(slot) def connect_errors_changed(self, slot): self._presenter.connect_errors_changed(slot) def connect_x_range_changed(self, slot): self._presenter.connect_x_range_changed(slot) def connect_y_range_changed(self, slot): self._presenter.connect_y_range_changed(slot) def connect_plot_selection(self, slot): self._presenter.connect_plot_selection(slot) # add subplot def add_subplot(self, name): self._presenter.add_subplot(name) def rm_subplot(self,name): self._presenter.rm_subplot(name) def get_selection(self): name = self._presenter.widget.current_selection() if name == "All": return self._presenter.all() return [name] def set_plot_x_range(self, range): self._presenter.set_plot_x_range(range) def set_plot_y_range(self, y_range): self._presenter.set_plot_y_range(y_range) def set_errors(self, state): self._presenter.set_errors(state) def set_mock(self,mock_presenter): self._presenter = mock_presenter
def __init__(self, parent=None, auto_btn=False): view = QuickEditView(None, parent, auto_btn) self._presenter = QuickEditPresenter(view)
class QuickEditWidget(object): def __init__(self, parent=None, auto_btn=False): view = QuickEditView(None, parent, auto_btn) self._presenter = QuickEditPresenter(view) @property def widget(self): return self._presenter.widget @property def autoscale(self): return self._presenter.autoscale def disable_yaxis_changer(self): self._presenter.disable_yaxis_changer() def enable_yaxis_changer(self): self._presenter.enable_yaxis_changer() def disable_autoscale(self): self._presenter.disable_autoscale() def enable_autoscale(self): self._presenter.enable_autoscale() def uncheck_autoscale(self): self._presenter.uncheck_autoscale() """ connect statements""" def connect_autoscale_changed(self, slot): self._presenter.connect_autoscale_changed(slot) def connect_errors_changed(self, slot): self._presenter.connect_errors_changed(slot) def connect_x_range_changed(self, slot): self._presenter.connect_x_range_changed(slot) def connect_y_range_changed(self, slot): self._presenter.connect_y_range_changed(slot) def connect_plot_selection(self, slot): self._presenter.connect_plot_selection(slot) def add_subplot(self, name): self._presenter.add_subplot(name) def rm_subplot(self, name): self._presenter.rm_subplot(name) def clear_subplots(self): self._presenter.clear_subplots() def get_subplots(self): return self._presenter.all() def get_selection(self): name = self._presenter.widget.current_selection() if name == "All": return self.get_subplots() return [name] def set_plot_x_range(self, range): self._presenter.set_plot_x_range(range) def set_plot_y_range(self, y_range): self._presenter.set_plot_y_range(y_range) def get_plot_x_range(self): return self._presenter.get_plot_x_range() def get_plot_y_range(self): return self._presenter.get_plot_y_range() def set_errors(self, state): self._presenter.set_errors(state) def get_errors(self): return self._presenter.get_errors() def set_mock(self, mock_presenter): self._presenter = mock_presenter
def setUp(self): self.view = mock.create_autospec(QuickEditView) self.pres = QuickEditPresenter(self.view) self.slot = mock.Mock()
class QuickEditPresenterTest(unittest.TestCase): def setUp(self): self.view = mock.create_autospec(QuickEditView) self.pres = QuickEditPresenter(self.view) self.slot = mock.Mock() def test_add_subplot(self): name = "new plot" self.pres.add_subplot(name) self.assertEquals(self.view.add_subplot.call_count, 1) self.assertEquals(self.view.find_index.call_count, 1) self.assertEquals(self.view.set_index.call_count, 1) def test_connect_autoscale(self): self.pres.connect_autoscale_changed(self.slot) self.view.connect_autoscale_changed.assert_called_with(self.slot) def test_connect_errors(self): self.pres.connect_errors_changed(self.slot) self.view.connect_errors_changed.assert_called_with(self.slot) def test_connect_x_range(self): self.pres.connect_x_range_changed(self.slot) self.view.connect_x_range_changed.assert_called_with(self.slot) def test_connect_y_range(self): self.pres.connect_y_range_changed(self.slot) self.view.connect_y_range_changed.assert_called_with(self.slot) def test_connect_plot_selection(self): self.pres.connect_plot_selection(self.slot) self.view.connect_plot_selection.assert_called_with(self.slot) def test_all(self): names = ["all","one","two"] def plots(index): return names[index] self.view.number_of_plots = mock.MagicMock(return_value = len(names)) self.view.plot_at_index = mock.MagicMock(side_effect = plots) output = self.pres.all() # should miss out all for k in range(len(output)): self.assertEquals(names[k+1], output[k]) def test_set_plot_x_range(self): self.pres.set_plot_x_range([0,1]) self.view.set_plot_x_range.assert_called_with([0,1]) def test_set_plot_y_range(self): self.pres.set_plot_y_range([0,1]) self.view.set_plot_y_range.assert_called_with([0,1]) def test_set_errors_TT(self): self.view.get_errors = mock.MagicMock(return_value = True) self.pres.set_errors(True) self.assertEquals(self.view.set_errors.call_count,0) def test_set_errors_TF(self): self.view.get_errors = mock.MagicMock(return_value = True) self.pres.set_errors(False) self.assertEquals(self.view.set_errors.call_count,1) self.view.set_errors.assert_called_with(False) def test_set_errors_FT(self): self.view.get_errors = mock.MagicMock(return_value = False) self.pres.set_errors(True) self.assertEquals(self.view.set_errors.call_count,1) self.view.set_errors.assert_called_with(True) def test_set_errors_FF(self): self.view.get_errors = mock.MagicMock(return_value = False) self.pres.set_errors(False) self.assertEquals(self.view.set_errors.call_count,0) def test_rmSubplot(self): self.pres.rm_subplot("test") self.assertEquals(self.view.rm_subplot.call_count, 1) self.assertEquals(self.view.find_index.call_count, 2) self.assertEquals(self.view.set_index.call_count, 1)