Package pytilities :: Package event :: Package test :: Module restricteddispatcher
[hide private]
[frames] | no frames]

Source Code for Module pytilities.event.test.restricteddispatcher

 1  # Copyright (C) 2010 Tim Diels <limyreth@users.sourceforge.net> 
 2  #  
 3  # This file is part of pytilities. 
 4  #  
 5  # pytilities is free software: you can redistribute it and/or modify 
 6  # it under the terms of the GNU General Public License as published by 
 7  # the Free Software Foundation, either version 3 of the License, or 
 8  # (at your option) any later version. 
 9  #  
10  # pytilities is distributed in the hope that it will be useful, 
11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
13  # GNU General Public License for more details. 
14  #  
15  # You should have received a copy of the GNU General Public License 
16  # along with pytilities.  If not, see <http://www.gnu.org/licenses/>. 
17  # 
18   
19  __docformat__ = 'reStructuredText' 
20   
21  import unittest 
22   
23  from .. import Dispatcher, RestrictedDispatcher, UnsupportedEventError 
24  from .helpers import Listener 
25   
26 -class InitTestCase(unittest.TestCase):
27 - def setUp(self):
28 self.l = Listener() 29 30 d = Dispatcher() 31 d.register_events("a", "b") 32 self.ed = RestrictedDispatcher(d, allow="b")
33
34 - def test_fails(self):
35 self.assertFalse(self.ed.has_event("a")) 36 self.assertRaises(UnsupportedEventError, self.ed.add_handler, "a", 37 self.l.handle_noarg) 38 self.assertRaises(UnsupportedEventError, self.ed.remove_handler, "a", 39 self.l.handle_noarg) 40 self.assertRaises(UnsupportedEventError, self.ed.dispatch, "a")
41
42 - def test_success(self):
43 self.assert_(self.ed.has_event("b")) 44 45 self.ed.add_handler("b", self.l.handle_noarg) 46 self.ed.dispatch("b") 47 48 #has handler b 49 self.assertEquals(self.l.last, "noarg")
50
51 -def run():
52 unittest.main(__name__)
53