Skip to content

Commit

Permalink
Add additional APCI tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
basilfx committed Dec 8, 2020
1 parent ab869bc commit 6fabfa4
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions test/telegram_tests/apci_test.py
@@ -1,5 +1,6 @@
"""Unit test for APCI objects."""
import unittest
from unittest.mock import patch

from pytest import raises
from xknx.dpt import DPTArray, DPTBinary
Expand Down Expand Up @@ -32,6 +33,33 @@ def test_resolve_class_unsupported(self):
):
APCI.resolve_class(0x03C0)

def test_calculated_length(self):
"""Test the test_calculated_length method."""
with patch("logging.Logger.warning") as mock_warn:
payload = APCI()

self.assertEqual(payload.calculated_length(), 0)
mock_warn.assert_called_with(
"'calculated_length()' not implemented for %s", "APCI"
)

def test_from_knx(self):
"""Test the test_calculated_length method."""
with patch("logging.Logger.warning") as mock_warn:
payload = APCI()
payload.from_knx(bytes())

self.assertEqual(payload, APCI())
mock_warn.assert_called_with("'from_knx()' not implemented for %s", "APCI")

def test_to_knx(self):
"""Test the test_calculated_length method."""
with patch("logging.Logger.warning") as mock_warn:
payload = APCI()

self.assertEqual(payload.to_knx(), bytes([]))
mock_warn.assert_called_with("'to_knx()' not implemented for %s", "APCI")


class TestGroupValueRead(unittest.TestCase):
"""Test class for GroupValueRead objects."""
Expand All @@ -55,6 +83,12 @@ def test_to_knx(self):

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

def test_str(self):
"""Test the __str__ method."""
payload = GroupValueRead()

self.assertEqual(str(payload), "<GroupValueRead />")


class TestGroupValueWrite(unittest.TestCase):
"""Test class for GroupValueWrite objects."""
Expand All @@ -67,6 +101,13 @@ def test_calculated_length(self):
self.assertEqual(payload_a.calculated_length(), 4)
self.assertEqual(payload_b.calculated_length(), 1)

def test_calculated_length_exception(self):
"""Test the test_calculated_length method for unsupported dpt."""
payload = GroupValueWrite(dpt=object())

with self.assertRaises(TypeError):
payload.calculated_length()

def test_from_knx(self):
"""Test the from_knx method."""
payload_a = GroupValueWrite()
Expand All @@ -88,6 +129,21 @@ def test_to_knx(self):
self.assertEqual(payload_a.to_knx(), bytes([0x00, 0x80, 0x01, 0x02, 0x03]))
self.assertEqual(payload_b.to_knx(), bytes([0x00, 0x81]))

def test_to_knx_exception(self):
"""Test the to_knx method for unsupported dpt."""
payload = GroupValueWrite(dpt=object())

with self.assertRaises(TypeError):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = GroupValueWrite(dpt=DPTBinary(1))

self.assertEqual(
str(payload), '<GroupValueWrite dpt="<DPTBinary value="1" />" />'
)


class TestGroupValueResponse(unittest.TestCase):
"""Test class for TestGroupValueResponse objects."""
Expand All @@ -100,6 +156,13 @@ def test_calculated_length(self):
self.assertEqual(payload_a.calculated_length(), 4)
self.assertEqual(payload_b.calculated_length(), 1)

def test_calculated_length_exception(self):
"""Test the test_calculated_length method for unsupported dpt."""
payload = GroupValueResponse(dpt=object())

with self.assertRaises(TypeError):
payload.calculated_length()

def test_from_knx(self):
"""Test the from_knx method."""
payload_a = GroupValueResponse()
Expand All @@ -120,3 +183,18 @@ def test_to_knx(self):

self.assertEqual(payload_a.to_knx(), bytes([0x00, 0x40, 0x01, 0x02, 0x03]))
self.assertEqual(payload_b.to_knx(), bytes([0x00, 0x41]))

def test_to_knx_exception(self):
"""Test the to_knx method for unsupported dpt."""
payload = GroupValueResponse(dpt=object())

with self.assertRaises(TypeError):
payload.to_knx()

def test_str(self):
"""Test the __str__ method."""
payload = GroupValueResponse(dpt=DPTBinary(1))

self.assertEqual(
str(payload), '<GroupValueResponse dpt="<DPTBinary value="1" />" />'
)

0 comments on commit 6fabfa4

Please sign in to comment.