File: tunnelling_ack_test.py

package info (click to toggle)
python-xknx 3.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,064 kB
  • sloc: python: 40,895; javascript: 8,556; makefile: 32; sh: 12
file content (40 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Unit test for KNX/IP TunnellingAck objects."""

import pytest

from xknx.exceptions import CouldNotParseKNXIP
from xknx.knxip import ErrorCode, KNXIPFrame, TunnellingAck


class TestKNXIPTunnellingAck:
    """Test class for KNX/IP TunnellingAck objects."""

    def test_tunnelling_ack(self) -> None:
        """Test parsing and streaming tunneling ACK KNX/IP packet."""
        raw = bytes((0x06, 0x10, 0x04, 0x21, 0x00, 0x0A, 0x04, 0x2A, 0x17, 0x00))
        knxipframe, _ = KNXIPFrame.from_knx(raw)

        assert isinstance(knxipframe.body, TunnellingAck)
        assert knxipframe.body.communication_channel_id == 42
        assert knxipframe.body.sequence_counter == 23
        assert knxipframe.body.status_code == ErrorCode.E_NO_ERROR

        tunnelling_ack = TunnellingAck(
            communication_channel_id=42,
            sequence_counter=23,
        )
        knxipframe2 = KNXIPFrame.init_from_body(tunnelling_ack)

        assert knxipframe2.to_knx() == raw

    def test_from_knx_wrong_ack_information(self) -> None:
        """Test parsing and streaming wrong TunnellingAck (wrong length byte)."""
        raw = bytes((0x06, 0x10, 0x04, 0x21, 0x00, 0x0A, 0x03, 0x2A, 0x17, 0x00))
        with pytest.raises(CouldNotParseKNXIP):
            KNXIPFrame.from_knx(raw)

    def test_from_knx_wrong_ack_information2(self) -> None:
        """Test parsing and streaming wrong TunnellingAck (wrong length)."""
        raw = bytes((0x06, 0x10, 0x04, 0x21, 0x00, 0x0A, 0x04, 0x2A, 0x17))
        with pytest.raises(CouldNotParseKNXIP):
            KNXIPFrame.from_knx(raw)