From f526d0e22e8b881ccbca66b46a0e1b68bbc4cd6b Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 13 Oct 2016 13:13:23 +0200 Subject: python: Make 'get_key' more idiomatic. * lang/python/pyme/core.py (Context.get_key): Raise errors.KeyNotFound if the key is not found. This error is both a KeyError for idiomatic error handling as well as a GPGMEError so we don't break existing code. * lang/python/pyme/errors.py (KeyNotFound): New class. * lang/python/tests/support.py (no_such_key): New variable. * lang/python/tests/t-keylist.py: Test the new behavior. Signed-off-by: Justus Winter --- lang/python/tests/t-keylist.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lang/python/tests/t-keylist.py') diff --git a/lang/python/tests/t-keylist.py b/lang/python/tests/t-keylist.py index 5e8b3336..f7f6674e 100755 --- a/lang/python/tests/t-keylist.py +++ b/lang/python/tests/t-keylist.py @@ -20,6 +20,7 @@ from __future__ import absolute_import, print_function, unicode_literals del absolute_import, print_function, unicode_literals +import pyme from pyme import core, constants import support @@ -244,3 +245,25 @@ for i, key in enumerate(c.keylist()): if misc_check: misc_check (uids[0][0], key) + + +# check get_key() +with pyme.Context() as c: + c.get_key(support.alpha) + c.get_key(support.alpha, secret=True) + + c.get_key(support.bob) + try: + c.get_key(support.bob, secret=True) + except KeyError: + pass + else: + assert False, "Expected KeyError" + + # Legacy error + try: + c.get_key(support.no_such_key) + except pyme.errors.GPGMEError: + pass + else: + assert False, "Expected GPGMEError" -- cgit v1.2.3