Add suffix option to TestCase.mktemp
Generating tmp files properly ensures the cleanup.
diff --git a/OpenSSL/test/test_rand.py b/OpenSSL/test/test_rand.py
index 3d5c290..f86e4bf 100644
--- a/OpenSSL/test/test_rand.py
+++ b/OpenSSL/test/test_rand.py
@@ -205,8 +205,7 @@
Random data can be saved and loaded to files with paths specified as
bytes.
"""
- path = self.mktemp()
- path += NON_ASCII.encode(sys.getfilesystemencoding())
+ path = self.mktemp(suffix=NON_ASCII)
self._read_write_test(path)
@@ -215,7 +214,7 @@
Random data can be saved and loaded to files with paths specified as
unicode.
"""
- path = self.mktemp().decode('utf-8') + NON_ASCII
+ path = self.mktemp(suffix=NON_ASCII).decode('utf-8')
self._read_write_test(path)
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index bb1c9ae..808b8a6 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -436,7 +436,7 @@
instance giving the file name to ``Context.use_privatekey_file``.
"""
self._use_privatekey_file_test(
- self.mktemp() + NON_ASCII.encode(getfilesystemencoding()),
+ self.mktemp(suffix=NON_ASCII),
FILETYPE_PEM,
)
@@ -447,7 +447,7 @@
instance giving the file name to ``Context.use_privatekey_file``.
"""
self._use_privatekey_file_test(
- self.mktemp().decode(getfilesystemencoding()) + NON_ASCII,
+ self.mktemp(suffix=NON_ASCII).decode(getfilesystemencoding()),
FILETYPE_PEM,
)
@@ -545,7 +545,7 @@
``bytes`` filename) which will be used to identify connections created
using the context.
"""
- filename = self.mktemp() + NON_ASCII.encode(getfilesystemencoding())
+ filename = self.mktemp(suffix=NON_ASCII)
self._use_certificate_file_test(filename)
@@ -555,7 +555,9 @@
``bytes`` filename) which will be used to identify connections created
using the context.
"""
- filename = self.mktemp().decode(getfilesystemencoding()) + NON_ASCII
+ filename = self.mktemp(
+ suffix=NON_ASCII
+ ).decode(getfilesystemencoding())
self._use_certificate_file_test(filename)
@@ -990,7 +992,7 @@
``bytes`` instance and uses the certificates within for verification
purposes.
"""
- cafile = self.mktemp() + NON_ASCII.encode(getfilesystemencoding())
+ cafile = self.mktemp(suffix=NON_ASCII)
self._load_verify_cafile(cafile)
@@ -1001,7 +1003,7 @@
purposes.
"""
self._load_verify_cafile(
- self.mktemp().decode(getfilesystemencoding()) + NON_ASCII
+ self.mktemp(suffix=NON_ASCII).decode(getfilesystemencoding())
)
@@ -1041,7 +1043,7 @@
purposes.
"""
self._load_verify_directory_locations_capath(
- self.mktemp() + NON_ASCII.encode(getfilesystemencoding())
+ self.mktemp(suffix=NON_ASCII)
)
@@ -1052,7 +1054,7 @@
purposes.
"""
self._load_verify_directory_locations_capath(
- self.mktemp().decode(getfilesystemencoding()) + NON_ASCII
+ self.mktemp(suffix=NON_ASCII)
)
@@ -1287,7 +1289,7 @@
construct and verify a trust chain.
"""
self._use_certificate_chain_file_test(
- self.mktemp() + NON_ASCII.encode(getfilesystemencoding())
+ self.mktemp(suffix=NON_ASCII)
)
@@ -1298,7 +1300,7 @@
to construct and verify a trust chain.
"""
self._use_certificate_chain_file_test(
- self.mktemp().decode(getfilesystemencoding()) + NON_ASCII
+ self.mktemp(suffix=NON_ASCII)
)
@@ -1395,7 +1397,7 @@
specified file (given as ``bytes``).
"""
self._load_tmp_dh_test(
- self.mktemp() + NON_ASCII.encode(getfilesystemencoding()),
+ self.mktemp(suffix=NON_ASCII)
)
@@ -1405,7 +1407,7 @@
specified file (given as ``unicode``).
"""
self._load_tmp_dh_test(
- self.mktemp().decode(getfilesystemencoding()) + NON_ASCII,
+ self.mktemp(suffix=NON_ASCII).decode(getfilesystemencoding())
)
diff --git a/OpenSSL/test/util.py b/OpenSSL/test/util.py
index 12e5eb8..c26a57a 100644
--- a/OpenSSL/test/util.py
+++ b/OpenSSL/test/util.py
@@ -296,13 +296,13 @@
_temporaryFiles = None
- def mktemp(self):
+ def mktemp(self, suffix=""):
"""
Pathetic substitute for twisted.trial.unittest.TestCase.mktemp.
"""
if self._temporaryFiles is None:
self._temporaryFiles = []
- temp = b(mktemp(dir="."))
+ temp = mktemp(suffix=suffix, dir=".").encode("utf-8")
self._temporaryFiles.append(temp)
return temp