1 from functools
import partial
, partialmethod
11 def test_is_frozen(self
):
13 self
.assertTrue(self
._def
.is_frozen
)
15 def test_frozen(self
):
17 self
.assertTrue(self
._def
.frozen
)
19 def test_frozen_exc(self
):
22 with self
.assertRaisesRegex(bt2
.Frozen
, r
'.* value object is frozen$') as cm
:
25 self
.assertEqual(self
._def
, self
._def
_value
)
27 def test_get_value_when_frozen(self
):
29 self
.assertEqual(self
._def
, self
._def
_value
)
32 class _TestFrozenSimple(_TestFrozen
):
33 def _modify_def(self
):
34 self
._def
.value
= self
._def
_new
_value
37 class _TestCopySimple
:
39 cpy
= copy
.copy(self
._def
)
40 self
.assertIsNot(cpy
, self
._def
)
41 self
.assertNotEqual(cpy
.addr
, self
._def
.addr
)
42 self
.assertEqual(cpy
, self
._def
)
44 def test_deepcopy(self
):
45 cpy
= copy
.deepcopy(self
._def
)
46 self
.assertIsNot(cpy
, self
._def
)
47 self
.assertNotEqual(cpy
.addr
, self
._def
.addr
)
48 self
.assertEqual(cpy
, self
._def
)
57 class _TestNumericValue(_TestFrozenSimple
, _TestCopySimple
):
58 def _binop(self
, op
, rhs
):
64 r
= op(self
._def
, rhs
)
65 except Exception as e
:
69 rv
= op(self
._def
_value
, comp_value
)
70 except Exception as e
:
73 if rexc
is not None or rvexc
is not None:
74 # at least one of the operations raised an exception: in
75 # this case both operations should have raised the same
76 # type of exception (division by zero, bit shift with a
77 # floating point number operand, etc.)
78 self
.assertIs(type(rexc
), type(rvexc
))
83 def _unaryop(self
, op
):
89 except Exception as e
:
93 rv
= op(self
._def
_value
)
94 except Exception as e
:
97 if rexc
is not None or rvexc
is not None:
98 # at least one of the operations raised an exception: in
99 # this case both operations should have raised the same
100 # type of exception (division by zero, bit shift with a
101 # floating point number operand, etc.)
102 self
.assertIs(type(rexc
), type(rvexc
))
107 def _test_unaryop_type(self
, op
):
108 r
, rv
= self
._unaryop
(op
)
113 self
.assertIsInstance(r
, type(rv
))
115 def _test_unaryop_value(self
, op
):
116 r
, rv
= self
._unaryop
(op
)
121 self
.assertEqual(r
, rv
)
123 def _test_unaryop_addr_same(self
, op
):
124 addr_before
= self
._def
.addr
126 self
.assertEqual(self
._def
.addr
, addr_before
)
128 def _test_unaryop_value_same(self
, op
):
129 value_before
= copy
.copy(self
._def
)
131 self
.assertEqual(self
._def
, value_before
)
133 def _test_binop_type(self
, op
, rhs
):
134 r
, rv
= self
._binop
(op
, rhs
)
139 if op
in _COMP_BINOPS
:
140 # __eq__() and __ne__() always return a 'bool' object
141 self
.assertIsInstance(r
, bool)
143 self
.assertIsInstance(r
, type(rv
))
145 def _test_binop_value(self
, op
, rhs
):
146 r
, rv
= self
._binop
(op
, rhs
)
151 self
.assertEqual(r
, rv
)
153 def _test_binop_lhs_addr_same(self
, op
, rhs
):
154 addr_before
= self
._def
.addr
155 r
, rv
= self
._binop
(op
, rhs
)
156 self
.assertEqual(self
._def
.addr
, addr_before
)
158 def _test_binop_lhs_value_same(self
, op
, rhs
):
159 value_before
= copy
.copy(self
._def
)
160 r
, rv
= self
._binop
(op
, rhs
)
161 self
.assertEqual(self
._def
, value_before
)
163 def _test_binop_invalid_unknown(self
, op
):
164 if op
in _COMP_BINOPS
:
165 self
.skipTest('not testing')
170 with self
.assertRaises(TypeError):
173 def _test_binop_invalid_none(self
, op
):
174 if op
in _COMP_BINOPS
:
175 self
.skipTest('not testing')
177 with self
.assertRaises(TypeError):
180 def _test_ibinop_value(self
, op
, rhs
):
181 r
, rv
= self
._binop
(op
, rhs
)
186 # The inplace operators are special for value objects because
187 # they do not return a new, immutable object like it's the case
188 # for Python numbers. In Python, `a += 2`, where `a` is a number
189 # object, assigns a new number object reference to `a`, dropping
190 # the old reference. Since BT's value objects are mutable, we
191 # modify their internal value with the inplace operators. This
192 # means however that we can lose data in the process, for
195 # int_value_obj += 3.3
197 # Here, if `int_value_obj` is a Python `int` with the value 2,
198 # it would be a `float` object after this, holding the value
199 # 5.3. In our case, if `int_value_obj` is an integer value
200 # object, 3.3 is converted to an `int` object (3) and added to
201 # the current value of `int_value_obj`, so after this the value
202 # of the object is 5. This does not compare to 5.3, which is
203 # why we also use the `int()` type here.
204 if type(self
._def
) is bt2
.IntegerValue
:
207 self
.assertEqual(r
, rv
)
209 def _test_ibinop_type(self
, op
, rhs
):
210 r
, rv
= self
._binop
(op
, rhs
)
215 self
.assertIs(r
, self
._def
)
217 def _test_ibinop_invalid_unknown(self
, op
):
221 with self
.assertRaises(TypeError):
224 def _test_ibinop_invalid_none(self
, op
):
225 with self
.assertRaises(TypeError):
228 def _test_binop_rhs_false(self
, test_cb
, op
):
231 def _test_binop_rhs_true(self
, test_cb
, op
):
234 def _test_binop_rhs_pos_int(self
, test_cb
, op
):
237 def _test_binop_rhs_neg_int(self
, test_cb
, op
):
240 def _test_binop_rhs_zero_int(self
, test_cb
, op
):
243 def _test_binop_rhs_pos_vint(self
, test_cb
, op
):
244 test_cb(op
, bt2
.create_value(2))
246 def _test_binop_rhs_neg_vint(self
, test_cb
, op
):
247 test_cb(op
, bt2
.create_value(-23))
249 def _test_binop_rhs_zero_vint(self
, test_cb
, op
):
250 test_cb(op
, bt2
.create_value(0))
252 def _test_binop_rhs_pos_float(self
, test_cb
, op
):
255 def _test_binop_rhs_neg_float(self
, test_cb
, op
):
258 def _test_binop_rhs_zero_float(self
, test_cb
, op
):
261 def _test_binop_rhs_pos_vfloat(self
, test_cb
, op
):
262 test_cb(op
, bt2
.create_value(2.2))
264 def _test_binop_rhs_neg_vfloat(self
, test_cb
, op
):
265 test_cb(op
, bt2
.create_value(-23.4))
267 def _test_binop_rhs_zero_vfloat(self
, test_cb
, op
):
268 test_cb(op
, bt2
.create_value(0.0))
270 def _test_binop_type_false(self
, op
):
271 self
._test
_binop
_rhs
_false
(self
._test
_binop
_type
, op
)
273 def _test_binop_type_true(self
, op
):
274 self
._test
_binop
_rhs
_true
(self
._test
_binop
_type
, op
)
276 def _test_binop_type_pos_int(self
, op
):
277 self
._test
_binop
_rhs
_pos
_int
(self
._test
_binop
_type
, op
)
279 def _test_binop_type_neg_int(self
, op
):
280 self
._test
_binop
_rhs
_neg
_int
(self
._test
_binop
_type
, op
)
282 def _test_binop_type_zero_int(self
, op
):
283 self
._test
_binop
_rhs
_zero
_int
(self
._test
_binop
_type
, op
)
285 def _test_binop_type_pos_vint(self
, op
):
286 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_binop
_type
, op
)
288 def _test_binop_type_neg_vint(self
, op
):
289 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_binop
_type
, op
)
291 def _test_binop_type_zero_vint(self
, op
):
292 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_binop
_type
, op
)
294 def _test_binop_type_pos_float(self
, op
):
295 self
._test
_binop
_rhs
_pos
_float
(self
._test
_binop
_type
, op
)
297 def _test_binop_type_neg_float(self
, op
):
298 self
._test
_binop
_rhs
_neg
_float
(self
._test
_binop
_type
, op
)
300 def _test_binop_type_zero_float(self
, op
):
301 self
._test
_binop
_rhs
_zero
_float
(self
._test
_binop
_type
, op
)
303 def _test_binop_type_pos_vfloat(self
, op
):
304 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_binop
_type
, op
)
306 def _test_binop_type_neg_vfloat(self
, op
):
307 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_binop
_type
, op
)
309 def _test_binop_type_zero_vfloat(self
, op
):
310 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_binop
_type
, op
)
312 def _test_binop_value_false(self
, op
):
313 self
._test
_binop
_rhs
_false
(self
._test
_binop
_value
, op
)
315 def _test_binop_value_true(self
, op
):
316 self
._test
_binop
_rhs
_true
(self
._test
_binop
_value
, op
)
318 def _test_binop_value_pos_int(self
, op
):
319 self
._test
_binop
_rhs
_pos
_int
(self
._test
_binop
_value
, op
)
321 def _test_binop_value_neg_int(self
, op
):
322 self
._test
_binop
_rhs
_neg
_int
(self
._test
_binop
_value
, op
)
324 def _test_binop_value_zero_int(self
, op
):
325 self
._test
_binop
_rhs
_zero
_int
(self
._test
_binop
_value
, op
)
327 def _test_binop_value_pos_vint(self
, op
):
328 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_binop
_value
, op
)
330 def _test_binop_value_neg_vint(self
, op
):
331 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_binop
_value
, op
)
333 def _test_binop_value_zero_vint(self
, op
):
334 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_binop
_value
, op
)
336 def _test_binop_value_pos_float(self
, op
):
337 self
._test
_binop
_rhs
_pos
_float
(self
._test
_binop
_value
, op
)
339 def _test_binop_value_neg_float(self
, op
):
340 self
._test
_binop
_rhs
_neg
_float
(self
._test
_binop
_value
, op
)
342 def _test_binop_value_zero_float(self
, op
):
343 self
._test
_binop
_rhs
_zero
_float
(self
._test
_binop
_value
, op
)
345 def _test_binop_value_pos_vfloat(self
, op
):
346 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_binop
_value
, op
)
348 def _test_binop_value_neg_vfloat(self
, op
):
349 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_binop
_value
, op
)
351 def _test_binop_value_zero_vfloat(self
, op
):
352 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_binop
_value
, op
)
354 def _test_binop_lhs_addr_same_false(self
, op
):
355 self
._test
_binop
_rhs
_false
(self
._test
_binop
_lhs
_addr
_same
, op
)
357 def _test_binop_lhs_addr_same_true(self
, op
):
358 self
._test
_binop
_rhs
_true
(self
._test
_binop
_lhs
_addr
_same
, op
)
360 def _test_binop_lhs_addr_same_pos_int(self
, op
):
361 self
._test
_binop
_rhs
_pos
_int
(self
._test
_binop
_lhs
_addr
_same
, op
)
363 def _test_binop_lhs_addr_same_neg_int(self
, op
):
364 self
._test
_binop
_rhs
_neg
_int
(self
._test
_binop
_lhs
_addr
_same
, op
)
366 def _test_binop_lhs_addr_same_zero_int(self
, op
):
367 self
._test
_binop
_rhs
_zero
_int
(self
._test
_binop
_lhs
_addr
_same
, op
)
369 def _test_binop_lhs_addr_same_pos_vint(self
, op
):
370 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_binop
_lhs
_addr
_same
, op
)
372 def _test_binop_lhs_addr_same_neg_vint(self
, op
):
373 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_binop
_lhs
_addr
_same
, op
)
375 def _test_binop_lhs_addr_same_zero_vint(self
, op
):
376 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_binop
_lhs
_addr
_same
, op
)
378 def _test_binop_lhs_addr_same_pos_float(self
, op
):
379 self
._test
_binop
_rhs
_pos
_float
(self
._test
_binop
_lhs
_addr
_same
, op
)
381 def _test_binop_lhs_addr_same_neg_float(self
, op
):
382 self
._test
_binop
_rhs
_neg
_float
(self
._test
_binop
_lhs
_addr
_same
, op
)
384 def _test_binop_lhs_addr_same_zero_float(self
, op
):
385 self
._test
_binop
_rhs
_zero
_float
(self
._test
_binop
_lhs
_addr
_same
, op
)
387 def _test_binop_lhs_addr_same_pos_vfloat(self
, op
):
388 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_binop
_lhs
_addr
_same
, op
)
390 def _test_binop_lhs_addr_same_neg_vfloat(self
, op
):
391 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_binop
_lhs
_addr
_same
, op
)
393 def _test_binop_lhs_addr_same_zero_vfloat(self
, op
):
394 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_binop
_lhs
_addr
_same
, op
)
396 def _test_binop_lhs_value_same_false(self
, op
):
397 self
._test
_binop
_rhs
_false
(self
._test
_binop
_lhs
_value
_same
, op
)
399 def _test_binop_lhs_value_same_true(self
, op
):
400 self
._test
_binop
_rhs
_true
(self
._test
_binop
_lhs
_value
_same
, op
)
402 def _test_binop_lhs_value_same_pos_int(self
, op
):
403 self
._test
_binop
_rhs
_pos
_int
(self
._test
_binop
_lhs
_value
_same
, op
)
405 def _test_binop_lhs_value_same_neg_int(self
, op
):
406 self
._test
_binop
_rhs
_neg
_int
(self
._test
_binop
_lhs
_value
_same
, op
)
408 def _test_binop_lhs_value_same_zero_int(self
, op
):
409 self
._test
_binop
_rhs
_zero
_int
(self
._test
_binop
_lhs
_value
_same
, op
)
411 def _test_binop_lhs_value_same_pos_vint(self
, op
):
412 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_binop
_lhs
_value
_same
, op
)
414 def _test_binop_lhs_value_same_neg_vint(self
, op
):
415 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_binop
_lhs
_value
_same
, op
)
417 def _test_binop_lhs_value_same_zero_vint(self
, op
):
418 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_binop
_lhs
_value
_same
, op
)
420 def _test_binop_lhs_value_same_pos_float(self
, op
):
421 self
._test
_binop
_rhs
_pos
_float
(self
._test
_binop
_lhs
_value
_same
, op
)
423 def _test_binop_lhs_value_same_neg_float(self
, op
):
424 self
._test
_binop
_rhs
_neg
_float
(self
._test
_binop
_lhs
_value
_same
, op
)
426 def _test_binop_lhs_value_same_zero_float(self
, op
):
427 self
._test
_binop
_rhs
_zero
_float
(self
._test
_binop
_lhs
_value
_same
, op
)
429 def _test_binop_lhs_value_same_pos_vfloat(self
, op
):
430 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_binop
_lhs
_value
_same
, op
)
432 def _test_binop_lhs_value_same_neg_vfloat(self
, op
):
433 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_binop
_lhs
_value
_same
, op
)
435 def _test_binop_lhs_value_same_zero_vfloat(self
, op
):
436 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_binop
_lhs
_value
_same
, op
)
438 def _test_ibinop_type_false(self
, op
):
439 self
._test
_binop
_rhs
_false
(self
._test
_ibinop
_type
, op
)
441 def _test_ibinop_type_true(self
, op
):
442 self
._test
_binop
_rhs
_true
(self
._test
_ibinop
_type
, op
)
444 def _test_ibinop_type_pos_int(self
, op
):
445 self
._test
_binop
_rhs
_pos
_int
(self
._test
_ibinop
_type
, op
)
447 def _test_ibinop_type_neg_int(self
, op
):
448 self
._test
_binop
_rhs
_neg
_int
(self
._test
_ibinop
_type
, op
)
450 def _test_ibinop_type_zero_int(self
, op
):
451 self
._test
_binop
_rhs
_zero
_int
(self
._test
_ibinop
_type
, op
)
453 def _test_ibinop_type_pos_vint(self
, op
):
454 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_ibinop
_type
, op
)
456 def _test_ibinop_type_neg_vint(self
, op
):
457 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_ibinop
_type
, op
)
459 def _test_ibinop_type_zero_vint(self
, op
):
460 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_ibinop
_type
, op
)
462 def _test_ibinop_type_pos_float(self
, op
):
463 self
._test
_binop
_rhs
_pos
_float
(self
._test
_ibinop
_type
, op
)
465 def _test_ibinop_type_neg_float(self
, op
):
466 self
._test
_binop
_rhs
_neg
_float
(self
._test
_ibinop
_type
, op
)
468 def _test_ibinop_type_zero_float(self
, op
):
469 self
._test
_binop
_rhs
_zero
_float
(self
._test
_ibinop
_type
, op
)
471 def _test_ibinop_type_pos_vfloat(self
, op
):
472 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_ibinop
_type
, op
)
474 def _test_ibinop_type_neg_vfloat(self
, op
):
475 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_ibinop
_type
, op
)
477 def _test_ibinop_type_zero_vfloat(self
, op
):
478 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_ibinop
_type
, op
)
480 def _test_ibinop_value_false(self
, op
):
481 self
._test
_binop
_rhs
_false
(self
._test
_ibinop
_value
, op
)
483 def _test_ibinop_value_true(self
, op
):
484 self
._test
_binop
_rhs
_true
(self
._test
_ibinop
_value
, op
)
486 def _test_ibinop_value_pos_int(self
, op
):
487 self
._test
_binop
_rhs
_pos
_int
(self
._test
_ibinop
_value
, op
)
489 def _test_ibinop_value_neg_int(self
, op
):
490 self
._test
_binop
_rhs
_neg
_int
(self
._test
_ibinop
_value
, op
)
492 def _test_ibinop_value_zero_int(self
, op
):
493 self
._test
_binop
_rhs
_zero
_int
(self
._test
_ibinop
_value
, op
)
495 def _test_ibinop_value_pos_vint(self
, op
):
496 self
._test
_binop
_rhs
_pos
_vint
(self
._test
_ibinop
_value
, op
)
498 def _test_ibinop_value_neg_vint(self
, op
):
499 self
._test
_binop
_rhs
_neg
_vint
(self
._test
_ibinop
_value
, op
)
501 def _test_ibinop_value_zero_vint(self
, op
):
502 self
._test
_binop
_rhs
_zero
_vint
(self
._test
_ibinop
_value
, op
)
504 def _test_ibinop_value_pos_float(self
, op
):
505 self
._test
_binop
_rhs
_pos
_float
(self
._test
_ibinop
_value
, op
)
507 def _test_ibinop_value_neg_float(self
, op
):
508 self
._test
_binop
_rhs
_neg
_float
(self
._test
_ibinop
_value
, op
)
510 def _test_ibinop_value_zero_float(self
, op
):
511 self
._test
_binop
_rhs
_zero
_float
(self
._test
_ibinop
_value
, op
)
513 def _test_ibinop_value_pos_vfloat(self
, op
):
514 self
._test
_binop
_rhs
_pos
_vfloat
(self
._test
_ibinop
_value
, op
)
516 def _test_ibinop_value_neg_vfloat(self
, op
):
517 self
._test
_binop
_rhs
_neg
_vfloat
(self
._test
_ibinop
_value
, op
)
519 def _test_ibinop_value_zero_vfloat(self
, op
):
520 self
._test
_binop
_rhs
_zero
_vfloat
(self
._test
_ibinop
_value
, op
)
522 def test_bool_op(self
):
523 self
.assertEqual(bool(self
._def
), bool(self
._def
_value
))
525 def test_int_op(self
):
526 self
.assertEqual(int(self
._def
), int(self
._def
_value
))
528 def test_float_op(self
):
529 self
.assertEqual(float(self
._def
), float(self
._def
_value
))
531 def test_complex_op(self
):
532 self
.assertEqual(complex(self
._def
), complex(self
._def
_value
))
534 def test_str_op(self
):
535 self
.assertEqual(str(self
._def
), str(self
._def
_value
))
537 def test_eq_none(self
):
538 self
.assertFalse(self
._def
== None)
540 def test_ne_none(self
):
541 self
.assertTrue(self
._def
!= None)
551 ('add', operator
.add
),
552 ('radd', lambda a
, b
: operator
.add(b
, a
)),
553 ('and', operator
.and_
),
554 ('rand', lambda a
, b
: operator
.and_(b
, a
)),
555 ('floordiv', operator
.floordiv
),
556 ('rfloordiv', lambda a
, b
: operator
.floordiv(b
, a
)),
557 ('lshift', operator
.lshift
),
558 ('rlshift', lambda a
, b
: operator
.lshift(b
, a
)),
559 ('mod', operator
.mod
),
560 ('rmod', lambda a
, b
: operator
.mod(b
, a
)),
561 ('mul', operator
.mul
),
562 ('rmul', lambda a
, b
: operator
.mul(b
, a
)),
563 ('or', operator
.or_
),
564 ('ror', lambda a
, b
: operator
.or_(b
, a
)),
565 ('pow', operator
.pow),
566 ('rpow', lambda a
, b
: operator
.pow(b
, a
)),
567 ('rshift', operator
.rshift
),
568 ('rrshift', lambda a
, b
: operator
.rshift(b
, a
)),
569 ('sub', operator
.sub
),
570 ('rsub', lambda a
, b
: operator
.sub(b
, a
)),
571 ('truediv', operator
.truediv
),
572 ('rtruediv', lambda a
, b
: operator
.truediv(b
, a
)),
573 ('xor', operator
.xor
),
574 ('rxor', lambda a
, b
: operator
.xor(b
, a
)),
579 ('iadd', operator
.iadd
),
580 ('iand', operator
.iand
),
581 ('ifloordiv', operator
.ifloordiv
),
582 ('ilshift', operator
.ilshift
),
583 ('imod', operator
.imod
),
584 ('imul', operator
.imul
),
585 ('ior', operator
.ior
),
586 ('ipow', operator
.ipow
),
587 ('irshift', operator
.irshift
),
588 ('isub', operator
.isub
),
589 ('itruediv', operator
.itruediv
),
590 ('ixor', operator
.ixor
),
595 ('neg', operator
.neg
),
596 ('pos', operator
.pos
),
597 ('abs', operator
.abs),
598 ('invert', operator
.invert
),
600 ('round_0', partial(round, ndigits
=0)),
601 ('round_1', partial(round, ndigits
=1)),
602 ('round_2', partial(round, ndigits
=2)),
603 ('round_3', partial(round, ndigits
=3)),
605 ('floor', math
.floor
),
606 ('trunc', math
.trunc
),
610 def _inject_numeric_testing_methods(cls
):
611 def test_binop_name(suffix
):
612 return 'test_binop_{}_{}'.format(name
, suffix
)
614 def test_ibinop_name(suffix
):
615 return 'test_ibinop_{}_{}'.format(name
, suffix
)
617 def test_unaryop_name(suffix
):
618 return 'test_unaryop_{}_{}'.format(name
, suffix
)
620 # inject testing methods for each binary operation
621 for name
, binop
in _BINOPS
:
623 setattr(cls
, test_binop_name('invalid_unknown'), partialmethod(_TestNumericValue
._test
_binop
_invalid
_unknown
, op
=binop
))
624 setattr(cls
, test_binop_name('invalid_none'), partialmethod(_TestNumericValue
._test
_binop
_invalid
_none
, op
=binop
))
625 setattr(cls
, test_binop_name('type_true'), partialmethod(_TestNumericValue
._test
_binop
_type
_true
, op
=binop
))
626 setattr(cls
, test_binop_name('type_pos_int'), partialmethod(_TestNumericValue
._test
_binop
_type
_pos
_int
, op
=binop
))
627 setattr(cls
, test_binop_name('type_pos_vint'), partialmethod(_TestNumericValue
._test
_binop
_type
_pos
_vint
, op
=binop
))
628 setattr(cls
, test_binop_name('value_true'), partialmethod(_TestNumericValue
._test
_binop
_value
_true
, op
=binop
))
629 setattr(cls
, test_binop_name('value_pos_int'), partialmethod(_TestNumericValue
._test
_binop
_value
_pos
_int
, op
=binop
))
630 setattr(cls
, test_binop_name('value_pos_vint'), partialmethod(_TestNumericValue
._test
_binop
_value
_pos
_vint
, op
=binop
))
631 setattr(cls
, test_binop_name('lhs_addr_same_true'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_true
, op
=binop
))
632 setattr(cls
, test_binop_name('lhs_addr_same_pos_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_pos
_int
, op
=binop
))
633 setattr(cls
, test_binop_name('lhs_addr_same_pos_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_pos
_vint
, op
=binop
))
634 setattr(cls
, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_true
, op
=binop
))
635 setattr(cls
, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_pos
_int
, op
=binop
))
636 setattr(cls
, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_pos
_vint
, op
=binop
))
637 setattr(cls
, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue
._test
_binop
_type
_neg
_int
, op
=binop
))
638 setattr(cls
, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue
._test
_binop
_type
_neg
_vint
, op
=binop
))
639 setattr(cls
, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue
._test
_binop
_value
_neg
_int
, op
=binop
))
640 setattr(cls
, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue
._test
_binop
_value
_neg
_vint
, op
=binop
))
641 setattr(cls
, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_neg
_int
, op
=binop
))
642 setattr(cls
, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_neg
_vint
, op
=binop
))
643 setattr(cls
, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_neg
_int
, op
=binop
))
644 setattr(cls
, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_neg
_vint
, op
=binop
))
645 setattr(cls
, test_binop_name('type_false'), partialmethod(_TestNumericValue
._test
_binop
_type
_false
, op
=binop
))
646 setattr(cls
, test_binop_name('type_zero_int'), partialmethod(_TestNumericValue
._test
_binop
_type
_zero
_int
, op
=binop
))
647 setattr(cls
, test_binop_name('type_zero_vint'), partialmethod(_TestNumericValue
._test
_binop
_type
_zero
_vint
, op
=binop
))
648 setattr(cls
, test_binop_name('value_false'), partialmethod(_TestNumericValue
._test
_binop
_value
_false
, op
=binop
))
649 setattr(cls
, test_binop_name('value_zero_int'), partialmethod(_TestNumericValue
._test
_binop
_value
_zero
_int
, op
=binop
))
650 setattr(cls
, test_binop_name('value_zero_vint'), partialmethod(_TestNumericValue
._test
_binop
_value
_zero
_vint
, op
=binop
))
651 setattr(cls
, test_binop_name('lhs_addr_same_false'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_false
, op
=binop
))
652 setattr(cls
, test_binop_name('lhs_addr_same_zero_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_zero
_int
, op
=binop
))
653 setattr(cls
, test_binop_name('lhs_addr_same_zero_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_zero
_vint
, op
=binop
))
654 setattr(cls
, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_false
, op
=binop
))
655 setattr(cls
, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_zero
_int
, op
=binop
))
656 setattr(cls
, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_zero
_vint
, op
=binop
))
657 setattr(cls
, test_binop_name('type_pos_float'), partialmethod(_TestNumericValue
._test
_binop
_type
_pos
_float
, op
=binop
))
658 setattr(cls
, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue
._test
_binop
_type
_neg
_float
, op
=binop
))
659 setattr(cls
, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_type
_pos
_vfloat
, op
=binop
))
660 setattr(cls
, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_type
_neg
_vfloat
, op
=binop
))
661 setattr(cls
, test_binop_name('value_pos_float'), partialmethod(_TestNumericValue
._test
_binop
_value
_pos
_float
, op
=binop
))
662 setattr(cls
, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue
._test
_binop
_value
_neg
_float
, op
=binop
))
663 setattr(cls
, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_value
_pos
_vfloat
, op
=binop
))
664 setattr(cls
, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_value
_neg
_vfloat
, op
=binop
))
665 setattr(cls
, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_pos
_float
, op
=binop
))
666 setattr(cls
, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_neg
_float
, op
=binop
))
667 setattr(cls
, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_pos
_vfloat
, op
=binop
))
668 setattr(cls
, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_neg
_vfloat
, op
=binop
))
669 setattr(cls
, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_pos
_float
, op
=binop
))
670 setattr(cls
, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_neg
_float
, op
=binop
))
671 setattr(cls
, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_pos
_vfloat
, op
=binop
))
672 setattr(cls
, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_neg
_vfloat
, op
=binop
))
673 setattr(cls
, test_binop_name('type_zero_float'), partialmethod(_TestNumericValue
._test
_binop
_type
_zero
_float
, op
=binop
))
674 setattr(cls
, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_type
_zero
_vfloat
, op
=binop
))
675 setattr(cls
, test_binop_name('value_zero_float'), partialmethod(_TestNumericValue
._test
_binop
_value
_zero
_float
, op
=binop
))
676 setattr(cls
, test_binop_name('value_zero_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_value
_zero
_vfloat
, op
=binop
))
677 setattr(cls
, test_binop_name('lhs_addr_same_zero_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_zero
_float
, op
=binop
))
678 setattr(cls
, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_addr
_same
_zero
_vfloat
, op
=binop
))
679 setattr(cls
, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_zero
_float
, op
=binop
))
680 setattr(cls
, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericValue
._test
_binop
_lhs
_value
_same
_zero
_vfloat
, op
=binop
))
682 # inject testing methods for each unary operation
683 for name
, unaryop
in _UNARYOPS
:
684 setattr(cls
, test_unaryop_name('type'), partialmethod(_TestNumericValue
._test
_unaryop
_type
, op
=unaryop
))
685 setattr(cls
, test_unaryop_name('value'), partialmethod(_TestNumericValue
._test
_unaryop
_value
, op
=unaryop
))
686 setattr(cls
, test_unaryop_name('addr_same'), partialmethod(_TestNumericValue
._test
_unaryop
_addr
_same
, op
=unaryop
))
687 setattr(cls
, test_unaryop_name('value_same'), partialmethod(_TestNumericValue
._test
_unaryop
_value
_same
, op
=unaryop
))
689 # inject testing methods for each inplace binary operation
690 for name
, ibinop
in _IBINOPS
:
691 setattr(cls
, test_ibinop_name('invalid_unknown'), partialmethod(_TestNumericValue
._test
_ibinop
_invalid
_unknown
, op
=ibinop
))
692 setattr(cls
, test_ibinop_name('invalid_none'), partialmethod(_TestNumericValue
._test
_ibinop
_invalid
_none
, op
=ibinop
))
693 setattr(cls
, test_ibinop_name('type_true'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_true
, op
=ibinop
))
694 setattr(cls
, test_ibinop_name('value_true'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_true
, op
=ibinop
))
695 setattr(cls
, test_ibinop_name('type_pos_int'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_pos
_int
, op
=ibinop
))
696 setattr(cls
, test_ibinop_name('type_pos_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_pos
_vint
, op
=ibinop
))
697 setattr(cls
, test_ibinop_name('value_pos_int'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_pos
_int
, op
=ibinop
))
698 setattr(cls
, test_ibinop_name('value_pos_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_pos
_vint
, op
=ibinop
))
699 setattr(cls
, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_neg
_int
, op
=ibinop
))
700 setattr(cls
, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_neg
_vint
, op
=ibinop
))
701 setattr(cls
, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_neg
_int
, op
=ibinop
))
702 setattr(cls
, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_neg
_vint
, op
=ibinop
))
703 setattr(cls
, test_ibinop_name('type_false'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_false
, op
=ibinop
))
704 setattr(cls
, test_ibinop_name('value_false'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_false
, op
=ibinop
))
705 setattr(cls
, test_ibinop_name('type_zero_int'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_zero
_int
, op
=ibinop
))
706 setattr(cls
, test_ibinop_name('type_zero_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_zero
_vint
, op
=ibinop
))
707 setattr(cls
, test_ibinop_name('value_zero_int'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_zero
_int
, op
=ibinop
))
708 setattr(cls
, test_ibinop_name('value_zero_vint'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_zero
_vint
, op
=ibinop
))
709 setattr(cls
, test_ibinop_name('type_pos_float'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_pos
_float
, op
=ibinop
))
710 setattr(cls
, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_neg
_float
, op
=ibinop
))
711 setattr(cls
, test_ibinop_name('type_pos_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_pos
_vfloat
, op
=ibinop
))
712 setattr(cls
, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_neg
_vfloat
, op
=ibinop
))
713 setattr(cls
, test_ibinop_name('value_pos_float'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_pos
_float
, op
=ibinop
))
714 setattr(cls
, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_neg
_float
, op
=ibinop
))
715 setattr(cls
, test_ibinop_name('value_pos_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_pos
_vfloat
, op
=ibinop
))
716 setattr(cls
, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_neg
_vfloat
, op
=ibinop
))
717 setattr(cls
, test_ibinop_name('type_zero_float'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_zero
_float
, op
=ibinop
))
718 setattr(cls
, test_ibinop_name('type_zero_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_type
_zero
_vfloat
, op
=ibinop
))
719 setattr(cls
, test_ibinop_name('value_zero_float'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_zero
_float
, op
=ibinop
))
720 setattr(cls
, test_ibinop_name('value_zero_vfloat'), partialmethod(_TestNumericValue
._test
_ibinop
_value
_zero
_vfloat
, op
=ibinop
))
723 @unittest.skip("this is broken")
724 class CreateValueFuncTestCase(unittest
.TestCase
):
725 def test_create_none(self
):
726 v
= bt2
.create_value(None)
729 def test_create_bool_false(self
):
730 v
= bt2
.create_value(False)
731 self
.assertIsInstance(v
, bt2
.BoolValue
)
734 def test_create_bool_true(self
):
735 v
= bt2
.create_value(True)
736 self
.assertIsInstance(v
, bt2
.BoolValue
)
739 def test_create_int_pos(self
):
741 v
= bt2
.create_value(raw
)
742 self
.assertIsInstance(v
, bt2
.IntegerValue
)
743 self
.assertEqual(v
, raw
)
745 def test_create_int_neg(self
):
747 v
= bt2
.create_value(raw
)
748 self
.assertIsInstance(v
, bt2
.IntegerValue
)
749 self
.assertEqual(v
, raw
)
751 def test_create_float_pos(self
):
753 v
= bt2
.create_value(raw
)
754 self
.assertIsInstance(v
, bt2
.FloatValue
)
755 self
.assertEqual(v
, raw
)
757 def test_create_float_neg(self
):
759 v
= bt2
.create_value(raw
)
760 self
.assertIsInstance(v
, bt2
.FloatValue
)
761 self
.assertEqual(v
, raw
)
763 def test_create_string(self
):
765 v
= bt2
.create_value(raw
)
766 self
.assertIsInstance(v
, bt2
.StringValue
)
767 self
.assertEqual(v
, raw
)
769 def test_create_string_empty(self
):
771 v
= bt2
.create_value(raw
)
772 self
.assertIsInstance(v
, bt2
.StringValue
)
773 self
.assertEqual(v
, raw
)
775 def test_create_array_from_list(self
):
777 v
= bt2
.create_value(raw
)
778 self
.assertIsInstance(v
, bt2
.ArrayValue
)
779 self
.assertEqual(v
, raw
)
781 def test_create_array_from_tuple(self
):
783 v
= bt2
.create_value(raw
)
784 self
.assertIsInstance(v
, bt2
.ArrayValue
)
785 self
.assertEqual(v
, raw
)
787 def test_create_array_from_empty_list(self
):
789 v
= bt2
.create_value(raw
)
790 self
.assertIsInstance(v
, bt2
.ArrayValue
)
791 self
.assertEqual(v
, raw
)
793 def test_create_array_from_empty_tuple(self
):
795 v
= bt2
.create_value(raw
)
796 self
.assertIsInstance(v
, bt2
.ArrayValue
)
797 self
.assertEqual(v
, raw
)
799 def test_create_map(self
):
801 v
= bt2
.create_value(raw
)
802 self
.assertIsInstance(v
, bt2
.MapValue
)
803 self
.assertEqual(v
, raw
)
805 def test_create_map_empty(self
):
807 v
= bt2
.create_value(raw
)
808 self
.assertIsInstance(v
, bt2
.MapValue
)
809 self
.assertEqual(v
, raw
)
811 def test_create_vfalse(self
):
812 v
= bt2
.create_value(bt2
.create_value(False))
813 self
.assertIsInstance(v
, bt2
.BoolValue
)
816 def test_create_invalid(self
):
822 with self
.assertRaisesRegex(TypeError, "cannot create value object from 'A' object") as cm
:
823 v
= bt2
.create_value(a
)
826 @unittest.skip("this is broken")
827 class BoolValueTestCase(_TestFrozenSimple
, _TestCopySimple
, unittest
.TestCase
):
829 self
._f
= bt2
.BoolValue(False)
830 self
._t
= bt2
.BoolValue(True)
832 self
._def
_value
= False
833 self
._def
_new
_value
= True
840 def _assert_expecting_bool(self
):
841 return self
.assertRaisesRegex(TypeError, r
"expecting a 'bool' object")
843 def test_create_default(self
):
847 def test_create_false(self
):
848 self
.assertFalse(self
._f
)
850 def test_create_true(self
):
851 self
.assertTrue(self
._t
)
853 def test_create_from_vfalse(self
):
854 b
= bt2
.BoolValue(self
._f
)
857 def test_create_from_vtrue(self
):
858 b
= bt2
.BoolValue(self
._t
)
861 def test_create_from_int_non_zero(self
):
862 with self
.assertRaises(TypeError):
863 b
= bt2
.BoolValue(23)
865 def test_create_from_int_zero(self
):
866 with self
.assertRaises(TypeError):
869 def test_assign_true(self
):
874 def test_assign_false(self
):
879 def test_assign_vtrue(self
):
884 def test_assign_vfalse(self
):
889 def test_assign_int(self
):
890 with self
.assertRaises(TypeError):
894 def test_bool_op(self
):
895 self
.assertEqual(bool(self
._def
), bool(self
._def
_value
))
897 def test_str_op(self
):
898 self
.assertEqual(str(self
._def
), str(self
._def
_value
))
900 def test_eq_none(self
):
901 self
.assertFalse(self
._def
== None)
903 def test_ne_none(self
):
904 self
.assertTrue(self
._def
!= None)
906 def test_vfalse_eq_false(self
):
907 self
.assertEqual(self
._f
, False)
909 def test_vfalse_ne_true(self
):
910 self
.assertNotEqual(self
._f
, True)
912 def test_vtrue_eq_true(self
):
913 self
.assertEqual(self
._t
, True)
915 def test_vtrue_ne_false(self
):
916 self
.assertNotEqual(self
._t
, False)
919 @unittest.skip("this is broken")
920 class IntegerValueTestCase(_TestNumericValue
, unittest
.TestCase
):
924 self
._ip
= bt2
.IntegerValue(self
._pv
)
925 self
._in
= bt2
.IntegerValue(self
._nv
)
927 self
._def
_value
= self
._pv
928 self
._def
_new
_value
= -101
936 def _assert_expecting_int(self
):
937 return self
.assertRaisesRegex(TypeError, r
'expecting a number object')
939 def _assert_expecting_int64(self
):
940 return self
.assertRaisesRegex(ValueError, r
"expecting a signed 64-bit integral value")
942 def _assert_expecting_uint64(self
):
943 return self
.assertRaisesRegex(ValueError, r
"expecting an unsigned 64-bit integral value")
945 def test_create_default(self
):
946 i
= bt2
.IntegerValue()
947 self
.assertEqual(i
, 0)
949 def test_create_pos(self
):
950 self
.assertEqual(self
._ip
, self
._pv
)
952 def test_create_neg(self
):
953 self
.assertEqual(self
._in
, self
._nv
)
955 def test_create_pos_too_big(self
):
956 with self
._assert
_expecting
_int
64():
957 i
= bt2
.IntegerValue(2 ** 63)
959 def test_create_neg_too_big(self
):
960 with self
._assert
_expecting
_int
64():
961 i
= bt2
.IntegerValue(-(2 ** 63) - 1)
963 def test_create_from_vint(self
):
964 i
= bt2
.IntegerValue(self
._ip
)
965 self
.assertEqual(i
, self
._pv
)
967 def test_create_from_false(self
):
968 i
= bt2
.IntegerValue(False)
971 def test_create_from_true(self
):
972 i
= bt2
.IntegerValue(True)
975 def test_create_from_float(self
):
976 i
= bt2
.IntegerValue(99.6)
977 self
.assertEqual(i
, 99)
979 def test_create_from_vfloat(self
):
980 f
= bt2
.create_value(17.5)
981 i
= bt2
.IntegerValue(f
)
982 self
.assertEqual(i
, 17)
984 def test_create_from_unknown(self
):
988 with self
._assert
_expecting
_int
():
989 i
= bt2
.IntegerValue(A())
991 def test_create_from_varray(self
):
992 with self
._assert
_expecting
_int
():
993 i
= bt2
.IntegerValue(bt2
.ArrayValue())
995 def test_assign_true(self
):
997 self
._def
.value
= raw
998 self
.assertEqual(self
._def
, raw
)
1000 def test_assign_false(self
):
1002 self
._def
.value
= raw
1003 self
.assertEqual(self
._def
, raw
)
1005 def test_assign_pos_int(self
):
1007 self
._def
.value
= raw
1008 self
.assertEqual(self
._def
, raw
)
1010 def test_assign_neg_int(self
):
1012 self
._def
.value
= raw
1013 self
.assertEqual(self
._def
, raw
)
1015 def test_assign_vint(self
):
1017 self
._def
.value
= bt2
.create_value(raw
)
1018 self
.assertEqual(self
._def
, raw
)
1020 def test_assign_vfloat(self
):
1022 self
._def
.value
= bt2
.create_value(raw
)
1023 self
.assertEqual(self
._def
, int(raw
))
1026 _inject_numeric_testing_methods(IntegerValueTestCase
)
1029 @unittest.skip("this is broken")
1030 class FloatValueTestCase(_TestNumericValue
, unittest
.TestCase
):
1034 self
._fp
= bt2
.FloatValue(self
._pv
)
1035 self
._fn
= bt2
.FloatValue(self
._nv
)
1036 self
._def
= self
._fp
1037 self
._def
_value
= self
._pv
1038 self
._def
_new
_value
= -101.88
1046 def _assert_expecting_float(self
):
1047 return self
.assertRaisesRegex(TypeError, r
"expecting a real number object")
1049 def _test_invalid_op(self
, cb
):
1050 with self
.assertRaises(TypeError):
1053 def test_create_default(self
):
1054 f
= bt2
.FloatValue()
1055 self
.assertEqual(f
, 0.0)
1057 def test_create_pos(self
):
1058 self
.assertEqual(self
._fp
, self
._pv
)
1060 def test_create_neg(self
):
1061 self
.assertEqual(self
._fn
, self
._nv
)
1063 def test_create_from_vint(self
):
1064 f
= bt2
.FloatValue(self
._fp
)
1065 self
.assertEqual(f
, self
._pv
)
1067 def test_create_from_false(self
):
1068 f
= bt2
.FloatValue(False)
1071 def test_create_from_true(self
):
1072 f
= bt2
.FloatValue(True)
1075 def test_create_from_int(self
):
1077 f
= bt2
.FloatValue(raw
)
1078 self
.assertEqual(f
, float(raw
))
1080 def test_create_from_vint(self
):
1082 f
= bt2
.FloatValue(bt2
.create_value(raw
))
1083 self
.assertEqual(f
, float(raw
))
1085 def test_create_from_vfloat(self
):
1087 f
= bt2
.FloatValue(bt2
.create_value(raw
))
1088 self
.assertEqual(f
, raw
)
1090 def test_create_from_unknown(self
):
1094 with self
._assert
_expecting
_float
():
1095 f
= bt2
.FloatValue(A())
1097 def test_create_from_varray(self
):
1098 with self
._assert
_expecting
_float
():
1099 f
= bt2
.FloatValue(bt2
.ArrayValue())
1101 def test_assign_true(self
):
1102 self
._def
.value
= True
1103 self
.assertTrue(self
._def
)
1105 def test_assign_false(self
):
1106 self
._def
.value
= False
1107 self
.assertFalse(self
._def
)
1109 def test_assign_pos_int(self
):
1111 self
._def
.value
= raw
1112 self
.assertEqual(self
._def
, float(raw
))
1114 def test_assign_neg_int(self
):
1116 self
._def
.value
= raw
1117 self
.assertEqual(self
._def
, float(raw
))
1119 def test_assign_vint(self
):
1121 self
._def
.value
= bt2
.create_value(raw
)
1122 self
.assertEqual(self
._def
, float(raw
))
1124 def test_assign_float(self
):
1126 self
._def
.value
= raw
1127 self
.assertEqual(self
._def
, raw
)
1129 def test_assign_vfloat(self
):
1131 self
._def
.value
= bt2
.create_value(raw
)
1132 self
.assertEqual(self
._def
, raw
)
1134 def test_invalid_lshift(self
):
1135 self
._test
_invalid
_op
(lambda: self
._def
<< 23)
1137 def test_invalid_rshift(self
):
1138 self
._test
_invalid
_op
(lambda: self
._def
>> 23)
1140 def test_invalid_and(self
):
1141 self
._test
_invalid
_op
(lambda: self
._def
& 23)
1143 def test_invalid_or(self
):
1144 self
._test
_invalid
_op
(lambda: self
._def |
23)
1146 def test_invalid_xor(self
):
1147 self
._test
_invalid
_op
(lambda: self
._def ^
23)
1149 def test_invalid_invert(self
):
1150 self
._test
_invalid
_op
(lambda: ~self
._def
)
1153 _inject_numeric_testing_methods(FloatValueTestCase
)
1156 @unittest.skip("this is broken")
1157 class StringValueTestCase(_TestCopySimple
, _TestFrozenSimple
, unittest
.TestCase
):
1159 self
._def
_value
= 'Hello, World!'
1160 self
._def
= bt2
.StringValue(self
._def
_value
)
1161 self
._def
_new
_value
= 'Yes!'
1166 def _assert_expecting_str(self
):
1167 return self
.assertRaises(TypeError)
1169 def test_create_default(self
):
1170 s
= bt2
.StringValue()
1171 self
.assertEqual(s
, '')
1173 def test_create_from_str(self
):
1175 s
= bt2
.StringValue(raw
)
1176 self
.assertEqual(s
, raw
)
1178 def test_create_from_vstr(self
):
1180 s
= bt2
.StringValue(bt2
.create_value(raw
))
1181 self
.assertEqual(s
, raw
)
1183 def test_create_from_unknown(self
):
1187 with self
._assert
_expecting
_str
():
1188 i
= bt2
.StringValue(A())
1190 def test_create_from_varray(self
):
1191 with self
._assert
_expecting
_str
():
1192 i
= bt2
.StringValue(bt2
.ArrayValue())
1194 def test_assign_int(self
):
1195 with self
._assert
_expecting
_str
():
1196 self
._def
.value
= 283
1198 def test_assign_str(self
):
1201 self
.assertEqual(self
._def
, raw
)
1203 def test_assign_vstr(self
):
1205 self
._def
= bt2
.create_value(raw
)
1206 self
.assertEqual(self
._def
, raw
)
1209 self
.assertEqual(self
._def
, self
._def
_value
)
1212 self
.assertNotEqual(self
._def
, 23)
1214 def test_lt_vstring(self
):
1215 s1
= bt2
.StringValue('allo')
1216 s2
= bt2
.StringValue('bateau')
1217 self
.assertLess(s1
, s2
)
1219 def test_lt_string(self
):
1220 s1
= bt2
.StringValue('allo')
1221 self
.assertLess(s1
, 'bateau')
1223 def test_le_vstring(self
):
1224 s1
= bt2
.StringValue('allo')
1225 s2
= bt2
.StringValue('bateau')
1226 self
.assertLessEqual(s1
, s2
)
1228 def test_le_string(self
):
1229 s1
= bt2
.StringValue('allo')
1230 self
.assertLessEqual(s1
, 'bateau')
1232 def test_gt_vstring(self
):
1233 s1
= bt2
.StringValue('allo')
1234 s2
= bt2
.StringValue('bateau')
1235 self
.assertGreater(s2
, s1
)
1237 def test_gt_string(self
):
1238 s1
= bt2
.StringValue('allo')
1239 self
.assertGreater('bateau', s1
)
1241 def test_ge_vstring(self
):
1242 s1
= bt2
.StringValue('allo')
1243 s2
= bt2
.StringValue('bateau')
1244 self
.assertGreaterEqual(s2
, s1
)
1246 def test_ge_string(self
):
1247 s1
= bt2
.StringValue('allo')
1248 self
.assertGreaterEqual('bateau', s1
)
1250 def test_bool_op(self
):
1251 self
.assertEqual(bool(self
._def
), bool(self
._def
_value
))
1253 def test_str_op(self
):
1254 self
.assertEqual(str(self
._def
), str(self
._def
_value
))
1257 self
.assertEqual(len(self
._def
), len(self
._def
_value
))
1259 def test_getitem(self
):
1260 self
.assertEqual(self
._def
[5], self
._def
_value
[5])
1262 def test_append_str(self
):
1263 to_append
= 'meow meow meow'
1264 self
._def
+= to_append
1265 self
._def
_value
+= to_append
1266 self
.assertEqual(self
._def
, self
._def
_value
)
1268 def test_append_vstr(self
):
1269 to_append
= 'meow meow meow'
1270 self
._def
+= bt2
.create_value(to_append
)
1271 self
._def
_value
+= to_append
1272 self
.assertEqual(self
._def
, self
._def
_value
)
1275 @unittest.skip("this is broken")
1276 class ArrayValueTestCase(_TestFrozen
, unittest
.TestCase
):
1278 self
._def
_value
= [None, False, True, -23, 0, 42, -42.4, 23.17, 'yes']
1279 self
._def
= bt2
.ArrayValue(copy
.deepcopy(self
._def
_value
))
1284 def _modify_def(self
):
1285 self
._def
[2] = 'xyz'
1287 def _assert_type_error(self
):
1288 return self
.assertRaises(TypeError)
1290 def test_create_default(self
):
1291 a
= bt2
.ArrayValue()
1292 self
.assertEqual(len(a
), 0)
1294 def test_create_from_array(self
):
1295 self
.assertEqual(self
._def
, self
._def
_value
)
1297 def test_create_from_tuple(self
):
1298 t
= 1, 2, False, None
1299 a
= bt2
.ArrayValue(t
)
1300 self
.assertEqual(a
, t
)
1302 def test_create_from_varray(self
):
1303 va
= bt2
.ArrayValue(copy
.deepcopy(self
._def
_value
))
1304 a
= bt2
.ArrayValue(va
)
1305 self
.assertEqual(va
, a
)
1307 def test_create_from_unknown(self
):
1311 with self
._assert
_type
_error
():
1312 a
= bt2
.ArrayValue(A())
1314 def test_bool_op_true(self
):
1315 self
.assertTrue(bool(self
._def
))
1317 def test_bool_op_false(self
):
1318 self
.assertFalse(bool(bt2
.ArrayValue()))
1321 self
.assertEqual(len(self
._def
), len(self
._def
_value
))
1323 def test_copy(self
):
1324 to_copy
= (1, 2, 'hello', (4, 5.2))
1325 a
= bt2
.ArrayValue(to_copy
)
1327 self
.assertEqual(a
, cpy
)
1328 self
.assertNotEqual(a
.addr
, cpy
.addr
)
1329 self
.assertEqual(a
[3].addr
, cpy
[3].addr
)
1331 def test_deepcopy(self
):
1332 to_copy
= (1, 2, 'hello', (4, 5.2))
1333 a
= bt2
.ArrayValue(to_copy
)
1334 cpy
= copy
.deepcopy(a
)
1335 self
.assertEqual(a
, cpy
)
1336 self
.assertNotEqual(a
.addr
, cpy
.addr
)
1337 self
.assertNotEqual(a
[3].addr
, cpy
[3].addr
)
1339 def test_eq_int(self
):
1340 self
.assertNotEqual(self
._def
, 23)
1342 def test_eq_diff_len(self
):
1343 a1
= bt2
.create_value([1, 2, 3])
1344 a2
= bt2
.create_value([1, 2])
1345 self
.assertNotEqual(a1
, a2
)
1347 def test_eq_diff_content_same_len(self
):
1348 a1
= bt2
.create_value([1, 2, 3])
1349 a2
= bt2
.create_value([4, 5, 6])
1350 self
.assertNotEqual(a1
, a2
)
1352 def test_eq_same_content_same_len(self
):
1353 raw
= (3, True, [1, 2.5, None, {'a': 17.6, 'b': None}])
1354 a1
= bt2
.ArrayValue(raw
)
1355 a2
= bt2
.ArrayValue(copy
.deepcopy(raw
))
1356 self
.assertEqual(a1
, a2
)
1358 def test_setitem_int(self
):
1361 self
.assertEqual(self
._def
[2], raw
)
1363 def test_setitem_vint(self
):
1365 self
._def
[2] = bt2
.create_value(raw
)
1366 self
.assertEqual(self
._def
[2], raw
)
1368 def test_setitem_none(self
):
1370 self
.assertIsNone(self
._def
[2])
1372 def test_setitem_index_wrong_type(self
):
1373 with self
._assert
_type
_error
():
1374 self
._def
['yes'] = 23
1376 def test_setitem_index_neg(self
):
1377 with self
.assertRaises(IndexError):
1380 def test_setitem_index_out_of_range(self
):
1381 with self
.assertRaises(IndexError):
1382 self
._def
[len(self
._def
)] = 23
1384 def test_append_none(self
):
1385 self
._def
.append(None)
1386 self
.assertIsNone(self
._def
[len(self
._def
) - 1])
1388 def test_append_int(self
):
1390 self
._def
.append(raw
)
1391 self
.assertEqual(self
._def
[len(self
._def
) - 1], raw
)
1393 def test_append_vint(self
):
1395 self
._def
.append(bt2
.create_value(raw
))
1396 self
.assertEqual(self
._def
[len(self
._def
) - 1], raw
)
1398 def test_append_unknown(self
):
1402 with self
._assert
_type
_error
():
1403 self
._def
.append(A())
1405 def test_iadd(self
):
1408 self
.assertEqual(self
._def
[len(self
._def
) - 3], raw
[0])
1409 self
.assertEqual(self
._def
[len(self
._def
) - 2], raw
[1])
1410 self
.assertEqual(self
._def
[len(self
._def
) - 1], raw
[2])
1412 def test_iadd_unknown(self
):
1416 with self
._assert
_type
_error
():
1419 def test_iadd_list_unknown(self
):
1423 with self
._assert
_type
_error
():
1426 def test_iter(self
):
1427 for velem
, elem
in zip(self
._def
, self
._def
_value
):
1428 self
.assertEqual(velem
, elem
)
1431 @unittest.skip("this is broken")
1432 class MapValueTestCase(_TestFrozen
, unittest
.TestCase
):
1445 self
._def
= bt2
.MapValue(copy
.deepcopy(self
._def
_value
))
1450 def _modify_def(self
):
1451 self
._def
['zero'] = 1
1453 def test_create_default(self
):
1455 self
.assertEqual(len(m
), 0)
1457 def test_create_from_dict(self
):
1458 self
.assertEqual(self
._def
, self
._def
_value
)
1460 def test_create_from_vmap(self
):
1461 vm
= bt2
.MapValue(copy
.deepcopy(self
._def
_value
))
1462 m
= bt2
.MapValue(vm
)
1463 self
.assertEqual(vm
, m
)
1465 def test_create_from_unknown(self
):
1469 with self
.assertRaises(AttributeError):
1470 m
= bt2
.MapValue(A())
1472 def test_bool_op_true(self
):
1473 self
.assertTrue(bool(self
._def
))
1475 def test_bool_op_false(self
):
1476 self
.assertFalse(bool(bt2
.MapValue()))
1479 self
.assertEqual(len(self
._def
), len(self
._def
_value
))
1481 def test_copy(self
):
1488 m
= bt2
.MapValue(to_copy
)
1490 self
.assertEqual(m
, cpy
)
1491 self
.assertNotEqual(m
.addr
, cpy
.addr
)
1492 self
.assertEqual(m
['inner'].addr
, cpy
['inner'].addr
)
1494 def test_deepcopy(self
):
1501 m
= bt2
.MapValue(to_copy
)
1502 cpy
= copy
.deepcopy(m
)
1503 self
.assertEqual(m
, cpy
)
1504 self
.assertNotEqual(m
.addr
, cpy
.addr
)
1505 self
.assertNotEqual(m
['inner'].addr
, cpy
['inner'].addr
)
1507 def test_eq_int(self
):
1508 self
.assertNotEqual(self
._def
, 23)
1510 def test_eq_diff_len(self
):
1511 a1
= bt2
.create_value({'a': 1, 'b': 2, 'c': 3})
1512 a2
= bt2
.create_value({'a': 1, 'b': 2})
1513 self
.assertNotEqual(a1
, a2
)
1515 def test_eq_diff_content_same_len(self
):
1516 a1
= bt2
.create_value({'a': 1, 'b': 2, 'c': 3})
1517 a2
= bt2
.create_value({'a': 4, 'b': 2, 'c': 3})
1518 self
.assertNotEqual(a1
, a2
)
1520 def test_eq_same_content_diff_keys(self
):
1521 a1
= bt2
.create_value({'a': 1, 'b': 2, 'c': 3})
1522 a2
= bt2
.create_value({'a': 1, 'k': 2, 'c': 3})
1523 self
.assertNotEqual(a1
, a2
)
1525 def test_eq_same_content_same_len(self
):
1529 'array': [1, 2.5, None, {'a': 17.6, 'b': None}]
1531 a1
= bt2
.MapValue(raw
)
1532 a2
= bt2
.MapValue(copy
.deepcopy(raw
))
1533 self
.assertEqual(a1
, a2
)
1534 self
.assertEqual(a1
, raw
)
1536 def test_setitem_int(self
):
1538 self
._def
['pos-int'] = raw
1539 self
.assertEqual(self
._def
['pos-int'], raw
)
1541 def test_setitem_vint(self
):
1543 self
._def
['pos-int'] = bt2
.create_value(raw
)
1544 self
.assertEqual(self
._def
['pos-int'], raw
)
1546 def test_setitem_none(self
):
1547 self
._def
['none'] = None
1548 self
.assertIsNone(self
._def
['none'])
1550 def test_setitem_new_int(self
):
1551 old_len
= len(self
._def
)
1552 self
._def
['new-int'] = 23
1553 self
.assertEqual(self
._def
['new-int'], 23)
1554 self
.assertEqual(len(self
._def
), old_len
+ 1)
1556 def test_setitem_index_wrong_type(self
):
1557 with self
.assertRaises(TypeError):
1560 def test_iter(self
):
1561 for vkey
, vval
in self
._def
.items():
1562 val
= self
._def
_value
[vkey
]
1563 self
.assertEqual(vval
, val
)
1565 def test_getitem_wrong_key(self
):
1566 with self
.assertRaises(KeyError):
1567 self
._def
['kilojoule']
This page took 0.065529 seconds and 5 git commands to generate.