예제 #1
0
 def test_to_knx_pack_error(self):
     """Test serializing DPT2ByteSigned with pack error."""
     with patch("struct.pack") as pack_mock:
         pack_mock.side_effect = struct.error()
         with pytest.raises(ConversionError):
             DPT2ByteSigned.to_knx(1234)
예제 #2
0
 def test_signed_wrong_value_from_knx(self):
     """Test DPT2ByteSigned parsing with wrong value."""
     with pytest.raises(ConversionError):
         DPT2ByteSigned.from_knx((0xFF, 0x4E, 0x12))
예제 #3
0
 def test_from_knx_unpack_error(self):
     """Test DPT2ByteSigned parsing with unpack error."""
     with patch("struct.unpack") as unpack_mock:
         unpack_mock.side_effect = struct.error()
         with pytest.raises(ConversionError):
             DPT2ByteSigned.from_knx((0x01, 0x23))
예제 #4
0
 def test_signed_value_min_value(self):
     """Test DPT2ByteSigned parsing and streaming with null values."""
     assert DPT2ByteSigned.to_knx(-20480) == (0xB0, 0x00)
     assert DPT2ByteSigned.from_knx((0xB0, 0x00)) == -20480
예제 #5
0
 def test_signed_value_0123(self):
     """Test DPT2ByteSigned parsing and streaming."""
     assert DPT2ByteSigned.to_knx(291) == (0x01, 0x23)
     assert DPT2ByteSigned.from_knx((0x01, 0x23)) == 291
예제 #6
0
 def test_signed_to_knx_exceed_limits(self):
     """Test initialization of DPT2ByteSigned with wrong value (Overflow)."""
     with pytest.raises(ConversionError):
         DPT2ByteSigned.to_knx(32768)
예제 #7
0
 def test_signed_value_max_value(self):
     """Test DPT2ByteSigned parsing and streaming."""
     assert DPT2ByteSigned.to_knx(32767) == (0x7F, 0xFF)
     assert DPT2ByteSigned.from_knx((0x7F, 0xFF)) == 32767
예제 #8
0
 def test_to_knx_pack_error(self):
     """Test serializing DPT2ByteSigned with pack error."""
     with patch('struct.pack') as packMock:
         packMock.side_effect = struct.error()
         with self.assertRaises(ConversionError):
             DPT2ByteSigned().to_knx(1234)
예제 #9
0
 def test_signed_assert_min_exceeded(self):
     """Test initialization of DPT2ByteSigned with wrong value (Underflow)."""
     with pytest.raises(ConversionError):
         DPT2ByteSigned.to_knx(-32769)
예제 #10
0
 def test_from_knx_unpack_error(self):
     """Test DPT2ByteSigned parsing with unpack error."""
     with patch('struct.unpack') as unpackMock:
         unpackMock.side_effect = struct.error()
         with self.assertRaises(ConversionError):
             DPT2ByteSigned().from_knx((0x01, 0x23))
예제 #11
0
 def test_signed_value_0123(self):
     """Test DPT2ByteSigned parsing and streaming."""
     self.assertEqual(DPT2ByteSigned().to_knx(291), (0x01, 0x23))
     self.assertEqual(DPT2ByteSigned().from_knx((0x01, 0x23)), 291)
예제 #12
0
 def test_signed_value_min_value(self):
     """Test DPT2ByteSigned parsing and streaming with null values."""
     self.assertEqual(DPT2ByteSigned().to_knx(-20480), (0xB0, 0x00))
     self.assertEqual(DPT2ByteSigned().from_knx((0xB0, 0x00)), -20480)
예제 #13
0
 def test_signed_value_max_value(self):
     """Test DPT2ByteSigned parsing and streaming."""
     self.assertEqual(DPT2ByteSigned().to_knx(32767), (0x7F, 0xFF))
     self.assertEqual(DPT2ByteSigned().from_knx((0x7F, 0xFF)), 32767)
예제 #14
0
 def test_signed_settings(self):
     """Test members of DPT2ByteSigned."""
     self.assertEqual(DPT2ByteSigned().value_min, -32768)
     self.assertEqual(DPT2ByteSigned().value_max, 32767)