PROTON-997: Add handler composition tests that do not involve exceptions TODO: exception peeling is needed if we want to use python exceptions to be caught by python testcases
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/f757b982 Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/f757b982 Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/f757b982 Branch: refs/heads/proton-go Commit: f757b982283675854643a180996552c5b310b0db Parents: 4e2258f Author: Bozo Dragojevic <[email protected]> Authored: Tue Jul 21 22:33:24 2015 +0200 Committer: Bozo Dragojevic <[email protected]> Committed: Wed Sep 16 15:40:05 2015 +0200 ---------------------------------------------------------------------- proton-c/bindings/python/proton/__init__.py | 1 - tests/python/proton_tests/reactor.py | 82 ++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f757b982/proton-c/bindings/python/proton/__init__.py ---------------------------------------------------------------------- diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py index a97e9af..8bdb7a3 100644 --- a/proton-c/bindings/python/proton/__init__.py +++ b/proton-c/bindings/python/proton/__init__.py @@ -3910,7 +3910,6 @@ class WrappedHandler(Wrapper): # instantiate the surrogate self.handlers.extend([]) - def _on_error(self, info): on_error = getattr(self, "on_error", None) if on_error is None: http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/f757b982/tests/python/proton_tests/reactor.py ---------------------------------------------------------------------- diff --git a/tests/python/proton_tests/reactor.py b/tests/python/proton_tests/reactor.py index b796ed2..890f4b0 100644 --- a/tests/python/proton_tests/reactor.py +++ b/tests/python/proton_tests/reactor.py @@ -45,11 +45,20 @@ class BarfOnTask: raise Barf() class BarfOnFinal: + init = False + + def on_reactor_init(self, event): + self.init = True def on_reactor_final(self, event): raise Barf() class BarfOnFinalDerived(CHandshaker): + init = False + + def on_reactor_init(self, event): + self.init = True + def on_reactor_final(self, event): raise Barf() @@ -263,6 +272,11 @@ class HandlerDerivationTest(Test): raise SkipTest() self.reactor = Reactor() + def wrong_exception(self): + import sys + ex = sys.exc_info() + assert False, " Unexpected exception " + str(ex[1]) + def test_reactor_final_derived(self): h = BarfOnFinalDerived() self.reactor.global_handler = h @@ -271,6 +285,8 @@ class HandlerDerivationTest(Test): assert False, "expected to barf" except Barf: pass + except: + self.wrong_exception() def test_reactor_final_py_child_py(self): class APoorExcuseForAHandler: @@ -282,6 +298,8 @@ class HandlerDerivationTest(Test): assert False, "expected to barf" except Barf: pass + except: + self.wrong_exception() def test_reactor_final_py_child_derived(self): class APoorExcuseForAHandler: @@ -293,6 +311,8 @@ class HandlerDerivationTest(Test): assert False, "expected to barf" except Barf: pass + except: + self.wrong_exception() def test_reactor_final_derived_child_derived(self): class APoorExcuseForAHandler(CHandshaker): @@ -305,6 +325,8 @@ class HandlerDerivationTest(Test): assert False, "expected to barf" except Barf: pass + except: + self.wrong_exception() def test_reactor_final_derived_child_py(self): class APoorExcuseForAHandler(CHandshaker): @@ -317,4 +339,64 @@ class HandlerDerivationTest(Test): assert False, "expected to barf" except Barf: pass + except: + self.wrong_exception() + + def test_reactor_init_derived(self): + h = BarfOnFinalDerived() + self.reactor.global_handler = h + try: + self.reactor.run() + assert False, "expected to barf" + except: + assert h.init, "excpected the init" + def test_reactor_init_py_child_py(self): + h = BarfOnFinal() + class APoorExcuseForAHandler: + def __init__(self): + self.handlers = [h] + self.reactor.global_handler = APoorExcuseForAHandler() + try: + self.reactor.run() + assert False, "expected to barf" + except: + assert h.init, "excpected the init" + + def test_reactor_init_py_child_derived(self): + h = BarfOnFinalDerived() + class APoorExcuseForAHandler: + def __init__(self): + self.handlers = [h] + self.reactor.global_handler = APoorExcuseForAHandler() + try: + self.reactor.run() + assert False, "expected to barf" + except: + assert h.init, "excpected the init" + + def test_reactor_init_derived_child_derived(self): + h = BarfOnFinalDerived() + class APoorExcuseForAHandler(CHandshaker): + def __init__(self): + CHandshaker.__init__(self) + self.handlers = [h] + self.reactor.global_handler = APoorExcuseForAHandler() + try: + self.reactor.run() + assert False, "expected to barf" + except: + assert h.init, "excpected the init" + + def test_reactor_init_derived_child_py(self): + h = BarfOnFinal() + class APoorExcuseForAHandler(CHandshaker): + def __init__(self): + CHandshaker.__init__(self) + self.handlers = [h] + self.reactor.global_handler = APoorExcuseForAHandler() + try: + self.reactor.run() + assert False, "expected to barf" + except: + assert h.init, "excpected the init" --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
