aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/tests/t-callbacks.py
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-05-24 10:29:32 +0000
committerJustus Winter <[email protected]>2016-05-24 11:13:35 +0000
commit09803c4a81b9431fd4c8f30abb1c60c4c735f0cb (patch)
treefd7e42c65876321b5e8d3a98027d8a14eaf57f28 /lang/python/tests/t-callbacks.py
parentpython: Fix hook. (diff)
downloadgpgme-09803c4a81b9431fd4c8f30abb1c60c4c735f0cb.tar.gz
gpgme-09803c4a81b9431fd4c8f30abb1c60c4c735f0cb.zip
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 <[email protected]>
Diffstat (limited to 'lang/python/tests/t-callbacks.py')
-rwxr-xr-xlang/python/tests/t-callbacks.py33
1 files changed, 33 insertions, 0 deletions
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"