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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
# This test code was written by the `hypothesis.extra.ghostwriter` module
# and is provided under the Creative Commons Zero public domain dedication.
import base64
from hypothesis import given, strategies as st
# TODO: replace st.nothing() with appropriate strategies
@given(
adobe=st.booleans(),
b=st.nothing(),
foldspaces=st.booleans(),
ignorechars=st.just(b" \t\n\r\x0b"),
pad=st.booleans(),
wrapcol=st.just(0),
)
def test_roundtrip_a85encode_a85decode(adobe, b, foldspaces, ignorechars, pad, wrapcol):
value0 = base64.a85encode(
b=b, foldspaces=foldspaces, wrapcol=wrapcol, pad=pad, adobe=adobe
)
value1 = base64.a85decode(
b=value0, foldspaces=foldspaces, adobe=adobe, ignorechars=ignorechars
)
assert b == value1, (b, value1)
@given(casefold=st.booleans(), s=st.nothing())
def test_roundtrip_b16encode_b16decode(casefold, s):
value0 = base64.b16encode(s=s)
value1 = base64.b16decode(s=value0, casefold=casefold)
assert s == value1, (s, value1)
@given(casefold=st.booleans(), map01=st.none(), s=st.nothing())
def test_roundtrip_b32encode_b32decode(casefold, map01, s):
value0 = base64.b32encode(s=s)
value1 = base64.b32decode(s=value0, casefold=casefold, map01=map01)
assert s == value1, (s, value1)
@given(altchars=st.none(), s=st.nothing(), validate=st.booleans())
def test_roundtrip_b64encode_b64decode(altchars, s, validate):
value0 = base64.b64encode(s=s, altchars=altchars)
value1 = base64.b64decode(s=value0, altchars=altchars, validate=validate)
assert s == value1, (s, value1)
@given(b=st.nothing(), pad=st.booleans())
def test_roundtrip_b85encode_b85decode(b, pad):
value0 = base64.b85encode(b=b, pad=pad)
value1 = base64.b85decode(b=value0)
assert b == value1, (b, value1)
@given(input=st.nothing(), output=st.nothing())
def test_roundtrip_encode_decode(input, output):
value0 = base64.encode(input=input, output=output)
value1 = base64.decode(input=value0, output=output)
assert input == value1, (input, value1)
@given(s=st.nothing())
def test_roundtrip_encodebytes_decodebytes(s):
value0 = base64.encodebytes(s=s)
value1 = base64.decodebytes(s=value0)
assert s == value1, (s, value1)
@given(s=st.nothing())
def test_roundtrip_standard_b64encode_standard_b64decode(s):
value0 = base64.standard_b64encode(s=s)
value1 = base64.standard_b64decode(s=value0)
assert s == value1, (s, value1)
@given(s=st.nothing())
def test_roundtrip_urlsafe_b64encode_urlsafe_b64decode(s):
value0 = base64.urlsafe_b64encode(s=s)
value1 = base64.urlsafe_b64decode(s=value0)
assert s == value1, (s, value1)
|