1
# Copyright (c) 2008 Divmod. See LICENSE for details.
4
Tests for L{epsilon.process}.
7
from zope.interface.verify import verifyObject
9
from twisted.trial.unittest import TestCase
10
from twisted.application.service import IService, MultiService
11
from twisted.internet.protocol import Protocol
13
from epsilon import process
16
class StandardIOServiceTests(TestCase):
18
Tests for L{StandardIOService}, an L{IService} implementation which
19
associates a L{IProtocol} provider with stdin and stdout when it is
22
def test_interface(self):
24
L{StandardIOService} instances provide L{IService}.
26
verifyObject(IService, process.StandardIOService(None))
29
def test_startService(self):
31
L{StandardIOService.startService} connects a protocol to a standard io
34
# This sucks. StandardIO sucks. APIs should be testable.
36
self.patch(process, 'StandardIO', L.append)
38
service = process.StandardIOService(proto)
39
service.startService()
40
self.assertEqual(L, [proto])
43
def test_setName(self):
45
L{StandardIOService.setName} sets the C{name} attribute.
47
service = process.StandardIOService(None)
48
service.setName("foo")
49
self.assertEqual(service.name, "foo")
52
def test_setServiceParent(self):
54
L{StandardIOService.setServiceParent} sets the C{parent} attribute and
55
adds the service as a child of the given parent.
57
parent = MultiService()
58
service = process.StandardIOService(None)
59
service.setServiceParent(parent)
60
self.assertEqual(list(parent), [service])
61
self.assertIdentical(service.parent, parent)
64
def test_disownServiceParent(self):
66
L{StandardIOService.disownServiceParent} sets the C{parent} attribute
67
to C{None} and removes the service from the parent's child list.
69
parent = MultiService()
70
service = process.StandardIOService(None)
71
service.setServiceParent(parent)
72
service.disownServiceParent()
73
self.assertEqual(list(parent), [])
74
self.assertIdentical(service.parent, None)