From: Philippe Proulx Date: Sat, 29 Jun 2019 16:30:09 +0000 (-0400) Subject: test_{field,value}.py: array test cases: add non-sequence equality tests X-Git-Url: https://git.efficios.com/?a=commitdiff_plain;h=73051d4685cce1b2dc8550c60b9a13d11a561a7e;p=babeltrace.git test_{field,value}.py: array test cases: add non-sequence equality tests The new tests verify that an array field or an array value is not equal to another iterable object which would provide the correct element values, but which is not a `collections.abc.Sequence`. This is similar to how [1, 3, 5] == collections.OrderedDict([(1, 2), (3, 4), (5, 6)]) is false. Signed-off-by: Philippe Proulx Change-Id: If7402e4f0e747d2c9d17ddb5ce7aa4fc4156314d Reviewed-on: https://review.lttng.org/c/babeltrace/+/1588 Tested-by: jenkins Reviewed-by: Francis Deslauriers --- diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index 03235cc3..ed3661eb 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 @@ -1074,6 +1075,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) diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index ca495716..3521eb05 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -18,6 +18,7 @@ from functools import partial, partialmethod import operator +import collections import unittest import numbers import math @@ -1287,6 +1288,12 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): a2 = bt2.ArrayValue(copy.deepcopy(raw)) self.assertEqual(a1, a2) + def test_eq_non_sequence_iterable(self): + dct = collections.OrderedDict([(1, 2), (3, 4), (5, 6)]) + a = bt2.ArrayValue((1, 3, 5)) + self.assertEqual(a, list(dct.keys())) + self.assertNotEqual(a, dct) + def test_setitem_int(self): raw = 19 self._def[2] = raw