test_{field,value}.py: array test cases: add non-sequence equality tests
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sat, 29 Jun 2019 16:30:09 +0000 (12:30 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 3 Jul 2019 01:31:27 +0000 (21:31 -0400)
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 <eeppeliteloop@gmail.com>
Change-Id: If7402e4f0e747d2c9d17ddb5ce7aa4fc4156314d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1588
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Francis Deslauriers <francis.deslauriers@efficios.com>
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_value.py

index 03235cc35c9e811d31d900bda20124e9f285c66d..ed3661ebbc13004b481bd94ad6d039f4b66b1e1d 100644 (file)
@@ -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)
index ca4957161cc65946d6a7c399cfc73be340a32acd..3521eb05b4fd37c02479734d750a7ee24fb491f7 100644 (file)
@@ -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
This page took 0.025908 seconds and 4 git commands to generate.