blob: e04a24cc26020c9fd8a7ae50699a2297aa310c0d [file] [log] [blame]
Paul Kehreracbd6622017-11-20 22:25:18 +08001# Copyright (c) Frederick Dean
2# See LICENSE for details.
3
4"""
5Unit tests for `OpenSSL.rand`.
6"""
7
8import pytest
9
10from OpenSSL import rand
11
12
13class TestRand(object):
14
15 @pytest.mark.parametrize('args', [
16 (b"foo", None),
17 (None, 3),
18 ])
19 def test_add_wrong_args(self, args):
20 """
21 `OpenSSL.rand.add` raises `TypeError` if called with arguments not of
22 type `str` and `int`.
23 """
24 with pytest.raises(TypeError):
25 rand.add(*args)
26
27 def test_add(self):
28 """
29 `OpenSSL.rand.add` adds entropy to the PRNG.
30 """
31 rand.add(b'hamburger', 3)
32
33 def test_status(self):
34 """
35 `OpenSSL.rand.status` returns `1` if the PRNG has sufficient entropy,
36 `0` otherwise.
37 """
38 assert rand.status() == 1