Ejemplo n.º 1
0
def test_buffer_bytes():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = buf.to_pybytes()

    assert result == val
Ejemplo n.º 2
0
def test_buffer_memoryview():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = memoryview(buf)

    assert result == val
Ejemplo n.º 3
0
def test_buffer_bytes():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = buf.to_pybytes()

    assert result == val
Ejemplo n.º 4
0
def test_buffer_memoryview():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = memoryview(buf)

    assert result == val
Ejemplo n.º 5
0
def test_buffer_memoryview_is_immutable():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = memoryview(buf)

    with pytest.raises(TypeError) as exc:
        result[0] = b'h'
        assert 'cannot modify read-only' in str(exc.value)

    b = bytes(buf)
    with pytest.raises(TypeError) as exc:
        b[0] = b'h'
        assert 'cannot modify read-only' in str(exc.value)
Ejemplo n.º 6
0
def test_buffer_memoryview_is_immutable():
    val = b'some data'

    buf = io.buffer_from_bytes(val)
    assert isinstance(buf, io.Buffer)

    result = memoryview(buf)

    with pytest.raises(TypeError) as exc:
        result[0] = b'h'
        assert 'cannot modify read-only' in str(exc.value)

    b = bytes(buf)
    with pytest.raises(TypeError) as exc:
        b[0] = b'h'
        assert 'cannot modify read-only' in str(exc.value)
Ejemplo n.º 7
0
 def make_buffer(bytes_obj):
     return bytearray(io.buffer_from_bytes(bytes_obj))
Ejemplo n.º 8
0
 def make_buffer(bytes_obj):
     return bytearray(io.buffer_from_bytes(bytes_obj))