Debian Codegraph @

tests/test_rand.py

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