(self)
| 503 | self.assertEqual(value, 0x12345678) |
| 504 | |
| 505 | def test_bool(self): |
| 506 | class ExplodingBool(object): |
| 507 | def __bool__(self): |
| 508 | raise OSError |
| 509 | for prefix in tuple("<>!=")+('',): |
| 510 | false = (), [], [], '', 0 |
| 511 | true = [1], 'test', 5, -1, 0xffffffff+1, 0xffffffff/2 |
| 512 | |
| 513 | falseFormat = prefix + '?' * len(false) |
| 514 | packedFalse = struct.pack(falseFormat, *false) |
| 515 | unpackedFalse = struct.unpack(falseFormat, packedFalse) |
| 516 | |
| 517 | trueFormat = prefix + '?' * len(true) |
| 518 | packedTrue = struct.pack(trueFormat, *true) |
| 519 | unpackedTrue = struct.unpack(trueFormat, packedTrue) |
| 520 | |
| 521 | self.assertEqual(len(true), len(unpackedTrue)) |
| 522 | self.assertEqual(len(false), len(unpackedFalse)) |
| 523 | |
| 524 | for t in unpackedFalse: |
| 525 | self.assertFalse(t) |
| 526 | for t in unpackedTrue: |
| 527 | self.assertTrue(t) |
| 528 | |
| 529 | packed = struct.pack(prefix+'?', 1) |
| 530 | |
| 531 | self.assertEqual(len(packed), struct.calcsize(prefix+'?')) |
| 532 | |
| 533 | if len(packed) != 1: |
| 534 | self.assertFalse(prefix, msg='encoded bool is not one byte: %r' |
| 535 | %packed) |
| 536 | |
| 537 | try: |
| 538 | struct.pack(prefix + '?', ExplodingBool()) |
| 539 | except OSError: |
| 540 | pass |
| 541 | else: |
| 542 | self.fail("Expected OSError: struct.pack(%r, " |
| 543 | "ExplodingBool())" % (prefix + '?')) |
| 544 | |
| 545 | for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']: |
| 546 | self.assertTrue(struct.unpack('>?', c)[0]) |
| 547 | self.assertTrue(struct.unpack('<?', c)[0]) |
| 548 | self.assertTrue(struct.unpack('=?', c)[0]) |
| 549 | self.assertTrue(struct.unpack('@?', c)[0]) |
| 550 | |
| 551 | def test_count_overflow(self): |
| 552 | hugecount = '{}b'.format(sys.maxsize+1) |
nothing calls this directly
no test coverage detected