コード例 #1
0
 def _callProcessExited(self, reason):
     default = object()
     processExited = getattr(self.proto, 'processExited', default)
     if processExited is default:
         getWarningMethod()(
             _missingProcessExited % (qual(self.proto.__class__),),
             DeprecationWarning, stacklevel=0)
     else:
         processExited(Failure(reason))
コード例 #2
0
    def test_callProcessExitedMissing(self):
        """
        L{BaseProcess._callProcessExited} emits a L{DeprecationWarning} if the
        object referred to by its C{proto} attribute has no C{processExited}
        method.
        """
        class FakeProto:
            pass

        reason = object()
        process = BaseProcess(FakeProto())

        self.addCleanup(setWarningMethod, getWarningMethod())
        warnings = []
        def collect(message, category, stacklevel):
            warnings.append((message, category, stacklevel))
        setWarningMethod(collect)

        process._callProcessExited(reason)

        [(message, category, stacklevel)] = warnings
        self.assertEqual(
            message,
            "Since Twisted 8.2, IProcessProtocol.processExited is required.  "
            "%s.%s must implement it." % (
                FakeProto.__module__, FakeProto.__name__))
        self.assertIdentical(category, DeprecationWarning)
        # The stacklevel doesn't really make sense for this kind of
        # deprecation.  Requiring it to be 0 will at least avoid pointing to
        # any part of Twisted or a random part of the application's code, which
        # I think would be more misleading than having it point inside the
        # warning system itself. -exarkun
        self.assertEqual(stacklevel, 0)
コード例 #3
0
    def test_callProcessExitedMissing(self):
        """
        L{BaseProcess._callProcessExited} emits a L{DeprecationWarning} if the
        object referred to by its C{proto} attribute has no C{processExited}
        method.
        """
        class FakeProto:
            pass

        reason = object()
        process = BaseProcess(FakeProto())

        self.addCleanup(setWarningMethod, getWarningMethod())
        warnings = []

        def collect(message, category, stacklevel):
            warnings.append((message, category, stacklevel))

        setWarningMethod(collect)

        process._callProcessExited(reason)

        [(message, category, stacklevel)] = warnings
        self.assertEqual(
            message,
            "Since Twisted 8.2, IProcessProtocol.processExited is required.  "
            "%s.%s must implement it." %
            (FakeProto.__module__, FakeProto.__name__))
        self.assertIdentical(category, DeprecationWarning)
        # The stacklevel doesn't really make sense for this kind of
        # deprecation.  Requiring it to be 0 will at least avoid pointing to
        # any part of Twisted or a random part of the application's code, which
        # I think would be more misleading than having it point inside the
        # warning system itself. -exarkun
        self.assertEqual(stacklevel, 0)