2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2015-03-02 01:56:47 +03:00
|
|
|
from PIL import _binary
|
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_standard() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
assert _binary.i8(b"*") == 42
|
|
|
|
assert _binary.o8(42) == b"*"
|
2015-04-24 02:26:52 +03:00
|
|
|
|
2015-03-02 01:56:47 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_little_endian() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
assert _binary.i16le(b"\xff\xff\x00\x00") == 65535
|
|
|
|
assert _binary.i32le(b"\xff\xff\x00\x00") == 65535
|
2015-04-24 02:26:52 +03:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
assert _binary.o16le(65535) == b"\xff\xff"
|
|
|
|
assert _binary.o32le(65535) == b"\xff\xff\x00\x00"
|
2015-03-02 01:56:47 +03:00
|
|
|
|
2015-04-24 02:26:52 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_big_endian() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
assert _binary.i16be(b"\x00\x00\xff\xff") == 0
|
|
|
|
assert _binary.i32be(b"\x00\x00\xff\xff") == 65535
|
|
|
|
|
|
|
|
assert _binary.o16be(65535) == b"\xff\xff"
|
|
|
|
assert _binary.o32be(65535) == b"\x00\x00\xff\xff"
|