-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathrun-base64.test
More file actions
52 lines (39 loc) · 1.44 KB
/
run-base64.test
File metadata and controls
52 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[case testAllBase64Features_librt_experimental]
from typing import Any
import base64
from librt.base64 import b64encode
from testutil import assertRaises
def test_encode_basic() -> None:
assert b64encode(b"x") == b"eA=="
with assertRaises(TypeError):
b64encode(bytearray(b"x"))
def check_encode(b: bytes) -> None:
assert b64encode(b) == getattr(base64, "b64encode")(b)
def test_encode_different_strings() -> None:
for i in range(256):
check_encode(bytes([i]))
check_encode(bytes([i]) + b"x")
check_encode(bytes([i]) + b"xy")
check_encode(bytes([i]) + b"xyz")
check_encode(bytes([i]) + b"xyza")
check_encode(b"x" + bytes([i]))
check_encode(b"xy" + bytes([i]))
check_encode(b"xyz" + bytes([i]))
check_encode(b"xyza" + bytes([i]))
b = b"a\x00\xb7" * 1000
for i in range(1000):
check_encode(b[:i])
for b in b"", b"ab", b"bac", b"1234", b"xyz88", b"abc" * 200:
check_encode(b)
def test_encode_wrapper() -> None:
enc: Any = b64encode
assert enc(b"x") == b"eA=="
with assertRaises(TypeError):
enc()
with assertRaises(TypeError):
enc(b"x", b"y")
[case testBase64FeaturesNotAvailableInNonExperimentalBuild_librt_base64]
# This also ensures librt.base64 can be built without experimental features
import librt.base64
def test_b64encode_not_available() -> None:
assert not hasattr(librt.base64, "b64encode")