terminator/terminatorlib/tests/testsignalman.py
2010-01-18 13:21:03 +00:00

57 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python
# Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only
"""testsignalman.py - Test the signalman class
>>> widget = TestWidget()
>>> signalman = Signalman()
>>> signalman.new(widget, 'test1', handler)
>>> signalman.cnxids[widget].keys()
['test1']
>>> widget.signals.values()
['test1']
>>> signalman.remove_widget(widget)
>>> signalman.cnxids.has_key(widget)
False
>>> widget.signals.values()
[]
>>> signalman.new(widget, 'test2', handler)
>>> signalman.new(widget, 'test3', handler)
>>> signalman.remove_signal(widget, 'test2')
>>> signalman.cnxids[widget].keys()
['test3']
>>> widget.signals.values()
['test3']
>>> signalman.remove_widget(widget)
>>>
"""
from ..signalman import Signalman
class TestWidget():
signals = None
count = None
def __init__(self):
self.signals = {}
self.count = 0
def connect(self, signal, handler, *args):
self.count = self.count + 1
self.signals[self.count] = signal
return(self.count)
def disconnect(self, signalid):
del(self.signals[signalid])
def handler():
print "I am a test handler"
if __name__ == '__main__':
import sys
import doctest
(failed, attempted) = doctest.testmod()
print "%d/%d tests failed" % (failed, attempted)
sys.exit(failed)