X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_value.py;h=fea749fc5b9234975d7f1abb7bb738ff85ccc747;hb=082db6480d4f3686922269ec24c2ecc7b2c28bce;hp=ca4957161cc65946d6a7c399cfc73be340a32acd;hpb=00512c974abe06c4de9a25181eb22c0b35047a9b;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index ca495716..fea749fc 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -18,8 +18,8 @@ from functools import partial, partialmethod import operator +import collections import unittest -import numbers import math import copy import bt2 @@ -38,10 +38,7 @@ class _TestCopySimple: copy.deepcopy(self._def) -_COMP_BINOPS = ( - operator.eq, - operator.ne, -) +_COMP_BINOPS = (operator.eq, operator.ne) # Base class for numeric value test cases. @@ -263,7 +260,7 @@ class _TestNumericValue(_TestCopySimple): test_cb(op, 0.0) def _test_binop_rhs_complex(self, test_cb, op): - test_cb(op, -23+19j) + test_cb(op, -23 + 19j) def _test_binop_rhs_zero_complex(self, test_cb, op): test_cb(op, 0j) @@ -574,79 +571,415 @@ def _inject_numeric_testing_methods(cls): # inject testing methods for each binary operation for name, binop in _BINOPS: - setattr(cls, test_binop_name('invalid_unknown'), partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop)) - setattr(cls, test_binop_name('invalid_none'), partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop)) - setattr(cls, test_binop_name('type_true'), partialmethod(_TestNumericValue._test_binop_type_true, op=binop)) - setattr(cls, test_binop_name('type_pos_int'), partialmethod(_TestNumericValue._test_binop_type_pos_int, op=binop)) - setattr(cls, test_binop_name('type_pos_vint'), partialmethod(_TestNumericValue._test_binop_type_pos_vint, op=binop)) - setattr(cls, test_binop_name('value_true'), partialmethod(_TestNumericValue._test_binop_value_true, op=binop)) - setattr(cls, test_binop_name('value_pos_int'), partialmethod(_TestNumericValue._test_binop_value_pos_int, op=binop)) - setattr(cls, test_binop_name('value_pos_vint'), partialmethod(_TestNumericValue._test_binop_value_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop)) - setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop)) - setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop)) - setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop)) - setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop)) - setattr(cls, test_binop_name('type_false'), partialmethod(_TestNumericValue._test_binop_type_false, op=binop)) - setattr(cls, test_binop_name('type_zero_int'), partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop)) - setattr(cls, test_binop_name('type_zero_vint'), partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop)) - setattr(cls, test_binop_name('value_false'), partialmethod(_TestNumericValue._test_binop_value_false, op=binop)) - setattr(cls, test_binop_name('value_zero_int'), partialmethod(_TestNumericValue._test_binop_value_zero_int, op=binop)) - setattr(cls, test_binop_name('value_zero_vint'), partialmethod(_TestNumericValue._test_binop_value_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop)) - setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop)) - setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop)) - setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop)) - setattr(cls, test_binop_name('type_pos_float'), partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop)) - setattr(cls, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('value_pos_float'), partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop)) - setattr(cls, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop)) - setattr(cls, test_binop_name('type_zero_float'), partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop)) - setattr(cls, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('value_zero_float'), partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop)) - setattr(cls, test_binop_name('value_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_value_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_float, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vfloat, op=binop)) - setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericValue._test_binop_type_complex, op=binop)) - setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericValue._test_binop_type_zero_complex, op=binop)) - setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericValue._test_binop_value_complex, op=binop)) - setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericValue._test_binop_value_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_zero_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_complex, op=binop)) - setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_complex, op=binop)) + setattr( + cls, + test_binop_name('invalid_unknown'), + partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop), + ) + setattr( + cls, + test_binop_name('invalid_none'), + partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop), + ) + setattr( + cls, + test_binop_name('type_true'), + partialmethod(_TestNumericValue._test_binop_type_true, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_int'), + partialmethod(_TestNumericValue._test_binop_type_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vint'), + partialmethod(_TestNumericValue._test_binop_type_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_true'), + partialmethod(_TestNumericValue._test_binop_value_true, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_int'), + partialmethod(_TestNumericValue._test_binop_value_pos_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vint'), + partialmethod(_TestNumericValue._test_binop_value_pos_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_true'), + partialmethod(_TestNumericValue._test_binop_lhs_addr_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_true'), + partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_neg_int'), + partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vint'), + partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_int'), + partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vint'), + partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_false'), + partialmethod(_TestNumericValue._test_binop_type_false, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_int'), + partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vint'), + partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('value_false'), + partialmethod(_TestNumericValue._test_binop_value_false, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_int'), + partialmethod(_TestNumericValue._test_binop_value_zero_int, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vint'), + partialmethod(_TestNumericValue._test_binop_value_zero_vint, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_false'), + partialmethod(_TestNumericValue._test_binop_lhs_addr_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_false'), + partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_int'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vint'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_neg_float'), + partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_neg_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_float'), + partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_neg_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_neg_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_neg_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_pos_float'), + partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_pos_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_float'), + partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_pos_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_pos_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_pos_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_zero_float'), + partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_vfloat'), + partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_float'), + partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_vfloat'), + partialmethod(_TestNumericValue._test_binop_value_zero_vfloat, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_float'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_float, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_vfloat'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_vfloat, op=binop + ), + ) + setattr( + cls, + test_binop_name('type_complex'), + partialmethod(_TestNumericValue._test_binop_type_complex, op=binop), + ) + setattr( + cls, + test_binop_name('type_zero_complex'), + partialmethod(_TestNumericValue._test_binop_type_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_complex'), + partialmethod(_TestNumericValue._test_binop_value_complex, op=binop), + ) + setattr( + cls, + test_binop_name('value_zero_complex'), + partialmethod(_TestNumericValue._test_binop_value_zero_complex, op=binop), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_addr_same_zero_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_addr_same_zero_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_complex, op=binop + ), + ) + setattr( + cls, + test_binop_name('lhs_value_same_zero_complex'), + partialmethod( + _TestNumericValue._test_binop_lhs_value_same_zero_complex, op=binop + ), + ) # inject testing methods for each unary operation for name, unaryop in _UNARYOPS: - setattr(cls, test_unaryop_name('type'), partialmethod(_TestNumericValue._test_unaryop_type, op=unaryop)) - setattr(cls, test_unaryop_name('value'), partialmethod(_TestNumericValue._test_unaryop_value, op=unaryop)) - setattr(cls, test_unaryop_name('addr_same'), partialmethod(_TestNumericValue._test_unaryop_addr_same, op=unaryop)) - setattr(cls, test_unaryop_name('value_same'), partialmethod(_TestNumericValue._test_unaryop_value_same, op=unaryop)) + setattr( + cls, + test_unaryop_name('type'), + partialmethod(_TestNumericValue._test_unaryop_type, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value'), + partialmethod(_TestNumericValue._test_unaryop_value, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('addr_same'), + partialmethod(_TestNumericValue._test_unaryop_addr_same, op=unaryop), + ) + setattr( + cls, + test_unaryop_name('value_same'), + partialmethod(_TestNumericValue._test_unaryop_value_same, op=unaryop), + ) class CreateValueFuncTestCase(unittest.TestCase): @@ -747,8 +1080,10 @@ class CreateValueFuncTestCase(unittest.TestCase): a = A() - with self.assertRaisesRegex(TypeError, "cannot create value object from 'A' object") as cm: - v = bt2.create_value(a) + with self.assertRaisesRegex( + TypeError, "cannot create value object from 'A' object" + ): + bt2.create_value(a) class BoolValueTestCase(_TestNumericValue, unittest.TestCase): @@ -787,11 +1122,11 @@ class BoolValueTestCase(_TestNumericValue, unittest.TestCase): def test_create_from_int_non_zero(self): with self.assertRaises(TypeError): - b = bt2.BoolValue(23) + bt2.BoolValue(23) def test_create_from_int_zero(self): with self.assertRaises(TypeError): - b = bt2.BoolValue(0) + bt2.BoolValue(0) def test_assign_true(self): b = bt2.BoolValue() @@ -863,10 +1198,14 @@ class _TestIntegerValue(_TestNumericValue): return self.assertRaisesRegex(TypeError, r'expecting an integral number object') def _assert_expecting_int64(self): - return self.assertRaisesRegex(ValueError, r"expecting a signed 64-bit integral value") + return self.assertRaisesRegex( + ValueError, r"expecting a signed 64-bit integral value" + ) def _assert_expecting_uint64(self): - return self.assertRaisesRegex(ValueError, r"expecting an unsigned 64-bit integral value") + return self.assertRaisesRegex( + ValueError, r"expecting an unsigned 64-bit integral value" + ) def test_create_default(self): i = self._CLS() @@ -895,11 +1234,11 @@ class _TestIntegerValue(_TestNumericValue): pass with self._assert_expecting_int(): - i = self._CLS(A()) + self._CLS(A()) def test_create_from_varray(self): with self._assert_expecting_int(): - i = self._CLS(bt2.ArrayValue()) + self._CLS(bt2.ArrayValue()) def test_assign_true(self): raw = True @@ -940,11 +1279,11 @@ class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_create_pos_too_big(self): with self._assert_expecting_int64(): - i = self._CLS(2 ** 63) + self._CLS(2 ** 63) def test_create_neg_too_big(self): with self._assert_expecting_int64(): - i = self._CLS(-(2 ** 63) - 1) + self._CLS(-(2 ** 63) - 1) def test_assign_neg_int(self): raw = -13 @@ -954,7 +1293,7 @@ class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_compare_big_int(self): # Larger than the IEEE 754 double-precision exact representation of # integers. - raw = (2**53) + 1 + raw = (2 ** 53) + 1 v = bt2.create_value(raw) self.assertEqual(v, raw) @@ -967,11 +1306,11 @@ class UnsignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase): def test_create_pos_too_big(self): with self._assert_expecting_uint64(): - i = self._CLS(2 ** 64) + self._CLS(2 ** 64) def test_create_neg(self): with self._assert_expecting_uint64(): - i = self._CLS(-1) + self._CLS(-1) _inject_numeric_testing_methods(UnsignedIntegerValueTestCase) @@ -1042,11 +1381,11 @@ class RealValueTestCase(_TestNumericValue, unittest.TestCase): pass with self._assert_expecting_float(): - f = bt2.RealValue(A()) + bt2.RealValue(A()) def test_create_from_varray(self): with self._assert_expecting_float(): - f = bt2.RealValue(bt2.ArrayValue()) + bt2.RealValue(bt2.ArrayValue()) def test_assign_true(self): self._def.value = True @@ -1134,11 +1473,11 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): pass with self._assert_expecting_str(): - i = bt2.StringValue(A()) + bt2.StringValue(A()) def test_create_from_varray(self): with self._assert_expecting_str(): - i = bt2.StringValue(bt2.ArrayValue()) + bt2.StringValue(bt2.ArrayValue()) def test_assign_int(self): with self._assert_expecting_str(): @@ -1196,6 +1535,15 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): s1 = bt2.StringValue('allo') self.assertGreaterEqual('bateau', s1) + def test_in_string(self): + s1 = bt2.StringValue('beau grand bateau') + self.assertIn('bateau', s1) + + def test_in_vstring(self): + s1 = bt2.StringValue('beau grand bateau') + s2 = bt2.StringValue('bateau') + self.assertIn(s2, s1) + def test_bool_op(self): self.assertEqual(bool(self._def), bool(self._def_value)) @@ -1257,7 +1605,7 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): pass with self._assert_type_error(): - a = bt2.ArrayValue(A()) + bt2.ArrayValue(A()) def test_bool_op_true(self): self.assertTrue(bool(self._def)) @@ -1287,6 +1635,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 @@ -1371,7 +1725,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): 'pos-int': 42, 'neg-float': -42.4, 'pos-float': 23.17, - 'str': 'yes' + 'str': 'yes', } self._def = bt2.MapValue(copy.deepcopy(self._def_value)) @@ -1398,7 +1752,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): pass with self.assertRaises(AttributeError): - m = bt2.MapValue(A()) + bt2.MapValue(A()) def test_bool_op_true(self): self.assertTrue(bool(self._def)) @@ -1428,11 +1782,7 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): self.assertNotEqual(a1, a2) def test_eq_same_content_same_len(self): - raw = { - '3': 3, - 'True': True, - 'array': [1, 2.5, None, {'a': 17.6, 'b': None}] - } + raw = {'3': 3, 'True': True, 'array': [1, 2.5, None, {'a': 17.6, 'b': None}]} a1 = bt2.MapValue(raw) a2 = bt2.MapValue(copy.deepcopy(raw)) self.assertEqual(a1, a2)