Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 def test_signed_wrong_value_from_knx(self):
     """Test DPT4ByteSigned parsing with wrong value."""
     with pytest.raises(ConversionError):
         DPT4ByteSigned.from_knx((0xFF, 0x4E, 0x12))
Exemplo n.º 3
0
 def test_from_knx_unpack_error(self):
     """Test DPT4ByteSigned parsing with unpack error."""
     with patch("struct.unpack") as unpack_mock:
         unpack_mock.side_effect = struct.error()
         with pytest.raises(ConversionError):
             DPT4ByteSigned.from_knx((0x01, 0x23, 0x45, 0x67))
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 def test_signed_to_knx_exceed_limits(self):
     """Test initialization of DPT4ByteSigned with wrong value (Overflow)."""
     with pytest.raises(ConversionError):
         DPT4ByteSigned.to_knx(2147483648)
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 def test_signed_value_01234567(self):
     """Test DPT4ByteSigned parsing and streaming."""
     self.assertEqual(DPT4ByteSigned().to_knx(19088743),
                      (0x01, 0x23, 0x45, 0x67))
     self.assertEqual(DPT4ByteSigned().from_knx((0x01, 0x23, 0x45, 0x67)),
                      19088743)
Exemplo n.º 9
0
 def test_signed_assert_min_exceeded(self):
     """Test initialization of DPT4ByteSigned with wrong value (Underflow)."""
     with pytest.raises(ConversionError):
         DPT4ByteSigned.to_knx(-2147483649)
Exemplo n.º 10
0
 def test_signed_value_min_value(self):
     """Test DPT4ByteSigned parsing and streaming with null values."""
     self.assertEqual(DPT4ByteSigned().to_knx(-2147483648),
                      (0x80, 0x00, 0x00, 0x00))
     self.assertEqual(DPT4ByteSigned().from_knx((0x80, 0x00, 0x00, 0x00)),
                      -2147483648)
Exemplo n.º 11
0
 def test_signed_value_max_value(self):
     """Test DPT4ByteSigned parsing and streaming."""
     self.assertEqual(DPT4ByteSigned().to_knx(2147483647),
                      (0x7F, 0xFF, 0xFF, 0xFF))
     self.assertEqual(DPT4ByteSigned().from_knx((0x7F, 0xFF, 0xFF, 0xFF)),
                      2147483647)
Exemplo n.º 12
0
 def test_signed_settings(self):
     """Test members of DPT4ByteSigned."""
     self.assertEqual(DPT4ByteSigned().value_min, -2147483648)
     self.assertEqual(DPT4ByteSigned().value_max, 2147483647)
Exemplo n.º 13
0
 def test_to_knx_pack_error(self):
     """Test serializing DPT4ByteSigned with pack error."""
     with patch('struct.pack') as packMock:
         packMock.side_effect = struct.error()
         with self.assertRaises(ConversionError):
             DPT4ByteSigned().to_knx(19088743)
Exemplo n.º 14
0
 def test_from_knx_unpack_error(self):
     """Test DPT4ByteSigned parsing with unpack error."""
     with patch('struct.unpack') as unpackMock:
         unpackMock.side_effect = struct.error()
         with self.assertRaises(ConversionError):
             DPT4ByteSigned().from_knx((0x01, 0x23, 0x45, 0x67))