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'])
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'])
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'])
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'), [])
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'), [])
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'])
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])
def test_nostate(self): def baaz(): return 'baaz' register_nostate_handler('baz', baaz) self.assertEqual(emmit_action('baz'), ['baaz'])