+ with self.assertRaises(ValueError) as ctx:
+ field.value = 256
+ self.assertEqual(
+ str(ctx.exception), 'Value 256 is outside valid range [0, 255]'
+ )
+
+ with self.assertRaises(ValueError) as ctx:
+ field.value = -1
+ self.assertEqual(str(ctx.exception), 'Value -1 is outside valid range [0, 255]')
+
+ def test_assign_int_out_of_range(self):
+ int_fc = self._tc.create_signed_integer_field_class(8)
+ field = _create_field(self._tc, int_fc)
+
+ with self.assertRaises(ValueError) as ctx:
+ field.value = 128
+ self.assertEqual(
+ str(ctx.exception), 'Value 128 is outside valid range [-128, 127]'
+ )
+
+ with self.assertRaises(ValueError) as ctx:
+ field.value = -129
+ self.assertEqual(
+ str(ctx.exception), 'Value -129 is outside valid range [-128, 127]'
+ )