-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import struct | ||
import pytest | ||
|
||
from umodbus.client.serial.redundancy_check import get_crc, validate_crc | ||
|
||
|
||
def test_get_crc(): | ||
""" Test if correct CRC is calculated. """ | ||
# Values are equal to those used in example in MODBUS over serial line | ||
# specification and implementation guide V1.02, chapter 6.2.2. | ||
assert struct.unpack('<H', get_crc(b'\x02\x07')) ==\ | ||
struct.unpack('<H', b'\x41\x12') | ||
|
||
|
||
def test_validate_valid_crc(): | ||
"""" Method should not raise assertion error. """ | ||
validate_crc(b'\x02\x07', b'\x41\x12') | ||
|
||
|
||
def test_validate_invalid_crc(): | ||
"""" Method should raise assertion error. """ | ||
with pytest.raises(AssertionError): | ||
validate_crc(b'\x02\x07', b'\x41\x11') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters