~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/test/test_manhole.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
 
 
6
from twisted.trial import unittest
 
7
from twisted.manhole import service
 
8
from twisted.spread.util import LocalAsRemote
 
9
 
 
10
class Dummy:
 
11
    pass
 
12
 
 
13
class DummyTransport:
 
14
    def getHost(self):
 
15
        return 'INET', '127.0.0.1', 0
 
16
 
 
17
class DummyManholeClient(LocalAsRemote):
 
18
    zero = 0
 
19
    broker = Dummy()
 
20
    broker.transport = DummyTransport()
 
21
 
 
22
    def __init__(self):
 
23
        self.messages = []
 
24
 
 
25
    def console(self, messages):
 
26
        self.messages.extend(messages)
 
27
 
 
28
    def receiveExplorer(self, xplorer):
 
29
        pass
 
30
 
 
31
    def setZero(self):
 
32
        self.zero = len(self.messages)
 
33
 
 
34
    def getMessages(self):
 
35
        return self.messages[self.zero:]
 
36
 
 
37
    # local interface
 
38
    sync_console = console
 
39
    sync_receiveExplorer = receiveExplorer
 
40
    sync_setZero = setZero
 
41
    sync_getMessages = getMessages
 
42
 
 
43
class ManholeTest(unittest.TestCase):
 
44
    """Various tests for the manhole service.
 
45
 
 
46
    Both the the importIdentity and importMain tests are known to fail
 
47
    when the __name__ in the manhole namespace is set to certain
 
48
    values.
 
49
    """
 
50
    def setUp(self):
 
51
        self.service = service.Service()
 
52
        self.p = service.Perspective(self.service)
 
53
        self.client = DummyManholeClient()
 
54
        self.p.attached(self.client, None)
 
55
 
 
56
    def test_importIdentity(self):
 
57
        """Making sure imported module is the same as one previously loaded.
 
58
        """
 
59
        self.p.perspective_do("from twisted.manhole import service")
 
60
        self.client.setZero()
 
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"))
 
64
 
 
65
    def test_importMain(self):
 
66
        """Trying to import __main__"""
 
67
        self.client.setZero()
 
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"):
 
72
                self.fail(msg[1])
 
73
 
 
74
#if __name__=='__main__':
 
75
#    unittest.main()