From 09803c4a81b9431fd4c8f30abb1c60c4c735f0cb Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 24 May 2016 12:29:32 +0200 Subject: python: Improve support for edit callbacks. * lang/python/helpers.c (pyEditCb): Stash exceptions. * lang/python/pyme/core.py (Context.op_edit): Hand in 'self'. * lang/python/tests/Makefile.am (py_tests): Add new test. * lang/python/tests/t-callbacks.py: Test edit callbacks. * lang/python/tests/t-edit.py: New file. Signed-off-by: Justus Winter --- lang/python/tests/t-callbacks.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lang/python/tests/t-callbacks.py') diff --git a/lang/python/tests/t-callbacks.py b/lang/python/tests/t-callbacks.py index 70f641d7..d962dc41 100755 --- a/lang/python/tests/t-callbacks.py +++ b/lang/python/tests/t-callbacks.py @@ -113,3 +113,36 @@ except Exception as e: assert e == myException else: assert False, "Expected an error, got none" + + +# Test the edit callback. +c = core.Context() +c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK) +c.set_passphrase_cb(lambda *args: "abc") +sink = core.Data() +alpha = c.get_key("A0FF4590BB6122EDEF6E3C542D727CC768697734", False) + +cookie = object() +edit_cb_called = False +def edit_cb(status, args, hook): + global edit_cb_called + edit_cb_called = True + assert hook == cookie + return "quit" if args == "keyedit.prompt" else None +c.op_edit(alpha, edit_cb, cookie, sink) +assert edit_cb_called + +# Test exceptions. +c = core.Context() +c.set_pinentry_mode(constants.PINENTRY_MODE_LOOPBACK) +c.set_passphrase_cb(lambda *args: "abc") +sink = core.Data() + +def edit_cb(status, args): + raise myException +try: + c.op_edit(alpha, edit_cb, None, sink) +except Exception as e: + assert e == myException +else: + assert False, "Expected an error, got none" -- cgit v1.2.3