def testOnPreferences(self): ac = launcher.AppController(self.app) pref_controller_mock = mox.MockObject(launcher.PrefController) pref_controller_mock.ShowModal() mox.Replay(pref_controller_mock) ac.OnPreferences(None, pref_controller_mock) mox.Verify(pref_controller_mock)
def testSettings(self): ac = launcher.AppController(self.app) failures = [0] def failure_accum(a, b): failures[0] += 1 ac._FailureMessage = failure_accum # First make sure we choke if !=1 project is selected for projectlist in ((), (1, 2, 4)): failures = [0] frame_mock = mox.MockObject(launcher.MainFrame) frame_mock.SelectedProjects().AndReturn(projectlist) mox.Replay(frame_mock) ac.SetModelsViews(frame=frame_mock) ac.Settings(self, None) mox.Verify(frame_mock) self.assertEqual(1, failures[0]) # Now test things look fine with 1 project. frame_mock = mox.MockObject(launcher.MainFrame) frame_mock.SelectedProjects().AndReturn((1, )) frame_mock.RefreshView(None) mox.Replay(frame_mock) table_mock = mox.MockObject(launcher.MainTable) table_mock.SaveProjects() table_mock._projects = None mox.Replay(table_mock) ac.SetModelsViews(frame=frame_mock, table=table_mock) controller_mock = mox.MockObject(launcher.SettingsController) controller_mock.ShowModal().AndReturn(wx.ID_OK) mox.Replay(controller_mock) ac.Settings(None, settings_controller=controller_mock) mox.Verify(frame_mock) mox.Verify(table_mock) mox.Verify(controller_mock)
def testRemove(self): """Test Remove with both single and multiple projects.""" # Simulate with both positive and negative responses. # These functions will replace launcher.Controller_ConfirmRemove(). confirm_functions = (lambda a, b: True, lambda a, b: False) for confirm_function in confirm_functions: plists = (self.Projects(1), self.Projects(4)) for projectlist in plists: frame_mock = mox.MockObject(launcher.MainFrame) frame_mock.SelectedProjects().AndReturn(projectlist) table_mock = mox.MockObject(launcher.MainTable) table_mock._projects = None # Only if _ConfirmRemove() will return True do we tell our # mock to expect deletes to happen (RemoveProject() calls). if confirm_function(0, 0): for p in projectlist: table_mock.RemoveProject(p).InAnyOrder() frame_mock.UnselectAll() frame_mock.RefreshView(None) mox.Replay(frame_mock) mox.Replay(table_mock) controller = launcher.AppController(self.app) controller._ConfirmRemove = confirm_function controller.SetModelsViews(frame=frame_mock, table=table_mock) controller.Remove(None) mox.Verify(frame_mock)
def testOnAbout(self): # I tried to combine this with the above and a parameterized # helper, but (with extra doc et al) it ended up being larger and # just increasing complexity. ac = launcher.AppController(self.app) ab_controller_mock = mox.MockObject(launcher.AboutBoxController) ab_controller_mock.ShowModal() mox.Replay(ab_controller_mock) ac.OnAbout(None, ab_controller_mock) mox.Verify(ab_controller_mock)
def setUp(self): # Must always create a wx.App first self.app = wx.PySimpleApp() ac = launcher.AppController(self.app) self.frame = launcher.MainFrame(None, -1, launcher.MainTable(), None, ac, None) # Make the fake table and list control for selecton tests. fake_table = MainFrameTest.FakeTable() fake_listctrl = MainFrameTest.FakeListCtrl(wx.Frame(None, -1)) self.frame._table = fake_table self.frame._listctrl = fake_listctrl
def testInitAndConfigure(self): c = launcher.AppController(self.app) self.assertFalse(c._frame) self.assertFalse(c._table) table = 1 frame = 2 c.SetModelsViews(frame=frame, table=None) self.assertTrue(c._frame == frame) c.SetModelsViews(frame=None, table=table) self.assertTrue(c._table == table) c.SetModelsViews(frame=table, table=frame) self.assertTrue(c._frame == table) self.assertTrue(c._table == frame)
def setUp(self): # Must always create a wx.App first self.app = wx.PySimpleApp() ac = launcher.AppController(self.app)
def _CreateControllers(self): """Create controllers (MVC) for this application.""" self._app_controller = launcher.AppController(self) self._task_controller = launcher.TaskController(self._app_controller)