about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-30 15:58:28 +0200
committerhut <hut@lavabit.com>2010-03-30 15:58:28 +0200
commitb4f58d4600fde7c1aceee1e420ccc0c32b46e2bf (patch)
tree3f44d917a517216cbe142b50b83ab363e661c42d /test
parentda114c52ce077b06f9c5a8372e01801e19590a40 (diff)
downloadranger-b4f58d4600fde7c1aceee1e420ccc0c32b46e2bf.tar.gz
added RegexpSignalDispatcher though im not sure if ill use it
Diffstat (limited to 'test')
-rw-r--r--test/tc_signal.py44
1 files changed, 43 insertions, 1 deletions
diff --git a/test/tc_signal.py b/test/tc_signal.py
index 67625505..a585a86b 100644
--- a/test/tc_signal.py
+++ b/test/tc_signal.py
@@ -15,7 +15,7 @@
 
 if __name__ == '__main__': from __init__ import init; init()
 import unittest
-from ranger.ext.signal_dispatcher import SignalDispatcher
+from ranger.ext.signal_dispatcher import *
 
 class TestSignal(unittest.TestCase):
 	def setUp(self):
@@ -75,5 +75,47 @@ class TestSignal(unittest.TestCase):
 		sd.signal_emit('setnumber', number=100)
 		self.assertEqual(None, lst[-1])
 
+	def test_regexp_signals(self):
+		sd = RegexpSignalDispatcher()
+		lst = []
+		def modify(s):
+			s.number = 5
+		def set_number(s):
+			lst.append(s.number)
+		def stopit(s):
+			s.stop()
+
+		h1 = sd.signal_bind_regexp('.*ar', modify, priority=1)
+
+		sd.signal_bind('xyz', set_number)
+		sd.signal_bind('foobar', set_number)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		h2 = sd.signal_bind_regexp('x.z', modify, priority=1)
+#		print(sd._signals)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(5, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		sd.signal_unbind(h2)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(5, lst[-1])
+
+		sd.signal_unbind(h1)
+
+		sd.signal_emit('xyz', number=10)
+		self.assertEqual(10, lst[-1])
+		sd.signal_emit('foobar', number=10)
+		self.assertEqual(10, lst[-1])
+
 if __name__ == '__main__':
 	unittest.main()