+ def test_append_element_invalid_ranges(self):
+ sub_fc = self._tc.create_string_field_class()
+
+ with self.assertRaises(TypeError):
+ self._fc.append_option(self._fc, sub_fc, 'lel')
+
+ def test_append_element_dup_name(self):
+ sub_fc1 = self._tc.create_string_field_class()
+ sub_fc2 = self._tc.create_string_field_class()
+
+ with self.assertRaises(ValueError):
+ self._fc.append_option('yes', sub_fc1, self._ranges1)
+ self._fc.append_option('yes', sub_fc2, self._ranges2)
+
+ def test_append_element_invalid_ranges_signedness(self):
+ sub_fc = self._tc.create_string_field_class()
+
+ with self.assertRaises(TypeError):
+ self._fc.append_option(self._fc, sub_fc, self._inval_ranges)
+
+ def test_iadd(self):
+ other_fc = self._create_default_fc()
+ a_field_class = self._tc.create_real_field_class()
+ self._fc.append_option('a_float', a_field_class, self._ranges1)
+ c_field_class = self._tc.create_string_field_class()
+ d_field_class = self._tc.create_signed_enumeration_field_class(
+ field_value_range=32
+ )
+ self._fc += [
+ ('c_string', c_field_class, self._ranges2),
+ ('d_enum', d_field_class, self._ranges3),
+ ]
+ self.assertEqual(self._fc['a_float'].field_class.addr, a_field_class.addr)
+ self.assertEqual(self._fc['a_float'].name, 'a_float')
+ self.assertEqual(self._fc['a_float'].ranges, self._ranges1)
+ self.assertEqual(self._fc['c_string'].field_class.addr, c_field_class.addr)
+ self.assertEqual(self._fc['c_string'].name, 'c_string')
+ self.assertEqual(self._fc['c_string'].ranges, self._ranges2)
+ self.assertEqual(self._fc['d_enum'].field_class.addr, d_field_class.addr)
+ self.assertEqual(self._fc['d_enum'].name, 'd_enum')
+ self.assertEqual(self._fc['d_enum'].ranges, self._ranges3)
+
+ def test_bool_op(self):
+ self.assertFalse(self._fc)
+ self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1)
+ self.assertTrue(self._fc)
+
+ def test_len(self):
+ self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1)
+ self._fc.append_option('b', self._tc.create_string_field_class(), self._ranges2)
+ self._fc.append_option('c', self._tc.create_string_field_class(), self._ranges3)
+ self.assertEqual(len(self._fc), 3)
+
+ def test_getitem(self):
+ a_fc = self._tc.create_signed_integer_field_class(32)
+ b_fc = self._tc.create_string_field_class()
+ c_fc = self._tc.create_real_field_class()
+ self._fc.append_option('a', a_fc, self._ranges1)
+ self._fc.append_option('b', b_fc, self._ranges2)
+ self._fc.append_option('c', c_fc, self._ranges3)
+ self.assertEqual(self._fc['b'].field_class.addr, b_fc.addr)
+ self.assertEqual(self._fc['b'].name, 'b')
+ self.assertEqual(self._fc['b'].ranges.addr, self._ranges2.addr)
+
+ def test_getitem_invalid_key_type(self):
+ with self.assertRaises(TypeError):
+ self._fc[0]
+
+ def test_getitem_invalid_key(self):
+ with self.assertRaises(KeyError):
+ self._fc['no way']
+
+ def test_contains(self):
+ self.assertFalse('a' in self._fc)
+ self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1)
+ self.assertTrue('a' in self._fc)
+
+ def test_iter(self):
+ a_fc = self._tc.create_signed_integer_field_class(32)
+ b_fc = self._tc.create_string_field_class()
+ c_fc = self._tc.create_real_field_class()
+ opts = (
+ ('a', a_fc, self._ranges1),
+ ('b', b_fc, self._ranges2),
+ ('c', c_fc, self._ranges3),
+ )
+
+ for opt in opts:
+ self._fc.append_option(*opt)
+
+ for (name, opt), test_opt in zip(self._fc.items(), opts):
+ self.assertEqual(opt.name, test_opt[0])
+ self.assertEqual(name, opt.name)
+ self.assertEqual(opt.field_class.addr, test_opt[1].addr)
+ self.assertEqual(opt.ranges.addr, test_opt[2].addr)
+
+ def test_at_index(self):
+ a_fc = self._tc.create_signed_integer_field_class(32)
+ b_fc = self._tc.create_string_field_class()
+ c_fc = self._tc.create_real_field_class()
+ self._fc.append_option('c', c_fc, self._ranges1)
+ self._fc.append_option('a', a_fc, self._ranges2)
+ self._fc.append_option('b', b_fc, self._ranges3)
+ self.assertEqual(self._fc.option_at_index(1).field_class.addr, a_fc.addr)
+ self.assertEqual(self._fc.option_at_index(1).name, 'a')
+ self.assertEqual(self._fc.option_at_index(1).ranges.addr, self._ranges2.addr)
+
+ def test_at_index_invalid(self):
+ self._fc.append_option(
+ 'c', self._tc.create_signed_integer_field_class(32), self._ranges3
+ )
+
+ with self.assertRaises(TypeError):
+ self._fc.option_at_index('yes')
+
+ def test_at_index_out_of_bounds_after(self):
+ self._fc.append_option(
+ 'c', self._tc.create_signed_integer_field_class(32), self._ranges3
+ )
+
+ with self.assertRaises(IndexError):
+ self._fc.option_at_index(len(self._fc))
+
+ def _fill_default_fc_for_field_path_test(self):