Esempio n. 1
0
def test_unpack_very_long_string():
    text = u'%030x' % random.randrange(16**30000)
    given = BytesIO(b"\xF7\x30\x75\x00\x00" + text.encode('cesu-8'))
    assert types.String.from_resultset(given) == text


def test_unpack_invalid_string_length_indicator():
    # The string length indicator 254 is not definied
    with pytest.raises(InterfaceError):
        types.String.from_resultset(BytesIO(b"\xFE"))


@pytest.mark.parametrize("given,expected", [
    (b"\xFF", None),
    (b"\x0B\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
     byte_type(b"\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF")),
])
def test_unpack_binary(given, expected):
    given = BytesIO(given)
    assert types.Binary.from_resultset(given) == expected


def test_unpack_long_binary():
    binary_data = os.urandom(300)
    given = BytesIO(b"\xF6\x2C\x01" + binary_data)
    assert types.Binary.from_resultset(given) == binary_data


def test_unpack_very_long_binary():
    binary_data = os.urandom(30000)
    given = BytesIO(b"\xF7\x30\x75\x00\x00" + binary_data)
Esempio n. 2
0
 def from_resultset(cls, payload, connection=None):
     length = MixinStringType.get_length(payload)
     if length is None:
         return None
     return byte_type(payload.read(length))
Esempio n. 3
0
 def from_resultset(cls, payload, connection=None):
     length = MixinStringType.get_length(payload)
     if length is None:
         return None
     return byte_type(payload.read(length))
Esempio n. 4
0
    text = u'%030x' % random.randrange(16**30000)
    input = BytesIO(b"\xF7\x30\x75\x00\x00" + text.encode('cesu-8'))
    assert types.String.from_resultset(input) == text


def test_unpack_invalid_string_length_indicator():
    # The string length indicator 254 is not definied
    with pytest.raises(InterfaceError):
        types.String.from_resultset(BytesIO(b"\xFE"))


@pytest.mark.parametrize("input,expected", [
    (b"\xFF", None),
    (
        b"\x0B\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF",
        byte_type(b"\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF\x00\xFF")
    ),
])
def test_unpack_binary(input, expected):
    input = BytesIO(input)
    assert types.Binary.from_resultset(input) == expected


def test_unpack_long_binary():
    binary_data = os.urandom(300)
    input = BytesIO(b"\xF6\x2C\x01" + binary_data)
    assert types.Binary.from_resultset(input) == binary_data


def test_unpack_very_long_binary():
    binary_data = os.urandom(30000)