From 0d4e95621e05d50cd454049a424bb9ee098a5db6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 19 May 2016 15:53:19 +0200 Subject: 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 --- lang/python/tests/t-callbacks.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'lang/python/tests') 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 = """ +Key-Type: RSA +Key-Length: 1024 +Name-Real: Joe Tester +Name-Comment: with stupid passphrase +Name-Email: joe+pyme@example.org +Passphrase: Crypt0R0cks +Expire-Date: 2020-12-31 + +""" + +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" -- cgit v1.2.3