Exemple #1
0
    def run(self, test):
        """Overrides to provide plugin hooks and defer all output to
        the test result class.
        """
        #from father class code
        wrapper = self.config.plugins.prepareTest(test)
        if wrapper is not None:
            test = wrapper

        wrapped = self.config.plugins.setOutputStream(self.stream)
        if wrapped is not None:
            self.stream = wrapped

        result = self._makeResult()
        start = time.time()

        runtime = launcher.Runtime(self.config.options.config_file)
        runtime.setup_environment()
        runtime.start_test()
        setattr(test.config, 'runtime', runtime)
        test(result)
        runtime.stop_test()

        #from father class code
        stop = time.time()
        result.printErrors()
        result.printSummary(start, stop)
        self.config.plugins.finalize(result)
        return result
Exemple #2
0
 def testInit(self):
   runtime = launcher.Runtime()
   preferences = launcher.Preferences()
   projects = ['hi', 'mom']
   dialog = auth_dialog.AuthDialog(None)
   d = launcher.DeployController(runtime, preferences, projects, dialog)
   self.assertEqual(dialog, d.dialog)
   d = launcher.DeployController(runtime, preferences, projects)
   self.assertTrue(d.dialog)
    def doTestRunStateChanges(self,
                              initial_runstate,
                              end_runstate,
                              attrname,
                              do_selected=True):
        """test calling attrname with both a single and multi-selection of projects.
    Sets initial run state of the projects, and confirms it gets switched to
    end_runstate.

    Args:
      initial_runstate: the initial run state of the Projects
      end_runstate: the end run state of the Projects after the op
      attrname: call this attribute for each project
      do_selected: if True, do mock a SelectedProjects() call.
    """
        plists = (self.Projects(1), self.Projects(4))
        for projectlist in plists:
            for p in projectlist:
                p.runstate = initial_runstate
            tc = launcher.TaskController(FakeAppController())
            tc.SetModelsViews(runtime=launcher.Runtime())
            stateop = getattr(tc, attrname)
            self.assertTrue(callable(stateop))
            # Override thread creation; don't want real tasks running
            tc._CreateTaskThreadForProject = self._CreateTaskThreadForProject
            # Mock out "selected projects" of the frame to return projectlist
            frame_mock = mox.MockObject(launcher.MainFrame)
            if do_selected:
                frame_mock.SelectedProjects().AndReturn(projectlist)
            mox.Replay(frame_mock)
            tc.SetModelsViews(frame=frame_mock)
            # Finally, call the method we are testing, and verify
            stateop(None)
            mox.Verify(frame_mock)
            self.ConfirmThreads(end_runstate)
            # re-run our op and make sure no threads are modified/added/removed
            tmlen = len(self.threads)
            mox.Reset(frame_mock)
            if do_selected:
                frame_mock.SelectedProjects().AndReturn(projectlist)
            mox.Replay(frame_mock)
            stateop(None)
            mox.Verify(frame_mock)
            self.assertEqual(tmlen, len(self.threads))
            self.ConfirmThreads(end_runstate)
Exemple #4
0
 def testTaskThreadForProject(self):
   project = launcher.Project('path', 8000, 'project_name')
   d = launcher.DeployController(launcher.Runtime(), launcher.Preferences(),
                                 [project])
   d._name = 'fred'
   d._password = '******'
   tt = d._TaskThreadForProject(project)
   self.assertFalse(tt.isAlive())
   # confirm stdin works.  Use python so we don't need cygwin.
   # Print out the 'Running application' string so that
   # taskthread will know to transition from WillStart to DidStart.
   script = ('import sys; print "Running application http://x:5"; '
             'print sys.stdin.read().strip()')
   cat_cmd = [sys.executable, '-c', script]
   tt = d._TaskThreadForProject(project, cat_cmd)
   output = ['']
   def collect(line, date=True):
     output[0] += line
   tt.LogOutput = collect
   starting = [0]
   started = [0]
   lock = threading.Lock()
   def _TaskWillStart():
     starting[0] = time.time()
   def _TaskDidStart():
     started[0] = time.time()
   def _TaskDidStop(code):
     lock.release()
   tt._TaskWillStart = _TaskWillStart
   tt._TaskDidStart = _TaskDidStart
   tt._TaskDidStop = _TaskDidStop
   lock.acquire()
   tt.start()
   lock.acquire()  # blocks until _TaskDidStop() releases it
   lock.release()
   self.assertNotEqual(0, starting[0])
   self.assertNotEqual(0, started[0])
   # Make sure the 'started' happens after 'starting'
   self.assertTrue(started > starting)
   self.assertTrue('himom' in output[0])
Exemple #5
0
 def _CreateModels(self):
   """Create models (MVC) for this application."""
   self._table = launcher.MainTable()
   self._preferences = launcher.Preferences()
   self._runtime = launcher.Runtime(preferences=self._preferences)