X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fbindings%2Fpython%2Fbt2%2Ftest_value.py;h=c7cfe0142ba4f929eec5dcd9800e0a2d11adcac4;hb=13b81b5d9cca1fe1bafe18734edb90717eb771da;hp=3521eb05b4fd37c02479734d750a7ee24fb491f7;hpb=54495cd0fb0d125fe6895e6ea74705e28ea1a829;p=babeltrace.git diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index 3521eb05..c7cfe014 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -20,7 +20,6 @@ from functools import partial, partialmethod import operator import collections import unittest -import numbers import math import copy import bt2 @@ -39,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. @@ -264,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) @@ -486,10 +482,14 @@ class _TestNumericValue(_TestCopySimple): self.assertEqual(str(self._def), str(self._def_value)) def test_eq_none(self): - self.assertFalse(self._def == None) + # Disable the "comparison to None" warning, as this is precisely what + # we want to test here. + self.assertFalse(self._def == None) # noqa: E711 def test_ne_none(self): - self.assertTrue(self._def != None) + # Disable the "comparison to None" warning, as this is precisely what + # we want to test here. + self.assertTrue(self._def != None) # noqa: E711 # This is a list of binary operators used for @@ -575,79 +575,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): @@ -748,8 +1084,24 @@ 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) + + +def _create_const_value(value): + class MySink(bt2._UserSinkComponent): + def _user_consume(self): + pass + + @classmethod + def _user_query(cls, priv_query_exec, obj, params, method_obj): + nonlocal value + return {'my_value': value} + + res = bt2.QueryExecutor(MySink, 'obj', None).query() + return res['my_value'] class BoolValueTestCase(_TestNumericValue, unittest.TestCase): @@ -788,11 +1140,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() @@ -826,10 +1178,14 @@ class BoolValueTestCase(_TestNumericValue, unittest.TestCase): self.assertEqual(str(self._def), str(self._def_value)) def test_eq_none(self): - self.assertFalse(self._def == None) + # Disable the "comparison to None" warning, as this is precisely what + # we want to test here. + self.assertFalse(self._def == None) # noqa: E711 def test_ne_none(self): - self.assertTrue(self._def != None) + # Disable the "comparison to None" warning, as this is precisely what + # we want to test here. + self.assertTrue(self._def != None) # noqa: E711 def test_vfalse_eq_false(self): self.assertEqual(self._f, False) @@ -864,10 +1220,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() @@ -896,11 +1256,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 @@ -941,11 +1301,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 @@ -955,7 +1315,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) @@ -968,11 +1328,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) @@ -1011,10 +1371,6 @@ class RealValueTestCase(_TestNumericValue, unittest.TestCase): def test_create_neg(self): self.assertEqual(self._fn, self._nv) - def test_create_from_vint(self): - f = bt2.RealValue(self._fp) - self.assertEqual(f, self._pv) - def test_create_from_false(self): f = bt2.RealValue(False) self.assertFalse(f) @@ -1043,11 +1399,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 @@ -1108,6 +1464,7 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): self._def_value = 'Hello, World!' self._def = bt2.StringValue(self._def_value) + self._def_const = _create_const_value(self._def_value) self._def_new_value = 'Yes!' def tearDown(self): @@ -1135,11 +1492,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(): @@ -1158,7 +1515,10 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): def test_eq(self): self.assertEqual(self._def, self._def_value) - def test_eq(self): + def test_const_eq(self): + self.assertEqual(self._def_const, self._def_value) + + def test_eq_raw(self): self.assertNotEqual(self._def, 23) def test_lt_vstring(self): @@ -1197,6 +1557,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)) @@ -1209,12 +1578,22 @@ class StringValueTestCase(_TestCopySimple, unittest.TestCase): def test_getitem(self): self.assertEqual(self._def[5], self._def_value[5]) - def test_append_str(self): + def test_const_getitem(self): + self.assertEqual(self._def_const[5], self._def_value[5]) + + def test_iadd_str(self): to_append = 'meow meow meow' self._def += to_append self._def_value += to_append self.assertEqual(self._def, self._def_value) + def test_const_iadd_str(self): + to_append = 'meow meow meow' + with self.assertRaises(TypeError): + self._def_const += to_append + + self.assertEqual(self._def_const, self._def_value) + def test_append_vstr(self): to_append = 'meow meow meow' self._def += bt2.create_value(to_append) @@ -1226,6 +1605,7 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): self._def_value = [None, False, True, -23, 0, 42, -42.4, 23.17, 'yes'] self._def = bt2.ArrayValue(copy.deepcopy(self._def_value)) + self._def_const = _create_const_value(copy.deepcopy(self._def_value)) def tearDown(self): del self._def @@ -1258,7 +1638,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)) @@ -1272,9 +1652,16 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): def test_eq_int(self): self.assertNotEqual(self._def, 23) + def test_const_eq(self): + a1 = _create_const_value([1, 2, 3]) + a2 = [1, 2, 3] + self.assertEqual(a1, a2) + def test_eq_diff_len(self): a1 = bt2.create_value([1, 2, 3]) a2 = bt2.create_value([1, 2]) + self.assertIs(type(a1), bt2.ArrayValue) + self.assertIs(type(a2), bt2.ArrayValue) self.assertNotEqual(a1, a2) def test_eq_diff_content_same_len(self): @@ -1320,6 +1707,10 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): with self.assertRaises(IndexError): self._def[len(self._def)] = 23 + def test_const_setitem(self): + with self.assertRaises(TypeError): + self._def_const[2] = 19 + def test_append_none(self): self._def.append(None) self.assertIsNone(self._def[len(self._def) - 1]) @@ -1329,6 +1720,10 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): self._def.append(raw) self.assertEqual(self._def[len(self._def) - 1], raw) + def test_const_append(self): + with self.assertRaises(AttributeError): + self._def_const.append(12194) + def test_append_vint(self): raw = 145 self._def.append(bt2.create_value(raw)) @@ -1348,6 +1743,10 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): self.assertEqual(self._def[len(self._def) - 2], raw[1]) self.assertEqual(self._def[len(self._def) - 1], raw[2]) + def test_const_iadd(self): + with self.assertRaises(TypeError): + self._def_const += 12194 + def test_iadd_unknown(self): class A: pass @@ -1366,6 +1765,31 @@ class ArrayValueTestCase(_TestCopySimple, unittest.TestCase): for velem, elem in zip(self._def, self._def_value): self.assertEqual(velem, elem) + def test_const_iter(self): + for velem, elem in zip(self._def_const, self._def_value): + self.assertEqual(velem, elem) + + def test_const_get_item(self): + item1 = self._def_const[0] + item2 = self._def_const[2] + item3 = self._def_const[5] + item4 = self._def_const[7] + item5 = self._def_const[8] + + self.assertEqual(item1, None) + + self.assertIs(type(item2), bt2._BoolValueConst) + self.assertEqual(item2, True) + + self.assertIs(type(item3), bt2._SignedIntegerValueConst) + self.assertEqual(item3, 42) + + self.assertIs(type(item4), bt2._RealValueConst) + self.assertEqual(item4, 23.17) + + self.assertIs(type(item5), bt2._StringValueConst) + self.assertEqual(item5, 'yes') + class MapValueTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): @@ -1378,9 +1802,10 @@ 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)) + self._def_const = _create_const_value(self._def_value) def tearDown(self): del self._def @@ -1405,7 +1830,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)) @@ -1416,6 +1841,11 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): def test_len(self): self.assertEqual(len(self._def), len(self._def_value)) + def test_const_eq(self): + a1 = _create_const_value({'a': 1, 'b': 2, 'c': 3}) + a2 = {'a': 1, 'b': 2, 'c': 3} + self.assertEqual(a1, a2) + def test_eq_int(self): self.assertNotEqual(self._def, 23) @@ -1424,32 +1854,54 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): a2 = bt2.create_value({'a': 1, 'b': 2}) self.assertNotEqual(a1, a2) + def test_const_eq_diff_len(self): + a1 = _create_const_value({'a': 1, 'b': 2, 'c': 3}) + a2 = _create_const_value({'a': 1, 'b': 2}) + self.assertNotEqual(a1, a2) + def test_eq_diff_content_same_len(self): a1 = bt2.create_value({'a': 1, 'b': 2, 'c': 3}) a2 = bt2.create_value({'a': 4, 'b': 2, 'c': 3}) self.assertNotEqual(a1, a2) + def test_const_eq_diff_content_same_len(self): + a1 = _create_const_value({'a': 1, 'b': 2, 'c': 3}) + a2 = _create_const_value({'a': 4, 'b': 2, 'c': 3}) + self.assertNotEqual(a1, a2) + def test_eq_same_content_diff_keys(self): a1 = bt2.create_value({'a': 1, 'b': 2, 'c': 3}) a2 = bt2.create_value({'a': 1, 'k': 2, 'c': 3}) self.assertNotEqual(a1, a2) + def test_const_eq_same_content_diff_keys(self): + a1 = _create_const_value({'a': 1, 'b': 2, 'c': 3}) + a2 = _create_const_value({'a': 1, 'k': 2, 'c': 3}) + 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) self.assertEqual(a1, raw) + def test_const_eq_same_content_same_len(self): + raw = {'3': 3, 'True': True, 'array': [1, 2.5, None, {'a': 17.6, 'b': None}]} + a1 = _create_const_value(raw) + a2 = _create_const_value(copy.deepcopy(raw)) + self.assertEqual(a1, a2) + self.assertEqual(a1, raw) + def test_setitem_int(self): raw = 19 self._def['pos-int'] = raw self.assertEqual(self._def['pos-int'], raw) + def test_const_setitem_int(self): + with self.assertRaises(TypeError): + self._def_const['pos-int'] = 19 + def test_setitem_vint(self): raw = 19 self._def['pos-int'] = bt2.create_value(raw) @@ -1474,6 +1926,41 @@ class MapValueTestCase(_TestCopySimple, unittest.TestCase): val = self._def_value[vkey] self.assertEqual(vval, val) + def test_const_iter(self): + for vkey, vval in self._def_const.items(): + val = self._def_value[vkey] + self.assertEqual(vval, val) + + def test_get_item(self): + i = self._def['pos-float'] + self.assertIs(type(i), bt2.RealValue) + self.assertEqual(i, 23.17) + + def test_const_get_item(self): + item1 = self._def_const['none'] + item2 = self._def_const['true'] + item3 = self._def_const['pos-int'] + item4 = self._def_const['pos-float'] + item5 = self._def_const['str'] + + self.assertEqual(item1, None) + + self.assertIs(type(item2), bt2._BoolValueConst) + self.assertEqual(item2, True) + + self.assertIs(type(item3), bt2._SignedIntegerValueConst) + self.assertEqual(item3, 42) + + self.assertIs(type(item4), bt2._RealValueConst) + self.assertEqual(item4, 23.17) + + self.assertIs(type(item5), bt2._StringValueConst) + self.assertEqual(item5, 'yes') + def test_getitem_wrong_key(self): with self.assertRaises(KeyError): self._def['kilojoule'] + + +if __name__ == '__main__': + unittest.main()