aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/tests/t-idiomatic.py
diff options
context:
space:
mode:
Diffstat (limited to 'lang/python/tests/t-idiomatic.py')
-rwxr-xr-xlang/python/tests/t-idiomatic.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/lang/python/tests/t-idiomatic.py b/lang/python/tests/t-idiomatic.py
index 05a377e4..37cfb64a 100755
--- a/lang/python/tests/t-idiomatic.py
+++ b/lang/python/tests/t-idiomatic.py
@@ -23,7 +23,15 @@ from pyme import core, constants, errors
import support
support.init_gpgme(constants.PROTOCOL_OpenPGP)
-c = core.Context()
+
+# Both Context and Data can be used as context manager:
+with core.Context() as c, core.Data() as d:
+ c.get_engine_info()
+ d.write(b"Halloechen")
+ leak_c = c
+ leak_d = d
+assert leak_c.wrapped == None
+assert leak_d.wrapped == None
# Demonstrate automatic wrapping of file-like objects with 'fileno'
# method.
@@ -33,10 +41,11 @@ with tempfile.TemporaryFile() as source, \
source.write(b"Hallo Leute\n")
source.seek(0, os.SEEK_SET)
- c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
- signed.seek(0, os.SEEK_SET)
- c.op_verify(signed, None, sink)
- result = c.op_verify_result()
+ with core.Context() as c:
+ c.op_sign(source, signed, constants.SIG_MODE_NORMAL)
+ signed.seek(0, os.SEEK_SET)
+ c.op_verify(signed, None, sink)
+ result = c.op_verify_result()
assert len(result.signatures) == 1, "Unexpected number of signatures"
sig = result.signatures[0]