Home | Trees | Indices | Help |
|
---|
|
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 pytilities.event import Dispatcher, RestrictedDispatcher, UnsupportedEventError 24 from .helpers import Listener 2527 '''Using the allow arg'''5229 self.l = Listener() 30 31 d = Dispatcher() 32 d.register_events("a", "b") 33 self.ed = RestrictedDispatcher(d, allow=("b",))3436 self.assertFalse(self.ed.has_event("a")) 37 self.assertFalse(self.ed.has_event("c")) 38 self.assertRaises(UnsupportedEventError, self.ed.add_handler, "a", 39 self.l.handle_noarg) 40 self.assertRaises(UnsupportedEventError, self.ed.remove_handler, "a", 41 self.l.handle_noarg) 42 self.assertRaises(UnsupportedEventError, self.ed.dispatch, "a")4345 self.assert_(self.ed.has_event("b")) 46 47 self.ed.add_handler("b", self.l.handle_noarg) 48 self.ed.dispatch("b") 49 50 #has handler b 51 self.assertEquals(self.l.last, "noarg")54 '''Using the disallow arg'''7956 self.l = Listener() 57 58 d = Dispatcher() 59 d.register_events("a", "b") 60 self.ed = RestrictedDispatcher(d, disallow=("a",))6163 self.assertFalse(self.ed.has_event("a")) 64 self.assertFalse(self.ed.has_event("c")) 65 self.assertRaises(UnsupportedEventError, self.ed.add_handler, "a", 66 self.l.handle_noarg) 67 self.assertRaises(UnsupportedEventError, self.ed.remove_handler, "a", 68 self.l.handle_noarg) 69 self.assertRaises(UnsupportedEventError, self.ed.dispatch, "a")7072 self.assert_(self.ed.has_event("b")) 73 74 self.ed.add_handler("b", self.l.handle_noarg) 75 self.ed.dispatch("b") 76 77 #has handler b 78 self.assertEquals(self.l.last, "noarg")
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0 on Thu Jul 22 13:11:43 2010 | http://epydoc.sourceforge.net |