Debian Codegraph @

tests/test_itsdangerous/test_encoding.py

raw
1 import pytest
2
3 from itsdangerous.encoding import base64_decode
4 from itsdangerous.encoding import base64_encode
5 from itsdangerous.encoding import bytes_to_int
6 from itsdangerous.encoding import int_to_bytes
7 from itsdangerous.encoding import want_bytes
8 from itsdangerous.exc import BadData
9
10
11 @pytest.mark.parametrize("value", ("mañana", b"tomorrow"))
12 def test_want_bytes(value):
13 out = want_bytes(value)
14 assert isinstance(out, bytes)
15
16
17 @pytest.mark.parametrize("value", ("無限", b"infinite"))
18 def test_base64(value):
19 enc = base64_encode(value)
20 assert isinstance(enc, bytes)
21 dec = base64_decode(enc)
22 assert dec == want_bytes(value)
23
24
25 def test_base64_bad():
26 with pytest.raises(BadData):
27 base64_decode("12345")
28
29
30 @pytest.mark.parametrize(
31 ("value", "expect"), ((0, b""), (192, b"\xc0"), (18446744073709551615, b"\xff" * 8))
32 )
33 def test_int_bytes(value, expect):
34 enc = int_to_bytes(value)
35 assert enc == expect
36 dec = bytes_to_int(enc)
37 assert dec == value