1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Tests for L{twisted.manhole.explorer}.
8 from twisted.trial import unittest
9 from twisted.manhole.explorer import (
23 class PoolTestCase(unittest.TestCase):
25 Tests for the Pool class.
28 def test_instanceBuilding(self):
30 If the object is not in the pool a new instance is created and
34 e = p.getExplorer(123, 'id')
35 self.assertIsInstance(e, ExplorerImmutable)
36 self.assertEqual(e.value, 123)
37 self.assertEqual(e.identifier, 'id')
41 class CRUFTWatchyThingieTestCase(unittest.TestCase):
43 Tests for the CRUFT_WatchyThingie class.
45 def test_watchObjectConstructedClass(self):
47 L{CRUFT_WatchyThingie.watchObject} changes the class of its
48 first argument to a custom watching class.
51 cwt = CRUFT_WatchyThingie()
52 cwt.watchObject(foo, 'id', 'cback')
54 # check new constructed class
55 newClassName = foo.__class__.__name__
56 self.assertEqual(newClassName, "WatchingFoo%X" % (id(foo),))
59 def test_watchObjectConstructedInstanceMethod(self):
61 L{CRUFT_WatchyThingie.watchingfoo} adds a C{_watchEmitChanged}
62 attribute which refers to a bound method on the instance
66 cwt = CRUFT_WatchyThingie()
67 cwt.watchObject(foo, 'id', 'cback')
69 # check new constructed instance method
70 self.assertIdentical(foo._watchEmitChanged.im_self, foo)
74 class WatchMonkeyTestCase(unittest.TestCase):
76 Tests for the _WatchMonkey class.
78 def test_install(self):
80 When _WatchMonkey is installed on a method, calling that
81 method calls the _WatchMonkey.
93 wm = _WatchMonkey(foo)
94 wm.install('someMethod')
96 # patch wm's method to check that the method was exchanged
98 wm.__call__ = lambda s: called.append(True)
102 self.assertTrue(called)