Put some shared code into a shared module and start using it from all three of the main implementation modules.
Also add a test for the MemoryError behavior of OpenSSL.rand.bytes.
Also make the other error handling behavior of that function probably correct maybe.
At least, give it a better comment about why it is untested.
diff --git a/OpenSSL/test/test_rand.py b/OpenSSL/test/test_rand.py
index 8a3c5fe..ffbb731 100644
--- a/OpenSSL/test/test_rand.py
+++ b/OpenSSL/test/test_rand.py
@@ -23,7 +23,14 @@
self.assertRaises(TypeError, rand.bytes, None)
self.assertRaises(TypeError, rand.bytes, 3, None)
- # XXX Test failure of the malloc() in rand_bytes.
+
+ def test_insufficientMemory(self):
+ """
+ :py:obj:`OpenSSL.rand.bytes` raises :py:obj:`MemoryError` if more bytes
+ are requested than will fit in memory.
+ """
+ self.assertRaises(MemoryError, rand.bytes, 1024 * 1024 * 1024 * 1024)
+
def test_bytes(self):
"""
diff --git a/OpenSSL/test/util.py b/OpenSSL/test/util.py
index 31242ce..a1a0cd9 100644
--- a/OpenSSL/test/util.py
+++ b/OpenSSL/test/util.py
@@ -14,7 +14,8 @@
from unittest import TestCase
import sys
-from OpenSSL.crypto import Error, _exception_from_error_queue
+from OpenSSL._util import exception_from_error_queue
+from OpenSSL.crypto import Error
import memdbg
@@ -167,7 +168,7 @@
elif os.path.exists(temp):
os.unlink(temp)
try:
- _exception_from_error_queue()
+ exception_from_error_queue(Error)
except Error:
e = sys.exc_info()[1]
if e.args != ([],):