diff options
| author | Justus Winter <[email protected]> | 2016-05-19 13:53:19 +0000 | 
|---|---|---|
| committer | Justus Winter <[email protected]> | 2016-05-19 14:08:33 +0000 | 
| commit | 0d4e95621e05d50cd454049a424bb9ee098a5db6 (patch) | |
| tree | 83b6922cbfde4ca8080b41fe166e8bcd84925f95 /lang/python/tests/t-callbacks.py | |
| parent | python: Robust exception handling in callbacks. (diff) | |
| download | gpgme-0d4e95621e05d50cd454049a424bb9ee098a5db6.tar.gz gpgme-0d4e95621e05d50cd454049a424bb9ee098a5db6.zip | |
python: Improve progress callbacks.
* lang/python/helpers.c (pyProgressCb): Stash python errors, convert
'what' to Unicode object.
* lang/python/pyme/core.py (Context.set_progress_cb): Hand in 'self'.
* lang/python/tests/t-callbacks.py: Test progress callbacks.
Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to '')
| -rwxr-xr-x | lang/python/tests/t-callbacks.py | 38 | 
1 files changed, 38 insertions, 0 deletions
| diff --git a/lang/python/tests/t-callbacks.py b/lang/python/tests/t-callbacks.py index e89fcb8d..bd88d861 100755 --- a/lang/python/tests/t-callbacks.py +++ b/lang/python/tests/t-callbacks.py @@ -75,3 +75,41 @@ except Exception as e:      assert type(e) == TypeError  else:      assert False, "Expected an error, got none" + + + +# Test the progress callback. +parms = """<GnupgKeyParms format="internal"> +Key-Type: RSA +Key-Length: 1024 +Name-Real: Joe Tester +Name-Comment: with stupid passphrase +Name-Email: [email protected] +Passphrase: Crypt0R0cks +Expire-Date: 2020-12-31 +</GnupgKeyParms> +""" + +messages = [] +def progress_cb(what, typ, current, total, hook=None): +    messages.append( +        "PROGRESS UPDATE: what = {}, type = {}, current = {}, total = {}" +        .format(what, typ, current, total)) + +c = core.Context() +c.set_progress_cb(progress_cb, None) +c.op_genkey(parms, None, None) +assert len(messages) > 0 + +# Test exception handling. +def progress_cb(what, typ, current, total, hook=None): +    raise myException + +c = core.Context() +c.set_progress_cb(progress_cb, None) +try: +    c.op_genkey(parms, None, None) +except Exception as e: +    assert e == myException +else: +    assert False, "Expected an error, got none" | 
