2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
from twisted.trial import unittest
7
from twisted.manhole import service
8
from twisted.spread.util import LocalAsRemote
15
return 'INET', '127.0.0.1', 0
17
class DummyManholeClient(LocalAsRemote):
20
broker.transport = DummyTransport()
25
def console(self, messages):
26
self.messages.extend(messages)
28
def receiveExplorer(self, xplorer):
32
self.zero = len(self.messages)
34
def getMessages(self):
35
return self.messages[self.zero:]
38
sync_console = console
39
sync_receiveExplorer = receiveExplorer
40
sync_setZero = setZero
41
sync_getMessages = getMessages
43
class ManholeTest(unittest.TestCase):
44
"""Various tests for the manhole service.
46
Both the the importIdentity and importMain tests are known to fail
47
when the __name__ in the manhole namespace is set to certain
51
self.service = service.Service()
52
self.p = service.Perspective(self.service)
53
self.client = DummyManholeClient()
54
self.p.attached(self.client, None)
56
def test_importIdentity(self):
57
"""Making sure imported module is the same as one previously loaded.
59
self.p.perspective_do("from twisted.manhole import service")
61
self.p.perspective_do("int(service is sys.modules['twisted.manhole.service'])")
62
msg = self.client.getMessages()[0]
63
self.failUnlessEqual(msg, ('result',"1\n"))
65
def test_importMain(self):
66
"""Trying to import __main__"""
68
self.p.perspective_do("import __main__")
69
if self.client.getMessages():
70
msg = self.client.getMessages()[0]
71
if msg[0] in ("exception","stderr"):
74
#if __name__=='__main__':