Esempio 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)
Esempio 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))
Esempio 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))
Esempio 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
Esempio 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
Esempio 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)
Esempio 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
Esempio 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)
Esempio 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)
Esempio 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)
Esempio 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)
Esempio n. 12
0
 def test_signed_settings(self):
     """Test members of DPT4ByteSigned."""
     self.assertEqual(DPT4ByteSigned().value_min, -2147483648)
     self.assertEqual(DPT4ByteSigned().value_max, 2147483647)
Esempio 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)
Esempio 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))