summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemato/openpgp.py7
-rw-r--r--tests/test_openpgp.py12
2 files changed, 16 insertions, 3 deletions
diff --git a/gemato/openpgp.py b/gemato/openpgp.py
index 8b72cfa..607c46f 100644
--- a/gemato/openpgp.py
+++ b/gemato/openpgp.py
@@ -50,10 +50,11 @@ class OpenPGPEnvironment(object):
def __exit__(self, exc_type, exc_value, exc_cb):
if self._home is not None:
self.close()
- self._home = None
def close(self):
- shutil.rmtree(self._home)
+ if self._home is not None:
+ shutil.rmtree(self._home)
+ self._home = None
def import_key(self, keyfile):
"""
@@ -77,7 +78,7 @@ class OpenPGPEnvironment(object):
def home(self):
if self._home is None:
raise RuntimeError(
- 'OpenPGPEnvironment must be used via context manager')
+ 'OpenPGPEnvironment has been closed')
return self._home
diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py
index 88b105b..11a6f6e 100644
--- a/tests/test_openpgp.py
+++ b/tests/test_openpgp.py
@@ -222,3 +222,15 @@ class OpenPGPContextManagerTest(unittest.TestCase):
env.verify_file(f)
except gemato.exceptions.OpenPGPNoImplementation as e:
raise unittest.SkipTest(str(e))
+
+ def test_double_close(self):
+ with io.BytesIO(SIGNED_MANIFEST.encode('utf8')) as f:
+ with gemato.openpgp.OpenPGPEnvironment() as env:
+ env.close()
+
+ def test_home_after_close(self):
+ with io.BytesIO(SIGNED_MANIFEST.encode('utf8')) as f:
+ with gemato.openpgp.OpenPGPEnvironment() as env:
+ env.close()
+ with self.assertRaises(RuntimeError):
+ env.home