File: test_buffer_read_into.py

package info (click to toggle)
python-moderngl 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,700 kB
  • sloc: python: 15,758; cpp: 14,665; makefile: 14
file content (27 lines) | stat: -rw-r--r-- 644 bytes parent folder | download
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
"""
Test buffer read_into method
"""


def test_1(ctx):
    buf = ctx.buffer(b'abc')
    data = bytearray(3)
    buf.read_into(data)
    assert bytes(data) == b'abc'


def test_2(ctx):
    buf = ctx.buffer(b'abcxyz123')
    data = bytearray(3)
    buf.read_into(data, offset=6)
    assert bytes(data) == b'123'


def test_3(ctx):
    buf = ctx.buffer(b'abcxyz123')
    data = bytearray(12)
    buf.read_into(data, 3, offset=3, write_offset=0)
    buf.read_into(data, 3, offset=0, write_offset=3)
    buf.read_into(data, 3, offset=6, write_offset=6)
    buf.read_into(data, 3, offset=3, write_offset=9)
    assert bytes(data) == b'xyzabc123xyz'