Fix: bt2: duplicate test name in test_field.py
[babeltrace.git] / tests / bindings / python / bt2 / test_field.py
index 7c00b3060e0a20c9b24114db018a70db9d75562a..53906b97c065a4a5ed28eef0c5c82a62dad5334c 100644 (file)
@@ -73,7 +73,7 @@ def _create_const_field(tc, field_class, field_value_setter_fn):
     field_name = 'const field'
 
     class MyIter(bt2._UserMessageIterator):
-        def __init__(self, self_port_output):
+        def __init__(self, config, self_port_output):
             nonlocal field_class
             nonlocal field_value_setter_fn
             stream = _create_stream(tc, [(field_name, field_class)])
@@ -93,7 +93,7 @@ def _create_const_field(tc, field_class, field_value_setter_fn):
             return self._msgs.pop(0)
 
     class MySrc(bt2._UserSourceComponent, message_iterator_class=MyIter):
-        def __init__(self, params, obj):
+        def __init__(self, config, params, obj):
             self._add_output_port('out', params)
 
     graph = bt2.Graph()
@@ -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))
@@ -2144,7 +2167,7 @@ class OptionFieldTestCase(unittest.TestCase):
         self._def.has_field = True
         self.assertTrue(self._def.has_field)
 
-    def test_has_field_prop_true(self):
+    def test_has_field_prop_false(self):
         self._def.has_field = False
         self.assertFalse(self._def.has_field)
 
@@ -2152,7 +2175,7 @@ class OptionFieldTestCase(unittest.TestCase):
         self._def.value = 'allo'
         self.assertTrue(self._def)
 
-    def test_bool_op_true(self):
+    def test_bool_op_false(self):
         self._def.has_field = False
         self.assertFalse(self._def)
 
This page took 0.025376 seconds and 4 git commands to generate.