X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_field.py;h=ecf0194c3b7d589b036a82bf364f17e26a9e8be8;hp=7c00b3060e0a20c9b24114db018a70db9d75562a;hb=1198c63595288e43f354d8cce6db1e69a38d3a20;hpb=9494fc18a57a8c7696d67e9deb783d61c4ee2cfd diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index 7c00b306..ecf0194c 100644 --- a/tests/bindings/python/bt2/test_field.py +++ b/tests/bindings/python/bt2/test_field.py @@ -1284,12 +1284,35 @@ class _TestIntegerFieldCommon(_TestNumericField): field.value = (2 ** 53) + 1 self.assertEqual(field, raw) - def test_assign_uint_invalid_neg(self): - uint_fc = self._tc.create_unsigned_integer_field_class(32) + def test_assign_uint_out_of_range(self): + uint_fc = self._tc.create_unsigned_integer_field_class(8) field = _create_field(self._tc, uint_fc) - with self.assertRaises(ValueError): - field.value = -23 + 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]' + ) def test_str_op(self): self.assertEqual(str(self._def), str(self._def_value))