Ejemplo n.º 1
0
    def _run(self, suppress, todo, method, result):
        """
        Run a single method, either a test method or fixture.

        @param suppress: Any warnings to suppress, as defined by the C{suppress}
            attribute on this method, test case, or the module it is defined in.

        @param todo: Any expected failure or failures, as defined by the C{todo}
            attribute on this method, test case, or the module it is defined in.

        @param method: The method to run.

        @param result: The TestResult instance to which to report results.

        @return: C{True} if the method fails and no further method/fixture calls
            should be made, C{False} otherwise.
        """
        try:
            runWithWarningsSuppressed(suppress, method)
        except SkipTest as e:
            result.addSkip(self, self._getSkipReason(method, e))
        except:
            reason = failure.Failure()
            if todo is None or not todo.expected(reason):
                if reason.check(self.failureException):
                    addResult = result.addFailure
                else:
                    addResult = result.addError
                addResult(self, reason)
            else:
                result.addExpectedFailure(self, reason, todo)
        else:
            return False
        return True
Ejemplo n.º 2
0
    def _run(self, suppress, todo, method, result):
        """
        Run a single method, either a test method or fixture.

        @param suppress: Any warnings to suppress, as defined by the C{suppress}
            attribute on this method, test case, or the module it is defined in.

        @param todo: Any expected failure or failures, as defined by the C{todo}
            attribute on this method, test case, or the module it is defined in.

        @param method: The method to run.

        @param result: The TestResult instance to which to report results.

        @return: C{True} if the method fails and no further method/fixture calls
            should be made, C{False} otherwise.
        """
        try:
            runWithWarningsSuppressed(suppress, method)
        except SkipTest as e:
            result.addSkip(self, self._getSkipReason(method, e))
        except:
            reason = failure.Failure()
            if todo is None or not todo.expected(reason):
                if reason.check(self.failureException):
                    addResult = result.addFailure
                else:
                    addResult = result.addError
                addResult(self, reason)
            else:
                result.addExpectedFailure(self, reason, todo)
        else:
            return False
        return True
Ejemplo n.º 3
0
def deprecatedDeferredGenerator(f):
    """
    Calls L{deferredGenerator} while suppressing the deprecation warning.

    @param f: Function to call
    @return: Return value of function.
    """
    return runWithWarningsSuppressed(
        [ SUPPRESS(message="twisted.internet.defer.deferredGenerator was "
                          "deprecated") ],
        deferredGenerator, f)
Ejemplo n.º 4
0
def deprecatedDeferredGenerator(f):
    """
    Calls L{deferredGenerator} while suppressing the deprecation warning.

    @param f: Function to call
    @return: Return value of function.
    """
    return runWithWarningsSuppressed([
        SUPPRESS(message="twisted.internet.defer.deferredGenerator was "
                 "deprecated")
    ], deferredGenerator, f)
Ejemplo n.º 5
0
Archivo: detests.py Proyecto: DT021/wau
class DeferredTests(unittest.TestCase):
    touched = False

    def _cb_fail(self, reason):
        self.fail(reason)

    def _cb_error(self, reason):
        raise RuntimeError(reason)

    def _cb_skip(self, reason):
        raise unittest.SkipTest(reason)

    def _touchClass(self, ignored):
        self.__class__.touched = True

    def setUp(self):
        self.__class__.touched = False

    def test_pass(self):
        return defer.succeed('success')

    def test_passGenerated(self):
        self._touchClass(None)
        yield None
    test_passGenerated = runWithWarningsSuppressed(
        [ SUPPRESS(message="twisted.internet.defer.deferredGenerator was "
                          "deprecated") ],
        defer.deferredGenerator, test_passGenerated)


    @defer.inlineCallbacks
    def test_passInlineCallbacks(self):
        """
        Test case that is decorated with L{defer.inlineCallbacks}.
        """
        self._touchClass(None)
        yield None

    def test_fail(self):
        return defer.fail(self.failureException('I fail'))

    def test_failureInCallback(self):
        d = defer.succeed('fail')
        d.addCallback(self._cb_fail)
        return d

    def test_errorInCallback(self):
        d = defer.succeed('error')
        d.addCallback(self._cb_error)
        return d

    def test_skip(self):
        d = defer.succeed('skip')
        d.addCallback(self._cb_skip)
        d.addCallback(self._touchClass)
        return d

    def test_thread(self):
        return threads.deferToThread(lambda : None)

    def test_expectedFailure(self):
        d = defer.succeed('todo')
        d.addCallback(self._cb_error)
        return d
    test_expectedFailure.todo = "Expected failure"