diff options
author | Justus Winter <[email protected]> | 2016-05-24 13:14:53 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2016-05-24 16:00:16 +0000 |
commit | 8b57f06e0c04f5c9b87a3c76618230d757412076 (patch) | |
tree | e7a0779263eb230b5e82cf2dd6abf2b9188655b3 /lang/python/tests/t-callbacks.py | |
parent | python: Improve docstring. (diff) | |
download | gpgme-8b57f06e0c04f5c9b87a3c76618230d757412076.tar.gz gpgme-8b57f06e0c04f5c9b87a3c76618230d757412076.zip |
python: Support status callbacks.
* lang/python/helpers.c (pyStatusCb): New function.
(pygpgme_set_status_cb): Likewise.
* lang/python/helpers.h (pygpgme_set_status_cb): New prototype.
* lang/python/pyme/core.py (Context.__init__): Initialize
'last_statuscb'.
(Context._free_statuscb): New function.
(Context.set_status_cb): Likewise.
* lang/python/tests/t-callbacks.py: Test status callbacks.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to '')
-rwxr-xr-x | lang/python/tests/t-callbacks.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lang/python/tests/t-callbacks.py b/lang/python/tests/t-callbacks.py index d962dc41..57975264 100755 --- a/lang/python/tests/t-callbacks.py +++ b/lang/python/tests/t-callbacks.py @@ -146,3 +146,38 @@ except Exception as e: assert e == myException else: assert False, "Expected an error, got none" + + + +# Test the status callback. +source = core.Data("Hallo Leute\n") +sink = core.Data() + +status_cb_called = False +def status_cb(keyword, args, hook=None): + global status_cb_called + status_cb_called = True + assert hook == cookie + +c = core.Context() +c.set_status_cb(status_cb, cookie) +c.set_ctx_flag("full-status", "1") +c.op_encrypt([alpha], constants.ENCRYPT_ALWAYS_TRUST, source, sink) +assert status_cb_called + +# Test exceptions. +source = core.Data("Hallo Leute\n") +sink = core.Data() + +def status_cb(keyword, args): + raise myException + +c = core.Context() +c.set_status_cb(status_cb, None) +c.set_ctx_flag("full-status", "1") +try: + c.op_encrypt([alpha], constants.ENCRYPT_ALWAYS_TRUST, source, sink) +except Exception as e: + assert e == myException +else: + assert False, "Expected an error, got none" |