Esempio n. 1
0
def test_merge_frames():
    result = merge_frames({'lengths': [3, 4]}, [b'12', b'34', b'567'])
    expected = [b'123', b'4567']

    assert list(map(ensure_bytes, result)) == expected

    b = b'123'
    assert merge_frames({'lengths': [3]}, [b])[0] is b
Esempio n. 2
0
def test_merge_frames():
    result = merge_frames({'lengths': [3, 4]}, [b'12', b'34', b'567'])
    expected = [b'123', b'4567']

    assert list(map(ensure_bytes, result)) == expected

    b = b'123'
    assert merge_frames({'lengths': [3]}, [b])[0] is b
Esempio n. 3
0
def test_merge_frames():
    result = merge_frames({"lengths": [3, 4]}, [b"12", b"34", b"567"])
    expected = [b"123", b"4567"]

    assert list(map(ensure_bytes, result)) == expected

    b = b"123"
    assert merge_frames({"lengths": [3]}, [b])[0] is b

    L = [b"123", b"456"]
    assert merge_frames({"lengths": [3, 3]}, L) is L
Esempio n. 4
0
def test_merge_frames(lengths, writeable, frames):
    header = {"lengths": lengths, "writeable": writeable}
    result = merge_frames(header, frames)

    data = b"".join(frames)
    expected = []
    for i in lengths:
        expected.append(data[:i])
        data = data[i:]

    writeables = list(map(is_writeable, result))
    assert (r == e for r, e in zip(writeables, header["writeable"]) if e is not None)
    assert list(map(ensure_bytes, result)) == expected
def test_merge_frames(lengths, frames):
    header = {"lengths": lengths}
    result = merge_frames(header, frames)

    data = b"".join(frames)
    expected = []
    for i in lengths:
        expected.append(data[:i])
        data = data[i:]

    assert all(isinstance(f, memoryview) for f in result)
    assert all(not f.readonly for f in result)
    assert list(map(ensure_bytes, result)) == expected