Skip to content

Commit

Permalink
Add tests for value checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
basilfx committed Dec 31, 2020
1 parent 73f32f7 commit 9836b67
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions test/telegram_tests/apci_test.py
Expand Up @@ -451,6 +451,13 @@ def test_to_knx(self):

self.assertEqual(payload.to_knx(), bytes([0x02, 0x0B, 0x12, 0x34]))

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = MemoryRead(address=0xAABBCCDD, count=11)

with self.assertRaisesRegex(ConversionError, r".*Address.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = MemoryRead(address=0x1234, count=11)
Expand Down Expand Up @@ -485,6 +492,15 @@ def test_to_knx(self):
payload.to_knx(), bytes([0x02, 0x83, 0x12, 0x34, 0xAA, 0xBB, 0xCC])
)

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = MemoryWrite(
address=0xAABBCCDD, count=3, data=bytes([0xAA, 0xBB, 0xCC])
)

with self.assertRaisesRegex(ConversionError, r".*Address.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = MemoryWrite(address=0x1234, count=3, data=bytes([0xAA, 0xBB, 0xCC]))
Expand Down Expand Up @@ -527,6 +543,15 @@ def test_to_knx(self):
payload.to_knx(), bytes([0x02, 0x43, 0x12, 0x34, 0xAA, 0xBB, 0xCC])
)

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = MemoryResponse(
address=0xAABBCCDD, count=3, data=bytes([0xAA, 0xBB, 0xCC])
)

with self.assertRaisesRegex(ConversionError, r".*Address.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = MemoryResponse(
Expand Down Expand Up @@ -560,6 +585,13 @@ def test_to_knx(self):

self.assertEqual(payload.to_knx(), bytes([0x03, 0x0D]))

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = DeviceDescriptorRead(255)

with self.assertRaisesRegex(ConversionError, r".*Descriptor.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = DeviceDescriptorRead(0)
Expand Down Expand Up @@ -589,6 +621,13 @@ def test_to_knx(self):

self.assertEqual(payload.to_knx(), bytes([0x03, 0x4D, 0x00, 0x7B]))

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = DeviceDescriptorRead(255)

with self.assertRaisesRegex(ConversionError, r".*Descriptor.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = DeviceDescriptorResponse(descriptor=0, value=123)
Expand Down Expand Up @@ -906,6 +945,15 @@ def test_to_knx(self):

self.assertEqual(payload.to_knx(), bytes([0x03, 0xD5, 0x01, 0x04, 0x20, 0x08]))

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = PropertyValueRead(
object_index=1, property_id=4, count=32, start_index=8
)

with self.assertRaisesRegex(ConversionError, r".*Count.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = PropertyValueRead(
Expand Down Expand Up @@ -951,6 +999,15 @@ def test_to_knx(self):
payload.to_knx(), bytes([0x03, 0xD7, 0x01, 0x04, 0x20, 0x08, 0x12, 0x34])
)

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = PropertyValueWrite(
object_index=1, property_id=4, count=32, start_index=8, data=b"\x12\x34"
)

with self.assertRaisesRegex(ConversionError, r".*Count.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = PropertyValueWrite(
Expand Down Expand Up @@ -996,6 +1053,15 @@ def test_to_knx(self):
payload.to_knx(), bytes([0x03, 0xD6, 0x01, 0x04, 0x20, 0x08, 0x12, 0x34])
)

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = PropertyValueResponse(
object_index=1, property_id=4, count=32, start_index=8, data=b"\x12\x34"
)

with self.assertRaisesRegex(ConversionError, r".*Count.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = PropertyValueResponse(
Expand Down Expand Up @@ -1098,6 +1164,20 @@ def test_to_knx(self):
bytes([0x03, 0xD9, 0x01, 0x04, 0x08, 0x03, 0x00, 0x05, 0x07]),
)

def test_to_knx_conversion_error(self):
"""Test the to_knx method for conversion errors."""
payload = PropertyDescriptionResponse(
object_index=1,
property_id=4,
property_index=8,
type_=3,
max_count=4096,
access=7,
)

with self.assertRaisesRegex(ConversionError, r".*Max count.*"):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = PropertyDescriptionResponse(
Expand Down

0 comments on commit 9836b67

Please sign in to comment.