1
# Copyright (c) 2008 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Tests for L{twisted.internet._baseprocess} which implements process-related
6
functionality that is useful in all platforms supporting L{IReactorProcess}.
11
from twisted.python.deprecate import getWarningMethod, setWarningMethod
12
from twisted.trial.unittest import TestCase
13
from twisted.internet._baseprocess import BaseProcess
16
class BaseProcessTests(TestCase):
18
Tests for L{BaseProcess}, a parent class for other classes which represent
19
processes which implements functionality common to many different process
22
def test_callProcessExited(self):
24
L{BaseProcess._callProcessExited} calls the C{processExited} method of
25
its C{proto} attribute and passes it a L{Failure} wrapping the given
31
def processExited(self, reason):
34
reason = RuntimeError("fake reason")
35
process = BaseProcess(FakeProto())
36
process._callProcessExited(reason)
37
process.proto.reason.trap(RuntimeError)
38
self.assertIdentical(reason, process.proto.reason.value)
41
def test_callProcessExitedMissing(self):
43
L{BaseProcess._callProcessExited} emits a L{DeprecationWarning} if the
44
object referred to by its C{proto} attribute has no C{processExited}
51
process = BaseProcess(FakeProto())
53
self.addCleanup(setWarningMethod, getWarningMethod())
55
def collect(message, category, stacklevel):
56
warnings.append((message, category, stacklevel))
57
setWarningMethod(collect)
59
process._callProcessExited(reason)
61
[(message, category, stacklevel)] = warnings
64
"Since Twisted 8.2, IProcessProtocol.processExited is required. "
65
"%s.%s must implement it." % (
66
FakeProto.__module__, FakeProto.__name__))
67
self.assertIdentical(category, DeprecationWarning)
68
# The stacklevel doesn't really make sense for this kind of
69
# deprecation. Requiring it to be 0 will at least avoid pointing to
70
# any part of Twisted or a random part of the application's code, which
71
# I think would be more misleading than having it point inside the
72
# warning system itself. -exarkun
73
self.assertEqual(stacklevel, 0)