Add tests for jeb_utils.utils.byte_to_bits

This commit is contained in:
2026-04-02 14:11:25 +02:00
parent 33e6f0adb9
commit 91696ad034
+28
View File
@@ -0,0 +1,28 @@
from src.jeb_utils.utils import byte_to_bits
import pytest
@pytest.mark.parametrize('b,expected', [
(b'\x00', (0, 0, 0, 0, 0, 0, 0, 0)),
(b'\x01', (0, 0, 0, 0, 0, 0, 0, 1)),
(b'\x80', (1, 0, 0, 0, 0, 0, 0, 0)),
(b'\xf0', (1, 1, 1, 1, 0, 0, 0, 0)),
(b'\xff', (1, 1, 1, 1, 1, 1, 1, 1)),
])
def test_byte_to_bits(b, expected):
assert byte_to_bits(b) == expected
@pytest.mark.parametrize('b,expected_exception', [
(b'\x00\x00', ValueError),
(b'\x00\x01', ValueError),
(b'\x01\x00', ValueError),
(b'\xff\xff', ValueError),
(b'\xff\x00', ValueError),
(b'\x00\xff', ValueError),
(b'\x42\x2a', ValueError),
(b'\x00\x42\x2a', ValueError),
(b'\x25\x42\x2a', ValueError),
(b'Hello, World!', ValueError),
])
def test_byte_to_bits(b, expected_exception):
with pytest.raises(expected_exception):
byte_to_bits(b)