예제 #1
0
 def test_multiple_deco(self):
     @register('foo')
     @register('bar')
     def baz(state):
         return 'foo-bar'
     self.assertEqual(emmit_action('foo'), ['foo-bar'])
     self.assertEqual(emmit_action('bar'), ['foo-bar'])
예제 #2
0
 def test_register(self):
     @register('baz')
     def baz(state):
         return 'foo'
     
     @register('foo')
     def foo_bar(state):
         return "foo bar"
     self.assertEqual(emmit_action('foo'), ['foo bar'])
     self.assertEqual(emmit_action('baz'), ['foo'])
예제 #3
0
 def test_multiple_deco_method(self):
     class Foo(ActionHandler):
         def __init__(self):
             ActionHandler.__init__(self)
             self.test = "foobar"
         
         @register_method('bar')
         @register_method('foo')
         def foo(self, state):
             return self.test
     
     foo = Foo()
     self.assertEqual(emmit_action('foo'), ['foobar'])
     self.assertEqual(emmit_action('bar'), ['foobar'])
예제 #4
0
 def test_removeactions(self):
     class Foo(ActionHandler):
         def __init__(self):
             ActionHandler.__init__(self)
             self.test = "foobar"
         
         @register_method('foo')
         def foo(self, state):
             return self.test
     
     foo = Foo()
     register_handler('foo', lambda x: 'foo')
     self.assertEqual(emmit_action('foo'), ['foobar', 'foo'])
     foo.remove_actions()
     self.assertEqual(emmit_action('foo'), [])
예제 #5
0
 def test_removemethods(self):
     class Foo(ActionHandler):
         def __init__(self):
             ActionHandler.__init__(self)
             self.test = "foobar"
         
         @register_method('foo')
         def foo(self, state):
             return self.test
         
         @register_method('bar')
         def bar(self, state):
             return "bar"
     
     foo = Foo()
     bar = Foo()   
     remove_handler('foo', foo.foo)
     self.assertEqual(emmit_action('foo'), ['foobar'])
     self.assert_(foo.foo not in _inst.actions['foo'])
     remove_function(bar.foo)
     self.assertEqual(emmit_action('foo'), [])
예제 #6
0
 def test_context(self):
     register_handler('bar', lambda x: 'bar')
     cont = Context()
     class Bar(ActionHandler):
         def __init__(self):
             ActionHandler.__init__(self, cont)
         
         @register_method('bar')
         def baar(self, state):
             return 42
     bar = Bar()
     self.assertEqual(cont.emmit_action('bar'), [42])
     self.assertEqual(emmit_action('bar'), ['bar'])
예제 #7
0
 def test_stophandling(self):
     @register('spam')
     def first(state):
         return 1
     
     @register('spam')
     def second(state):
         raise StopHandling
     
     @register('spam')
     def third(state):
         return 3
     
     self.assertEqual(emmit_action('spam'), [1])
예제 #8
0
 def test_nostate(self):
     def baaz():
         return 'baaz'
     
     register_nostate_handler('baz', baaz)
     self.assertEqual(emmit_action('baz'), ['baaz'])