diff options
author | Hynek Schlawack <hs@ox.cx> | 2015-10-20 18:34:13 +0200 |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2015-10-20 21:14:48 +0200 |
commit | 80d005f68754f268da419540a593db83286f3d0c (patch) | |
tree | a2be0539075cfe3a3dfd580d78cfe756a196da68 /tests/test_rand.py | |
parent | d283a6454a9d3929edd1b17e4e02663a6947b5d1 (diff) | |
download | pyopenssl-git-80d005f68754f268da419540a593db83286f3d0c.tar.gz |
Replace the only EGD call by urandom
Also harmonize documentation. #boyScout
Diffstat (limited to 'tests/test_rand.py')
-rw-r--r-- | tests/test_rand.py | 51 |
1 files changed, 17 insertions, 34 deletions
diff --git a/tests/test_rand.py b/tests/test_rand.py index 8064011..ece0935 100644 --- a/tests/test_rand.py +++ b/tests/test_rand.py @@ -5,11 +5,12 @@ Unit tests for :py:obj:`OpenSSL.rand`. """ -from unittest import main import os import stat import sys +import pytest + from OpenSSL import rand from .util import NON_ASCII, TestCase, b @@ -97,40 +98,26 @@ class RandTests(TestCase): # entropy or not. self.assertTrue(rand.status() in (1, 2)) - def test_egd_wrong_args(self): - """ - :py:obj:`OpenSSL.rand.egd` raises :py:obj:`TypeError` when called with - the wrong number of arguments or with arguments not of type - :py:obj:`str` and :py:obj:`int`. - """ - self.assertRaises(TypeError, rand.egd) - self.assertRaises(TypeError, rand.egd, None) - self.assertRaises(TypeError, rand.egd, "foo", None) - self.assertRaises(TypeError, rand.egd, None, 3) - self.assertRaises(TypeError, rand.egd, "foo", 3, None) - - def test_egd_missing(self): + def test_egd_warning(self): """ - :py:obj:`OpenSSL.rand.egd` returns :py:obj:`0` or :py:obj:`-1` if the - EGD socket passed to it does not exist. + Calling egd raises :exc:`DeprecationWarning`. """ - result = rand.egd(self.mktemp()) - expected = (-1, 0) - self.assertTrue( - result in expected, - "%r not in %r" % (result, expected)) + pytest.deprecated_call(rand.egd, b"foo", 255) + pytest.deprecated_call(rand.egd, b"foo") - def test_egd_missing_and_bytes(self): + def test_egd_wrong_args(self): """ - :py:obj:`OpenSSL.rand.egd` returns :py:obj:`0` or :py:obj:`-1` if the - EGD socket passed to it does not exist even if a size argument is - explicitly passed. + :meth:`OpenSSL.rand.egd` raises :exc:`TypeError` when called with the + wrong number of arguments or with arguments not of type :obj:`str` and + :obj:`int`. """ - result = rand.egd(self.mktemp(), 1024) - expected = (-1, 0) - self.assertTrue( - result in expected, - "%r not in %r" % (result, expected)) + for args in [(), + (None,), + ("foo", None), + (None, 3), + ("foo", 3, None)]: + with pytest.raises(TypeError): + rand.egd(*args) def test_cleanup_wrong_args(self): """ @@ -206,7 +193,3 @@ class RandTests(TestCase): """ path = self.mktemp().decode('utf-8') + NON_ASCII self._read_write_test(path) - - -if __name__ == '__main__': - main() |