twisted.trial.unittest.PyUnitResultAdapter

Here are the examples of the python api twisted.trial.unittest.PyUnitResultAdapter taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

Example 1

Project: mythbox Source File: test_pyunitcompat.py
    def test_tracebackFromFailure(self):
        """
        Errors added through the L{PyUnitResultAdapter} have the same traceback
        information as if there were no adapter at all.
        """
        try:
            1/0
        except ZeroDivisionError:
            exc_info = sys.exc_info()
            f = Failure()
        pyresult = pyunit.TestResult()
        result = PyUnitResultAdapter(pyresult)
        result.addError(self, f)
        self.assertEqual(pyresult.errors[0][1],
                         ''.join(traceback.format_exception(*exc_info)))

Example 2

Project: mythbox Source File: test_pyunitcompat.py
    def test_tracebackFromCleanFailure(self):
        """
        Errors added through the L{PyUnitResultAdapter} have the same
        traceback information as if there were no adapter at all, even
        if the Failure that held the information has been cleaned.
        """
        try:
            1/0
        except ZeroDivisionError:
            exc_info = sys.exc_info()
            f = Failure()
        f.cleanFailure()
        pyresult = pyunit.TestResult()
        result = PyUnitResultAdapter(pyresult)
        result.addError(self, f)
        self.assertEqual(pyresult.errors[0][1],
                         ''.join(traceback.format_exception(*exc_info)))

Example 3

Project: Piped Source File: statustest.py
    @defer.inlineCallbacks
    def run(self, namespace, result):
        """
        Run the test case, storing the results in C{result}.

        First runs C{setUp} on self, then runs the test method (defined in the
        constructor), then runs C{tearDown}. Any of these may return
        L{Deferred}s. After they complete, does some reactor cleanup.

        @param result: A L{TestResult} object.
        """
        # Difference from unittest.TestCase: we run in an asynchronous environment, so we yield instead of _wait
        #   We also inject the namespace as keyword arguments to the setUp method,
        #   and don't collect warnings.
        setattr(self, 'setUp', _MethodWrapper(getattr(self, 'setUp'), namespace))

        new_result = itrial.IReporter(result, None)
        if new_result is None:
            result = unittest.PyUnitResultAdapter(result)
        else:
            result = new_result
        self._timedOut = False
        result.startTest(self)
        if self.getSkip(): # don't run test methods that are marked as .skip
            result.addSkip(self, self.getSkip())
            result.stopTest(self)
            return
        self._observer = unittest._logObserver

        @defer.inlineCallbacks
        def runThunk():
            self._passed = False
            self._deprecateReactor(reactor)
            try:
                d = self.deferSetUp(None, result)
                try:
                    yield d
                finally:
                    self._cleanUp(result)
                    self._classCleanUp(result)
            finally:
                self._undeprecateReactor(reactor)

        yield runThunk()

        result.stopTest(self)