X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_field.py;h=f92142bc13518b3f5c8e18fc0ce4c24b8f1fee96;hb=45c51519900e100d9acda4acb9516ef69bc2d045;hp=f6fc4ca3037e0229eefa3abbdde5018278a8c8cb;hpb=7bb4180f2758d78af3f4d539f6b3e4e1fa60335f;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index f6fc4ca3..f92142bc 100644 --- a/tests/bindings/python/bt2/test_field.py +++ b/tests/bindings/python/bt2/test_field.py @@ -22,6 +22,7 @@ import unittest import math import copy import itertools +import collections import bt2 from utils import get_default_trace_class @@ -43,7 +44,8 @@ def _create_stream(tc, ctx_field_classes): packet_context_fc.append_member(name, fc) trace = tc() - stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc) + stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc, + supports_packets=True) stream = trace.create_stream(stream_class) return stream @@ -120,56 +122,90 @@ def _create_struct_array_field(tc, length): return packet.context_field[field_name] +# Base class for numeric field test cases. +# +# To be compatible with this base class, a derived class must, in its +# setUp() method: +# +# * Set `self._def` to a field object with an arbitrary value. +# * Set `self._def_value` to the equivalent value of `self._def`. class _TestNumericField: + # Tries the binary operation `op`: + # + # 1. Between `self._def`, which is a field object, and `rhs`. + # 2. Between `self._def_value`, which is the raw value of + # `self._def`, and `rhs`. + # + # Returns the results of 1. and 2. + # + # If there's an exception while performing 1. or 2., asserts that + # both operations raised exceptions, that both exceptions have the + # same type, and returns `None` for both results. def _binop(self, op, rhs): - rexc = None - rvexc = None + type_rexc = None + type_rvexc = None comp_value = rhs + # try with field object try: r = op(self._def, rhs) except Exception as e: - rexc = e + type_rexc = type(e) + # try with value try: rv = op(self._def_value, comp_value) except Exception as e: - rvexc = e + type_rvexc = type(e) - if rexc is not None or rvexc is not None: + if type_rexc is not None or type_rvexc is not None: # at least one of the operations raised an exception: in # this case both operations should have raised the same # type of exception (division by zero, bit shift with a # floating point number operand, etc.) - self.assertIs(type(rexc), type(rvexc)) + self.assertIs(type_rexc, type_rvexc) return None, None return r, rv + # Tries the unary operation `op`: + # + # 1. On `self._def`, which is a field object. + # 2. On `self._def_value`, which is the value of `self._def`. + # + # Returns the results of 1. and 2. + # + # If there's an exception while performing 1. or 2., asserts that + # both operations raised exceptions, that both exceptions have the + # same type, and returns `None` for both results. def _unaryop(self, op): - rexc = None - rvexc = None + type_rexc = None + type_rvexc = None + # try with field object try: r = op(self._def) except Exception as e: - rexc = e + type_rexc = type(e) + # try with value try: rv = op(self._def_value) except Exception as e: - rvexc = e + type_rvexc = type(e) - if rexc is not None or rvexc is not None: + if type_rexc is not None or type_rvexc is not None: # at least one of the operations raised an exception: in # this case both operations should have raised the same # type of exception (division by zero, bit shift with a # floating point number operand, etc.) - self.assertIs(type(rexc), type(rvexc)) + self.assertIs(type_rexc, type_rvexc) return None, None return r, rv + # Tests that the unary operation `op` gives results with the same + # type for both `self._def` and `self._def_value`. def _test_unaryop_type(self, op): r, rv = self._unaryop(op) @@ -178,6 +214,9 @@ class _TestNumericField: self.assertIsInstance(r, type(rv)) + # Tests that the unary operation `op` gives results with the same + # value for both `self._def` and `self._def_value`. This uses the + # __eq__() operator of `self._def`. def _test_unaryop_value(self, op): r, rv = self._unaryop(op) @@ -186,16 +225,22 @@ class _TestNumericField: self.assertEqual(r, rv) + # Tests that the unary operation `op`, when applied to `self._def`, + # does not change its underlying BT object address. def _test_unaryop_addr_same(self, op): addr_before = self._def.addr self._unaryop(op) self.assertEqual(self._def.addr, addr_before) + # Tests that the unary operation `op`, when applied to `self._def`, + # does not change its value. def _test_unaryop_value_same(self, op): value_before = copy.copy(self._def_value) self._unaryop(op) self.assertEqual(self._def, value_before) + # Tests that the binary operation `op` gives results with the same + # type for both `self._def` and `self._def_value`. def _test_binop_type(self, op, rhs): r, rv = self._binop(op, rhs) @@ -208,6 +253,9 @@ class _TestNumericField: else: self.assertIsInstance(r, type(rv)) + # Tests that the binary operation `op` gives results with the same + # value for both `self._def` and `self._def_value`. This uses the + # __eq__() operator of `self._def`. def _test_binop_value(self, op, rhs): r, rv = self._binop(op, rhs) @@ -216,17 +264,36 @@ class _TestNumericField: self.assertEqual(r, rv) + # Tests that the binary operation `op`, when applied to `self._def`, + # does not change its underlying BT object address. def _test_binop_lhs_addr_same(self, op, rhs): addr_before = self._def.addr r, rv = self._binop(op, rhs) self.assertEqual(self._def.addr, addr_before) + # Tests that the binary operation `op`, when applied to `self._def`, + # does not change its value. @unittest.skip('copy is not implemented') def _test_binop_lhs_value_same(self, op, rhs): value_before = copy.copy(self._def) r, rv = self._binop(op, rhs) self.assertEqual(self._def, value_before) + # The methods below which take the `test_cb` and/or `op` parameters + # are meant to be used with one of the _test_binop_*() functions + # above as `test_cb` and a binary operator function as `op`. + # + # For example: + # + # self._test_binop_rhs_pos_int(self._test_binop_value, + # operator.add) + # + # This tests that a numeric field object added to a positive integer + # value gives a result with the expected value. + # + # `vint` and `vfloat` mean a signed integer value object and a real + # value object. + def _test_binop_invalid_unknown(self, op): if op in _COMP_BINOPS: self.skipTest('not testing') @@ -244,54 +311,6 @@ class _TestNumericField: with self.assertRaises(TypeError): op(self._def, None) - def _test_ibinop_value(self, op, rhs): - r, rv = self._binop(op, rhs) - - if r is None: - return - - # The inplace operators are special for field objects because - # they do not return a new, immutable object like it's the case - # for Python numbers. In Python, `a += 2`, where `a` is a number - # object, assigns a new number object reference to `a`, dropping - # the old reference. Since BT's field objects are mutable, we - # modify their internal value with the inplace operators. This - # means however that we can lose data in the process, for - # example: - # - # int_value_obj += 3.3 - # - # Here, if `int_value_obj` is a Python `int` with the value 2, - # it would be a `float` object after this, holding the value - # 5.3. In our case, if `int_value_obj` is an integer field - # object, 3.3 is converted to an `int` object (3) and added to - # the current value of `int_value_obj`, so after this the value - # of the object is 5. This does not compare to 5.3, which is - # why we also use the `int()` type here. - if isinstance(self._def, bt2.field._IntegerField): - rv = int(rv) - - self.assertEqual(r, rv) - - def _test_ibinop_type(self, op, rhs): - r, rv = self._binop(op, rhs) - - if r is None: - return - - self.assertIs(r, self._def) - - def _test_ibinop_invalid_unknown(self, op): - class A: - pass - - with self.assertRaises(TypeError): - op(self._def, A()) - - def _test_ibinop_invalid_none(self, op): - with self.assertRaises(TypeError): - op(self._def, None) - def _test_binop_rhs_false(self, test_cb, op): test_cb(op, False) @@ -334,6 +353,12 @@ class _TestNumericField: def _test_binop_rhs_zero_vfloat(self, test_cb, op): test_cb(op, bt2.create_value(0.0)) + def _test_binop_rhs_complex(self, test_cb, op): + test_cb(op, -23+19j) + + def _test_binop_rhs_zero_complex(self, test_cb, op): + test_cb(op, 0j) + def _test_binop_type_false(self, op): self._test_binop_rhs_false(self._test_binop_type, op) @@ -376,6 +401,12 @@ class _TestNumericField: def _test_binop_type_zero_vfloat(self, op): self._test_binop_rhs_zero_vfloat(self._test_binop_type, op) + def _test_binop_type_complex(self, op): + self._test_binop_rhs_complex(self._test_binop_type, op) + + def _test_binop_type_zero_complex(self, op): + self._test_binop_rhs_zero_complex(self._test_binop_type, op) + def _test_binop_value_false(self, op): self._test_binop_rhs_false(self._test_binop_value, op) @@ -418,6 +449,12 @@ class _TestNumericField: def _test_binop_value_zero_vfloat(self, op): self._test_binop_rhs_zero_vfloat(self._test_binop_value, op) + def _test_binop_value_complex(self, op): + self._test_binop_rhs_complex(self._test_binop_value, op) + + def _test_binop_value_zero_complex(self, op): + self._test_binop_rhs_zero_complex(self._test_binop_value, op) + def _test_binop_lhs_addr_same_false(self, op): self._test_binop_rhs_false(self._test_binop_lhs_addr_same, op) @@ -460,6 +497,12 @@ class _TestNumericField: def _test_binop_lhs_addr_same_zero_vfloat(self, op): self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_addr_same, op) + def _test_binop_lhs_addr_same_complex(self, op): + self._test_binop_rhs_complex(self._test_binop_lhs_addr_same, op) + + def _test_binop_lhs_addr_same_zero_complex(self, op): + self._test_binop_rhs_zero_complex(self._test_binop_lhs_addr_same, op) + def _test_binop_lhs_value_same_false(self, op): self._test_binop_rhs_false(self._test_binop_lhs_value_same, op) @@ -502,89 +545,11 @@ class _TestNumericField: def _test_binop_lhs_value_same_zero_vfloat(self, op): self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_value_same, op) - def _test_ibinop_type_false(self, op): - self._test_binop_rhs_false(self._test_ibinop_type, op) - - def _test_ibinop_type_true(self, op): - self._test_binop_rhs_true(self._test_ibinop_type, op) - - def _test_ibinop_type_pos_int(self, op): - self._test_binop_rhs_pos_int(self._test_ibinop_type, op) - - def _test_ibinop_type_neg_int(self, op): - self._test_binop_rhs_neg_int(self._test_ibinop_type, op) - - def _test_ibinop_type_zero_int(self, op): - self._test_binop_rhs_zero_int(self._test_ibinop_type, op) - - def _test_ibinop_type_pos_vint(self, op): - self._test_binop_rhs_pos_vint(self._test_ibinop_type, op) - - def _test_ibinop_type_neg_vint(self, op): - self._test_binop_rhs_neg_vint(self._test_ibinop_type, op) + def _test_binop_lhs_value_same_complex(self, op): + self._test_binop_rhs_complex(self._test_binop_lhs_value_same, op) - def _test_ibinop_type_zero_vint(self, op): - self._test_binop_rhs_zero_vint(self._test_ibinop_type, op) - - def _test_ibinop_type_pos_float(self, op): - self._test_binop_rhs_pos_float(self._test_ibinop_type, op) - - def _test_ibinop_type_neg_float(self, op): - self._test_binop_rhs_neg_float(self._test_ibinop_type, op) - - def _test_ibinop_type_zero_float(self, op): - self._test_binop_rhs_zero_float(self._test_ibinop_type, op) - - def _test_ibinop_type_pos_vfloat(self, op): - self._test_binop_rhs_pos_vfloat(self._test_ibinop_type, op) - - def _test_ibinop_type_neg_vfloat(self, op): - self._test_binop_rhs_neg_vfloat(self._test_ibinop_type, op) - - def _test_ibinop_type_zero_vfloat(self, op): - self._test_binop_rhs_zero_vfloat(self._test_ibinop_type, op) - - def _test_ibinop_value_false(self, op): - self._test_binop_rhs_false(self._test_ibinop_value, op) - - def _test_ibinop_value_true(self, op): - self._test_binop_rhs_true(self._test_ibinop_value, op) - - def _test_ibinop_value_pos_int(self, op): - self._test_binop_rhs_pos_int(self._test_ibinop_value, op) - - def _test_ibinop_value_neg_int(self, op): - self._test_binop_rhs_neg_int(self._test_ibinop_value, op) - - def _test_ibinop_value_zero_int(self, op): - self._test_binop_rhs_zero_int(self._test_ibinop_value, op) - - def _test_ibinop_value_pos_vint(self, op): - self._test_binop_rhs_pos_vint(self._test_ibinop_value, op) - - def _test_ibinop_value_neg_vint(self, op): - self._test_binop_rhs_neg_vint(self._test_ibinop_value, op) - - def _test_ibinop_value_zero_vint(self, op): - self._test_binop_rhs_zero_vint(self._test_ibinop_value, op) - - def _test_ibinop_value_pos_float(self, op): - self._test_binop_rhs_pos_float(self._test_ibinop_value, op) - - def _test_ibinop_value_neg_float(self, op): - self._test_binop_rhs_neg_float(self._test_ibinop_value, op) - - def _test_ibinop_value_zero_float(self, op): - self._test_binop_rhs_zero_float(self._test_ibinop_value, op) - - def _test_ibinop_value_pos_vfloat(self, op): - self._test_binop_rhs_pos_vfloat(self._test_ibinop_value, op) - - def _test_ibinop_value_neg_vfloat(self, op): - self._test_binop_rhs_neg_vfloat(self._test_ibinop_value, op) - - def _test_ibinop_value_zero_vfloat(self, op): - self._test_binop_rhs_zero_vfloat(self._test_ibinop_value, op) + def _test_binop_lhs_value_same_zero_complex(self, op): + self._test_binop_rhs_zero_complex(self._test_binop_lhs_value_same, op) def test_bool_op(self): self.assertEqual(bool(self._def), bool(self._def_value)) @@ -614,6 +579,11 @@ class _TestNumericField: self.assertTrue(self._def != None) # noqa: E711 +# This is a list of binary operators used for +# _inject_numeric_testing_methods(). +# +# Each entry is a pair of binary operator name (used as part of the +# created testing method's name) and operator function. _BINOPS = ( ('lt', operator.lt), ('le', operator.le), @@ -648,22 +618,11 @@ _BINOPS = ( ) -_IBINOPS = ( - ('iadd', operator.iadd), - ('iand', operator.iand), - ('ifloordiv', operator.ifloordiv), - ('ilshift', operator.ilshift), - ('imod', operator.imod), - ('imul', operator.imul), - ('ior', operator.ior), - ('ipow', operator.ipow), - ('irshift', operator.irshift), - ('isub', operator.isub), - ('itruediv', operator.itruediv), - ('ixor', operator.ixor), -) - - +# This is a list of unary operators used for +# _inject_numeric_testing_methods(). +# +# Each entry is a pair of unary operator name (used as part of the +# created testing method's name) and operator function. _UNARYOPS = ( ('neg', operator.neg), ('pos', operator.pos), @@ -680,13 +639,24 @@ _UNARYOPS = ( ) +# This function injects a bunch of testing methods to a numeric +# field test case. +# +# It is meant to be used like this: +# +# _inject_numeric_testing_methods(MyNumericFieldTestCase) +# +# This function injects: +# +# * One testing method for each _TestNumericField._test_binop_*() +# method, for each binary operator in the _BINOPS tuple. +# +# * One testing method for each _TestNumericField._test_unaryop*() +# method, for each unary operator in the _UNARYOPS tuple. def _inject_numeric_testing_methods(cls): def test_binop_name(suffix): return 'test_binop_{}_{}'.format(name, suffix) - def test_ibinop_name(suffix): - return 'test_ibinop_{}_{}'.format(name, suffix) - def test_unaryop_name(suffix): return 'test_unaryop_{}_{}'.format(name, suffix) @@ -750,6 +720,14 @@ def _inject_numeric_testing_methods(cls): setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_vfloat, op=binop)) setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_float, op=binop)) setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_vfloat, op=binop)) + setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericField._test_binop_type_complex, op=binop)) + setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericField._test_binop_type_zero_complex, op=binop)) + setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericField._test_binop_value_complex, op=binop)) + setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericField._test_binop_value_zero_complex, op=binop)) + setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_complex, op=binop)) + setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_complex, op=binop)) + setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_complex, op=binop)) + setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_complex, op=binop)) # inject testing methods for each unary operation for name, unaryop in _UNARYOPS: @@ -758,39 +736,6 @@ def _inject_numeric_testing_methods(cls): setattr(cls, test_unaryop_name('addr_same'), partialmethod(_TestNumericField._test_unaryop_addr_same, op=unaryop)) setattr(cls, test_unaryop_name('value_same'), partialmethod(_TestNumericField._test_unaryop_value_same, op=unaryop)) - # inject testing methods for each inplace binary operation - for name, ibinop in _IBINOPS: - setattr(cls, test_ibinop_name('invalid_unknown'), partialmethod(_TestNumericField._test_ibinop_invalid_unknown, op=ibinop)) - setattr(cls, test_ibinop_name('invalid_none'), partialmethod(_TestNumericField._test_ibinop_invalid_none, op=ibinop)) - setattr(cls, test_ibinop_name('type_true'), partialmethod(_TestNumericField._test_ibinop_type_true, op=ibinop)) - setattr(cls, test_ibinop_name('value_true'), partialmethod(_TestNumericField._test_ibinop_value_true, op=ibinop)) - setattr(cls, test_ibinop_name('type_pos_int'), partialmethod(_TestNumericField._test_ibinop_type_pos_int, op=ibinop)) - setattr(cls, test_ibinop_name('type_pos_vint'), partialmethod(_TestNumericField._test_ibinop_type_pos_vint, op=ibinop)) - setattr(cls, test_ibinop_name('value_pos_int'), partialmethod(_TestNumericField._test_ibinop_value_pos_int, op=ibinop)) - setattr(cls, test_ibinop_name('value_pos_vint'), partialmethod(_TestNumericField._test_ibinop_value_pos_vint, op=ibinop)) - setattr(cls, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericField._test_ibinop_type_neg_int, op=ibinop)) - setattr(cls, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericField._test_ibinop_type_neg_vint, op=ibinop)) - setattr(cls, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericField._test_ibinop_value_neg_int, op=ibinop)) - setattr(cls, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericField._test_ibinop_value_neg_vint, op=ibinop)) - setattr(cls, test_ibinop_name('type_false'), partialmethod(_TestNumericField._test_ibinop_type_false, op=ibinop)) - setattr(cls, test_ibinop_name('value_false'), partialmethod(_TestNumericField._test_ibinop_value_false, op=ibinop)) - setattr(cls, test_ibinop_name('type_zero_int'), partialmethod(_TestNumericField._test_ibinop_type_zero_int, op=ibinop)) - setattr(cls, test_ibinop_name('type_zero_vint'), partialmethod(_TestNumericField._test_ibinop_type_zero_vint, op=ibinop)) - setattr(cls, test_ibinop_name('value_zero_int'), partialmethod(_TestNumericField._test_ibinop_value_zero_int, op=ibinop)) - setattr(cls, test_ibinop_name('value_zero_vint'), partialmethod(_TestNumericField._test_ibinop_value_zero_vint, op=ibinop)) - setattr(cls, test_ibinop_name('type_pos_float'), partialmethod(_TestNumericField._test_ibinop_type_pos_float, op=ibinop)) - setattr(cls, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericField._test_ibinop_type_neg_float, op=ibinop)) - setattr(cls, test_ibinop_name('type_pos_vfloat'), partialmethod(_TestNumericField._test_ibinop_type_pos_vfloat, op=ibinop)) - setattr(cls, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericField._test_ibinop_type_neg_vfloat, op=ibinop)) - setattr(cls, test_ibinop_name('value_pos_float'), partialmethod(_TestNumericField._test_ibinop_value_pos_float, op=ibinop)) - setattr(cls, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericField._test_ibinop_value_neg_float, op=ibinop)) - setattr(cls, test_ibinop_name('value_pos_vfloat'), partialmethod(_TestNumericField._test_ibinop_value_pos_vfloat, op=ibinop)) - setattr(cls, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericField._test_ibinop_value_neg_vfloat, op=ibinop)) - setattr(cls, test_ibinop_name('type_zero_float'), partialmethod(_TestNumericField._test_ibinop_type_zero_float, op=ibinop)) - setattr(cls, test_ibinop_name('type_zero_vfloat'), partialmethod(_TestNumericField._test_ibinop_type_zero_vfloat, op=ibinop)) - setattr(cls, test_ibinop_name('value_zero_float'), partialmethod(_TestNumericField._test_ibinop_value_zero_float, op=ibinop)) - setattr(cls, test_ibinop_name('value_zero_vfloat'), partialmethod(_TestNumericField._test_ibinop_value_zero_vfloat, op=ibinop)) - class _TestIntegerFieldCommon(_TestNumericField): def test_assign_true(self): @@ -820,11 +765,6 @@ class _TestIntegerFieldCommon(_TestNumericField): self._def.value = field self.assertEqual(self._def, raw) - def test_assign_float(self): - raw = 123.456 - self._def.value = raw - self.assertEqual(self._def, int(raw)) - def test_assign_invalid_type(self): with self.assertRaises(TypeError): self._def.value = 'yes' @@ -876,11 +816,11 @@ class SignedIntegerFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): class SignedEnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): def _create_fc(self, tc): fc = tc.create_signed_enumeration_field_class(32) - fc.map_range('something', 17) - fc.map_range('speaker', 12, 16) - fc.map_range('can', 18, 2540) - fc.map_range('whole range', -(2 ** 31), (2 ** 31) - 1) - fc.map_range('zip', -45, 1001) + fc.add_mapping('something', bt2.SignedIntegerRangeSet([(17, 17)])) + fc.add_mapping('speaker', bt2.SignedIntegerRangeSet([(12, 16)])) + fc.add_mapping('can', bt2.SignedIntegerRangeSet([(18, 2540)])) + fc.add_mapping('whole range', bt2.SignedIntegerRangeSet([(-(2 ** 31), (2 ** 31) - 1)])) + fc.add_mapping('zip', bt2.SignedIntegerRangeSet([(-45, 1001)])) return fc def setUp(self): @@ -1136,6 +1076,15 @@ class _TestArrayFieldCommon: field[2] = 1948754 self.assertNotEqual(self._def, field) + def test_eq_non_sequence_iterable(self): + dct = collections.OrderedDict([(1, 2), (3, 4), (5, 6)]) + field = _create_int_array_field(self._tc, 3) + field[0] = 1 + field[1] = 3 + field[2] = 5 + self.assertEqual(field, list(dct.keys())) + self.assertNotEqual(field, dct) + def test_setitem(self): self._def[2] = 24 self.assertEqual(self._def[2], 24) @@ -1506,26 +1455,16 @@ class StructureFieldTestCase(unittest.TestCase): class VariantFieldTestCase(unittest.TestCase): def _create_fc(self, tc): - selector_fc = tc.create_signed_enumeration_field_class(field_value_range=32) - selector_fc.map_range('corner', 23) - selector_fc.map_range('zoom', 17, 20) - selector_fc.map_range('mellotron', 1001) - selector_fc.map_range('giorgio', 2000, 3000) - ft0 = tc.create_signed_integer_field_class(32) ft1 = tc.create_string_field_class() ft2 = tc.create_real_field_class() ft3 = tc.create_signed_integer_field_class(17) - fc = tc.create_variant_field_class() fc.append_option('corner', ft0) fc.append_option('zoom', ft1) fc.append_option('mellotron', ft2) fc.append_option('giorgio', ft3) - fc.selector_field_class = selector_fc - top_fc = tc.create_structure_field_class() - top_fc.append_member('selector_field', selector_fc) top_fc.append_member('variant_field', fc) return top_fc