Removed str type from bitstream (str is ambiguous)
This commit is contained in:
@@ -38,11 +38,11 @@ def test_from_int(value: int, length: int, expected: int):
|
||||
[True, False, False, True, True],
|
||||
[[True], [False, True], [False, False]],
|
||||
[b"a", b"bc"],
|
||||
["aa", "b"],
|
||||
[b"aa", b"b"],
|
||||
[Bitstream.from_bytes(b"A"), Bitstream.from_int(0b1011, 4), Bitstream.from_bytes(b"B")],
|
||||
[True, b"A", "B", [False, True], Bitstream.from_int(0b10110, 5), False],
|
||||
[True, b"A", b"B", [False, True], Bitstream.from_int(0b10110, 5), False],
|
||||
])
|
||||
def test_init(values: List[Union[bool, List[bool], bytes, str, Bitstream]]):
|
||||
def test_init(values: List[Union[bool, List[bool], bytes, Bitstream]]):
|
||||
bitstream = Bitstream(*values)
|
||||
|
||||
bitstream.seek(0)
|
||||
@@ -79,10 +79,9 @@ def test_getitem_index_error():
|
||||
True,
|
||||
[True, True],
|
||||
b"A",
|
||||
"B",
|
||||
Bitstream(True, b"C"),
|
||||
])
|
||||
def test_setitem(value: Union[bool, List[bool], bytes, str, Bitstream]):
|
||||
def test_setitem(value: Union[bool, List[bool], bytes, Bitstream]):
|
||||
bit_length = get_bit_length(value)
|
||||
read_type = bool if type(value) is list else type(value)
|
||||
for length in range(10):
|
||||
@@ -111,13 +110,8 @@ def test_setitem(value: Union[bool, List[bool], bytes, str, Bitstream]):
|
||||
),
|
||||
(
|
||||
b"A",
|
||||
[b"A", "A", Bitstream.from_bytes(b"A"), Bitstream.from_bytes(b"A").bits],
|
||||
[[], [False], b"B", "B", Bitstream.from_bytes(b"B"), Bitstream.from_bytes(b"B").bits]
|
||||
),
|
||||
(
|
||||
"B",
|
||||
[b"B", "B", Bitstream.from_bytes(b"B"), Bitstream.from_bytes(b"B").bits],
|
||||
[[], [False], b"A", "A", Bitstream.from_bytes(b"A"), Bitstream.from_bytes(b"A").bits]
|
||||
[b"A", b"A", Bitstream.from_bytes(b"A"), Bitstream.from_bytes(b"A").bits],
|
||||
[[], [False], b"B", b"B", Bitstream.from_bytes(b"B"), Bitstream.from_bytes(b"B").bits]
|
||||
),
|
||||
(
|
||||
b"ABC",
|
||||
@@ -126,9 +120,9 @@ def test_setitem(value: Union[bool, List[bool], bytes, str, Bitstream]):
|
||||
),
|
||||
])
|
||||
def test_eq(
|
||||
value: Union[bool, List[bool], bytes, str, Bitstream],
|
||||
equals: List[Union[bool, List[bool], bytes, str, Bitstream]],
|
||||
not_equals: List[Union[bool, List[bool], bytes, str, Bitstream]]):
|
||||
value: Union[bool, List[bool], bytes, Bitstream],
|
||||
equals: List[Union[bool, List[bool], bytes, Bitstream]],
|
||||
not_equals: List[Union[bool, List[bool], bytes, Bitstream]]):
|
||||
bitstream = Bitstream(value)
|
||||
for equal in equals:
|
||||
assert bitstream == equal
|
||||
@@ -143,9 +137,9 @@ def test_eq(
|
||||
([False], 3, [False, False, False]),
|
||||
])
|
||||
def test_mul(
|
||||
values: Union[bool, List[bool], bytes, str, Bitstream],
|
||||
values: Union[bool, List[bool], bytes, Bitstream],
|
||||
number: int,
|
||||
expected: Union[List[bool], bytes, str, Bitstream]):
|
||||
expected: Union[List[bool], bytes, Bitstream]):
|
||||
bitstream = Bitstream(values)
|
||||
|
||||
assert (bitstream * number) == expected
|
||||
@@ -161,9 +155,9 @@ def test_mul(
|
||||
(b"A", b"B", b"AB"),
|
||||
])
|
||||
def test_add(
|
||||
init_values: Union[bool, List[bool], bytes, str, Bitstream],
|
||||
add_value: Union[bool, List[bool], bytes, str, Bitstream],
|
||||
expected: Union[List[bool], bytes, str, Bitstream]):
|
||||
init_values: Union[bool, List[bool], bytes, Bitstream],
|
||||
add_value: Union[bool, List[bool], bytes, Bitstream],
|
||||
expected: Union[List[bool], bytes, Bitstream]):
|
||||
bitstream = Bitstream(init_values)
|
||||
|
||||
assert (bitstream + add_value) == expected
|
||||
@@ -179,7 +173,7 @@ def test_add(
|
||||
[b"A"],
|
||||
[True, b"B"],
|
||||
])
|
||||
def test_iter(init_values: List[Union[bool, List[bool], bytes, str, Bitstream]]):
|
||||
def test_iter(init_values: List[Union[bool, List[bool], bytes, Bitstream]]):
|
||||
bitstream = Bitstream(*init_values)
|
||||
assert len(list(bitstream)) == len(bitstream)
|
||||
for index, bit in enumerate(bitstream):
|
||||
@@ -194,7 +188,7 @@ def test_iter(init_values: List[Union[bool, List[bool], bytes, str, Bitstream]])
|
||||
([[False] * 7, True], b"\x01"),
|
||||
])
|
||||
def test_bytes(
|
||||
init_values: List[Union[bool, List[bool], bytes, str, Bitstream]],
|
||||
init_values: List[Union[bool, List[bool], bytes, Bitstream]],
|
||||
expected: bytes):
|
||||
assert bytes(Bitstream(*init_values)) == expected
|
||||
|
||||
@@ -207,7 +201,7 @@ def test_bytes(
|
||||
([False] * 7 + [True], [False] * 7 + [True]),
|
||||
])
|
||||
def test_bits(
|
||||
init_values: List[Union[bool, List[bool], bytes, str, Bitstream]],
|
||||
init_values: List[Union[bool, List[bool], bytes, Bitstream]],
|
||||
expected: List[bool]):
|
||||
assert Bitstream(*init_values).bits == expected
|
||||
|
||||
@@ -236,10 +230,10 @@ def test_append(lst: List[bool]):
|
||||
@pytest.mark.parametrize("extend_value", [
|
||||
[True, False, True],
|
||||
b"A",
|
||||
"B",
|
||||
b"BB",
|
||||
Bitstream(True, b"C"),
|
||||
])
|
||||
def test_extend(extend_value: Union[List[bool], bytes, str, Bitstream]):
|
||||
def test_extend(extend_value: Union[List[bool], bytes, Bitstream]):
|
||||
for i in range(10):
|
||||
bitstream = Bitstream([False] * i)
|
||||
bitstream.extend(extend_value)
|
||||
@@ -304,11 +298,6 @@ def test_read():
|
||||
bytes, 8, 1,
|
||||
b"A"
|
||||
),
|
||||
(
|
||||
Bitstream(True, b"A", False, True, False),
|
||||
str, 8, 1,
|
||||
"A"
|
||||
),
|
||||
(
|
||||
Bitstream(True, b"A", False, True, False),
|
||||
Bitstream, 1 + 8 + 3, 0,
|
||||
@@ -322,10 +311,10 @@ def test_read():
|
||||
])
|
||||
def test_read_index(
|
||||
bitstream: Bitstream,
|
||||
read_type: Type[Union[bool, bytes, str, Bitstream, int]],
|
||||
read_type: Type[Union[bool, bytes, Bitstream, int]],
|
||||
bit_length: int,
|
||||
bit_index: Optional[int],
|
||||
expected: Union[List[bool], bytes, str, Bitstream, int]):
|
||||
expected: Union[List[bool], bytes, Bitstream, int]):
|
||||
value = bitstream.read(read_type, bit_length, bit_index)
|
||||
|
||||
if read_type is bool:
|
||||
@@ -360,7 +349,7 @@ def test_read_error():
|
||||
(Bitstream(False), True, 0, 0),
|
||||
(Bitstream(False), True, None, 0),
|
||||
])
|
||||
def test_write(bitstream: Bitstream, value: Union[bool, List[bool], bytes, str, Bitstream], bit_index: Optional[int], current_offset: Optional[int]):
|
||||
def test_write(bitstream: Bitstream, value: Union[bool, List[bool], bytes, Bitstream], bit_index: Optional[int], current_offset: Optional[int]):
|
||||
if current_offset is not None:
|
||||
bitstream.seek(current_offset)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user