diff options
-rw-r--r-- | gemato/openpgp.py | 2 | ||||
-rw-r--r-- | tests/test_openpgp.py | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gemato/openpgp.py b/gemato/openpgp.py index adb4a5b..8b72cfa 100644 --- a/gemato/openpgp.py +++ b/gemato/openpgp.py @@ -45,7 +45,7 @@ class OpenPGPEnvironment(object): self._home = tempfile.mkdtemp() def __enter__(self): - pass + return self def __exit__(self, exc_type, exc_value, exc_cb): if self._home is not None: diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index dc2eafc..88b105b 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -202,3 +202,23 @@ class OpenPGPNoKeyTest(unittest.TestCase): self.env.verify_file, f) except gemato.exceptions.OpenPGPNoImplementation as e: raise unittest.SkipTest(str(e)) + + +class OpenPGPContextManagerTest(unittest.TestCase): + """ + Test the context manager API for OpenPGPEnvironment. + """ + + def test_verify_manifest(self): + with io.BytesIO(SIGNED_MANIFEST.encode('utf8')) as f: + with gemato.openpgp.OpenPGPEnvironment() as env: + try: + try: + env.import_key( + io.BytesIO(PUBLIC_KEY.encode('utf8'))) + except RuntimeError: + raise unittest.SkipTest('Unable to import OpenPGP key') + + env.verify_file(f) + except gemato.exceptions.OpenPGPNoImplementation as e: + raise unittest.SkipTest(str(e)) |