File: test_510_byte_stream.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (51 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (2)
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
# Copyright (c) 2020, Manfred Moitzi
# License: MIT License

import pytest
import struct
from ezdxf.tools.binarydata import ByteStream


def test_init():
    bs = ByteStream(b"ABCDABC\x00")
    assert bs.index == 0
    assert len(bs.buffer) == 8


def test_read_ps():
    bs = ByteStream(b"ABCDABC\x00")
    s = bs.read_padded_string()
    assert s == "ABCDABC"
    assert bs.index == 8
    assert bs.has_data is False


def test_read_ps_align():
    bs = ByteStream(b"ABCD\x00")
    s = bs.read_padded_string()
    assert s == "ABCD"
    assert bs.index == 8
    assert bs.has_data is False


def test_read_pus():
    bs = ByteStream(b"A\x00B\x00C\x00D\x00\x00\x00")
    s = bs.read_padded_unicode_string()
    assert s == "ABCD"
    assert bs.index == 12
    assert bs.has_data is False


def test_read_doubles():
    data = struct.pack("3d", 1.0, 2.0, 3.0)
    bs = ByteStream(data)
    x = bs.read_struct("d")[0]
    y = bs.read_struct("d")[0]
    z = bs.read_struct("d")[0]
    assert (x, y, z) == (1.0, 2.0, 3.0)
    assert bs.index == 24
    assert bs.has_data is False


if __name__ == "__main__":
    pytest.main([__file__])