2020-04-05 14:36:06 +00:00
|
|
|
#!/usr/bin/env python
|
2015-06-23 00:34:24 +00:00
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
2020-05-01 14:36:16 +00:00
|
|
|
"""test_signalman.py - Test the signalman class
|
2015-06-23 00:34:24 +00:00
|
|
|
|
|
|
|
>>> widget = TestWidget()
|
|
|
|
>>> signalman = Signalman()
|
|
|
|
>>> signalman.new(widget, 'test1', handler)
|
|
|
|
1
|
2020-05-01 15:38:34 +00:00
|
|
|
>>> list(signalman.cnxids[widget].keys())
|
|
|
|
['test1']
|
|
|
|
>>> list(widget.signals.values())
|
|
|
|
['test1']
|
2015-06-23 00:34:24 +00:00
|
|
|
>>> signalman.remove_widget(widget)
|
2020-04-06 12:11:06 +00:00
|
|
|
>>> widget in signalman.cnxids
|
2015-06-23 00:34:24 +00:00
|
|
|
False
|
2020-05-01 15:38:34 +00:00
|
|
|
>>> list(widget.signals.values())
|
|
|
|
[]
|
2015-06-23 00:34:24 +00:00
|
|
|
>>> signalman.new(widget, 'test2', handler)
|
|
|
|
2
|
|
|
|
>>> signalman.new(widget, 'test3', handler)
|
|
|
|
3
|
|
|
|
>>> signalman.remove_signal(widget, 'test2')
|
2020-05-01 15:38:34 +00:00
|
|
|
>>> list(signalman.cnxids[widget].keys())
|
|
|
|
['test3']
|
|
|
|
>>> list(widget.signals.values())
|
|
|
|
['test3']
|
2015-06-23 00:34:24 +00:00
|
|
|
>>> signalman.remove_widget(widget)
|
|
|
|
>>>
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys, os.path
|
|
|
|
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
|
|
|
|
from terminatorlib.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():
|
2018-04-24 18:22:10 +00:00
|
|
|
print("I am a test handler")
|
2015-06-23 00:34:24 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
import doctest
|
|
|
|
(failed, attempted) = doctest.testmod()
|
2018-04-24 18:22:10 +00:00
|
|
|
print("%d/%d tests failed" % (failed, attempted))
|
2015-06-23 00:34:24 +00:00
|
|
|
sys.exit(failed)
|