def test_to_knx_pack_error(self): """Test serializing DPT4ByteSigned with pack error.""" with patch("struct.pack") as pack_mock: pack_mock.side_effect = struct.error() with pytest.raises(ConversionError): DPT4ByteSigned.to_knx(19088743)
def test_signed_value_01234567(self): """Test DPT4ByteSigned parsing and streaming.""" assert DPT4ByteSigned.to_knx(19088743) == (0x01, 0x23, 0x45, 0x67) assert DPT4ByteSigned.from_knx((0x01, 0x23, 0x45, 0x67)) == 19088743
def test_signed_value_min_value(self): """Test DPT4ByteSigned parsing and streaming with null values.""" assert DPT4ByteSigned.to_knx(-2147483648) == (0x80, 0x00, 0x00, 0x00) assert DPT4ByteSigned.from_knx((0x80, 0x00, 0x00, 0x00)) == -2147483648
def test_signed_value_max_value(self): """Test DPT4ByteSigned parsing and streaming.""" assert DPT4ByteSigned.to_knx(2147483647) == (0x7F, 0xFF, 0xFF, 0xFF) assert DPT4ByteSigned.from_knx((0x7F, 0xFF, 0xFF, 0xFF)) == 2147483647
def test_signed_to_knx_exceed_limits(self): """Test initialization of DPT4ByteSigned with wrong value (Overflow).""" with pytest.raises(ConversionError): DPT4ByteSigned.to_knx(2147483648)
def test_signed_assert_min_exceeded(self): """Test initialization of DPT4ByteSigned with wrong value (Underflow).""" with pytest.raises(ConversionError): DPT4ByteSigned.to_knx(-2147483649)