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):
"""