Skip to content

Commit

Permalink
temp.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Mar 3, 2024
1 parent c3312be commit ac02e2a
Show file tree
Hide file tree
Showing 6 changed files with 372 additions and 359 deletions.
15 changes: 0 additions & 15 deletions test/message/test_ascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,6 @@ def prepare_frame():
return MessageAscii([1], False)


def test_check_LRC(self):
"""Test check_LRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert MessageAscii.check_LRC(data, 0x1C)

def test_check_noLRC(self):
"""Test check_LRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert not MessageAscii.check_LRC(data, 0x0C)

def test_compute_LRC(self):
"""Test compute_LRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert MessageAscii.compute_LRC(data) == 0x1c

def test_roundtrip_LRC(self):
"""Test combined compute/check LRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
Expand Down
21 changes: 21 additions & 0 deletions test/message/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest

from pymodbus.message import MessageType
from pymodbus.message.ascii import MessageAscii
from pymodbus.message.rtu import MessageRTU
from pymodbus.transport import CommParams


Expand Down Expand Up @@ -96,3 +98,22 @@ async def test_encode(self, msg, data, dev_id, tid, res_data):
"""Test decode method in all types."""
t_data = msg.msg_handle.encode(data, dev_id, tid)
assert res_data == t_data


@pytest.mark.parametrize(
("func", "lrc", "expect"),
[(MessageAscii.check_LRC, 0x1c, True),
(MessageAscii.check_LRC, 0x0c, False),
(MessageAscii.compute_LRC, None, 0x1c),
(MessageRTU.check_CRC, 0xE2DB, True),
(MessageRTU.check_CRC, 0xDBE2, False),
(MessageRTU.compute_CRC, None, 0xE2DB),
]
)
def test_LRC_CRC(self, func, lrc, expect):
"""Test check_LRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
if lrc:
assert expect == func(data, lrc)
else:
assert expect == func(data)
16 changes: 0 additions & 16 deletions test/message/test_rtu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,12 @@ def prepare_frame():
"""Return message object."""
return MessageRTU([1], False)


def test_crc16_table(self):
"""Test the crc16 table is prefilled."""
assert len(MessageRTU.crc16_table) == 256
assert isinstance(MessageRTU.crc16_table[0], int)
assert isinstance(MessageRTU.crc16_table[255], int)

def test_check_CRC(self):
"""Test check_CRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert MessageRTU.check_CRC(data, 0xE2DB)

def test_check_noCRC(self):
"""Test check_CRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert not MessageRTU.check_CRC(data, 0xDBE2)

def test_compute_CRC(self):
"""Test compute_CRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
assert MessageRTU.compute_CRC(data) == 0xE2DB

def test_roundtrip_CRC(self):
"""Test combined compute/check CRC."""
data = b'\x12\x34\x23\x45\x34\x56\x45\x67'
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ac02e2a

Please sign in to comment.