Skip to content

Commit

Permalink
test change
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanov committed Jul 17, 2024
1 parent 7049cc2 commit 9ef905c
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tests/test_num_serializer.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import io

from pyftms.serializer import NumSerializer, SupportedNumbers, get_serializer
import pytest

_NUM_TESTS: tuple[tuple[str, SupportedNumbers, bytes], ...] = (
("u1", 128, b"\x80"),
("u2", 128, b"\x80\x00"),
("u3", 128, b"\x80\x00\x00"),
("u1.1", 12.8, b"\x80"),
("u2.1", 12.8, b"\x80\x00"),
("u3.1", 12.8, b"\x80\x00\x00"),
("s1", -128, b"\x80"),
("s2", -128, b"\x80\xff"),
("s3", -128, b"\x80\xff\xff"),
("s1.1", -12.8, b"\x80"),
("s2.1", -12.8, b"\x80\xff"),
("s3.1", -12.8, b"\x80\xff\xff"),
("u2", None, b"\xff\xff"),
("u2.1", None, b"\xff\xff"),
("s2", None, b"\xff\x7f"),
("s2.1", None, b"\xff\x7f"),
)
from pyftms.serializer import NumSerializer, SupportedNumbers, get_serializer


def _test(fmt: str, num: SupportedNumbers, buf: bytes):
@pytest.mark.parametrize(
"fmt,num,buf",
[
("u1", 128, b"\x80"),
("u2", 128, b"\x80\x00"),
("u3", 128, b"\x80\x00\x00"),
("u1.1", 12.8, b"\x80"),
("u2.1", 12.8, b"\x80\x00"),
("u3.1", 12.8, b"\x80\x00\x00"),
("s1", -128, b"\x80"),
("s2", -128, b"\x80\xff"),
("s3", -128, b"\x80\xff\xff"),
("s1.1", -12.8, b"\x80"),
("s2.1", -12.8, b"\x80\xff"),
("s3.1", -12.8, b"\x80\xff\xff"),
("u2", None, b"\xff\xff"),
("u2.1", None, b"\xff\xff"),
("s2", None, b"\xff\x7f"),
("s2.1", None, b"\xff\x7f"),
],
)
def test_num_serializer(fmt: str, num: SupportedNumbers, buf: bytes):
s = get_serializer(fmt)

assert isinstance(s, NumSerializer)
Expand All @@ -33,8 +37,3 @@ def _test(fmt: str, num: SupportedNumbers, buf: bytes):
sz = s.serialize(bio, num)
assert sz == s.get_size() and sz == len(buf)
assert bio.getvalue() == buf


def test_num_serializer():
for data in _NUM_TESTS:
_test(*data)

0 comments on commit 9ef905c

Please sign in to comment.