summaryrefslogtreecommitdiff
path: root/tests/test_openpgp.py
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-09-07 07:14:57 +0200
committerMichał Górny <mgorny@gentoo.org>2020-09-07 07:15:10 +0200
commitf50e150b12c02033a0666b66821c99fd0dc19dfe (patch)
tree4ae9231e8110213131f0d8878fc75cd7b48ba1c8 /tests/test_openpgp.py
parent4355f02079ed1aaea1867411c9770c90ae7679c6 (diff)
downloadgemato-f50e150b12c02033a0666b66821c99fd0dc19dfe.tar.gz
test_openpgp: Fix ResourceWarning (cleaning up tmpdir)
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'tests/test_openpgp.py')
-rw-r--r--tests/test_openpgp.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py
index 434df88..614127b 100644
--- a/tests/test_openpgp.py
+++ b/tests/test_openpgp.py
@@ -338,6 +338,12 @@ class MockedSystemGPGEnvironment(SystemGPGEnvironment):
os.environ['GNUPGHOME'] = self._tmpdir.name
super().__init__(*args, **kwargs)
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_value, exc_cb):
+ self.close()
+
def close(self):
if self._tmpdir is not None:
self._tmpdir.cleanup()
@@ -450,13 +456,13 @@ def test_verify_manifest(openpgp_env, manifest_var, key_var, expected):
def test_verify_untrusted_key():
try:
- openpgp_env = MockedSystemGPGEnvironment()
- with io.BytesIO(VALID_PUBLIC_KEY) as f:
- openpgp_env.import_key(f, trust=False)
+ with MockedSystemGPGEnvironment() as openpgp_env:
+ with io.BytesIO(VALID_PUBLIC_KEY) as f:
+ openpgp_env.import_key(f, trust=False)
- with io.StringIO(SIGNED_MANIFEST) as f:
- with pytest.raises(OpenPGPUntrustedSigFailure):
- openpgp_env.verify_file(f)
+ with io.StringIO(SIGNED_MANIFEST) as f:
+ with pytest.raises(OpenPGPUntrustedSigFailure):
+ openpgp_env.verify_file(f)
except OpenPGPNoImplementation as e:
pytest.skip(str(e))