summary refs log tree commit diff stats
path: root/test/tc_signal.py
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-03-30 04:50:38 +0200
committerhut <hut@lavabit.com>2010-03-30 04:50:38 +0200
commit1c1b6c31de513f0f056a915bf7d8e608c485ae50 (patch)
treeb2dd0153d058cdbcf0c24b033703ab6d7f0efa8e /test/tc_signal.py
parent489a1616407a3d6c588b1890c9ddbf795ae5724f (diff)
downloadranger-1c1b6c31de513f0f056a915bf7d8e608c485ae50.tar.gz
added SignalDispatcher class
Diffstat (limited to 'test/tc_signal.py')
-rw-r--r--test/tc_signal.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/tc_signal.py b/test/tc_signal.py
new file mode 100644
index 00000000..67625505
--- /dev/null
+++ b/test/tc_signal.py
@@ -0,0 +1,79 @@
+# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+if __name__ == '__main__': from __init__ import init; init()
+import unittest
+from ranger.ext.signal_dispatcher import SignalDispatcher
+
+class TestSignal(unittest.TestCase):
+	def setUp(self):
+		self.sd = SignalDispatcher()
+
+	def test_signal_register_emit(self):
+		sd = self.sd
+		def poo(sig):
+			self.assert_('works' in sig)
+			self.assertEqual('yes', sig.works)
+		handler = sd.signal_bind('x', poo)
+
+		sd.signal_emit('x', works='yes')
+		sd.signal_unbind(handler)
+		sd.signal_emit('x')
+
+	def test_signal_order(self):
+		sd = self.sd
+		lst = []
+		def addn(n):
+			return lambda _: lst.append(n)
+
+		sd.signal_bind('x', addn(6))
+		sd.signal_bind('x', addn(3), priority=1)
+		sd.signal_bind('x', addn(2), priority=1)
+		sd.signal_bind('x', addn(9), priority=0)
+		sd.signal_bind('x', addn(1337), priority=0.7)
+		sd.signal_emit('x')
+
+		self.assert_(lst.index(3) < lst.index(6))
+		self.assert_(lst.index(2) < lst.index(6))
+		self.assert_(lst.index(6) < lst.index(9))
+		self.assert_(lst.index(1337) < lst.index(6))
+		self.assert_(lst.index(1337) < lst.index(9))
+		self.assert_(lst.index(1337) > lst.index(2))
+
+	def test_modifying_arguments(self):
+		sd = self.sd
+		lst = []
+		def modify(s):
+			s.number = 5
+		def set_number(s):
+			lst.append(s.number)
+		def stopit(s):
+			s.stop()
+
+		sd.signal_bind('setnumber', set_number)
+		sd.signal_emit('setnumber', number=100)
+		self.assertEqual(100, lst[-1])
+
+		sd.signal_bind('setnumber', modify, priority=1)
+		sd.signal_emit('setnumber', number=100)
+		self.assertEqual(5, lst[-1])
+
+		lst.append(None)
+		sd.signal_bind('setnumber', stopit, priority=1)
+		sd.signal_emit('setnumber', number=100)
+		self.assertEqual(None, lst[-1])
+
+if __name__ == '__main__':
+	unittest.main()
2d0560aa9238f194911c03e56'>^
4d7c4f5 ^

daa4853 ^
86b7c42 ^

daa4853 ^













1e0e919 ^



daa4853 ^

86b7c42 ^
c5cf0e1 ^
86b7c42 ^
daa4853 ^
c5cf0e1 ^
daa4853 ^



c5cf0e1 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91







                                                             





                                                             



                                                             
                                                             


                                                             

                                              

                





                                                             

                                                  

                     


                                                


                              




                                                   



                                                        
                    
 


                                                       

                                                 
 

                                                   













                                                            



                                     

                                  
              
                                     
 
                       
                       



                                                       
                                                                       
#############################################################
##  This config file can live in the following locations:  ##
##                                                         ##
##      ./                                                 ##
##      /usr/local/getwtxt/                                ##
##      /etc/                                              ##
##      /usr/local/etc/                                    ##
##                                                         ##
##  The first location found wins. The default filename    ##
##  is getwtxt.yml. This can be configured via command     ##
##  line flags:                                            ##
##                                                         ##
##  For "myconfig.json"                                    ##
##    ./getwtxt -config myconfig -type json                ##
##                                                         ##
#############################################################

#############################################################
##  Changing the following option requires a restart.      ##
#############################################################

# This is the port that getwtxt will bind to.
# If BehindProxy is false, you should probably
# set this to 80 or 443
ListenPort: 9001

#############################################################
##  The following options may be changed at any time.      ##
##  getwtxt will automatically reload the config when      ##
##  changes are detected.                                  ##
#############################################################

# The type of database you want to use. Currently,
# the following are supported:
#   leveldb (default)
#   sqlite
DatabaseType: "leveldb"

# The location of the database structure. Can be
# a relative or absolute path.
DatabasePath: "getwtxt.db"

# The path to the assets directory, which contains:
#     style.css
#     tmpl/index.html
AssetsDirectory: "assets"

# If true, getwtxt will send all log messages, including
# requests, to stdout. It will ignore any set log file.
# Useful for debugging, but you probably want to keep
# logs.
StdoutLogging: false

# Log files getwtxt will use. HTTP Requests will be
# recorded in RequestLog, while everything else will go
# into MessageLog, such as errors and notices.
MessageLog: "/usr/local/getwtxt/logs/message.log"
RequestLog: "/usr/local/getwtxt/logs/request.log"

# This is the interval between data pushes from the
# in-memory cache to the on-disk database.
DatabasePushInterval: "5m"

# The time getwtxt will wait between attempts to scrape
# users' statuses from their twtxt.txt files
StatusFetchInterval: "1h"

# The following options pertain to your particular instance.
# They are used in the default page shown when you visit
# getwtxt in a web browser.
Instance:

  # The name of your instance.
  SiteName: "getwtxt"

  # Your instance's web address. If
  # BehindProxy is set to false, this
  # is also used to map incoming
  # requests.
  URL: "https://twtxt.example.com"

  # Your name.
  OwnerName: "Anonymous Microblogger"

  # Your email address.
  Email: "nobody@knows"

  # A short description of your instance, or your site.
  # This is shown at the top of the default web page
  # below your instance's name.
  Description: "A fast, resilient twtxt registry server written in Go!"