(self)
| 440 | self.assertNotIn(f(b"abd"), b) |
| 441 | |
| 442 | def test_fromhex(self): |
| 443 | self.assertRaises(TypeError, self.type2test.fromhex) |
| 444 | self.assertRaises(TypeError, self.type2test.fromhex, 1) |
| 445 | self.assertEqual(self.type2test.fromhex(''), self.type2test()) |
| 446 | b = bytearray([0x1a, 0x2b, 0x30]) |
| 447 | self.assertEqual(self.type2test.fromhex('1a2B30'), b) |
| 448 | self.assertEqual(self.type2test.fromhex(' 1A 2B 30 '), b) |
| 449 | |
| 450 | # check that ASCII whitespace is ignored |
| 451 | self.assertEqual(self.type2test.fromhex(' 1A\n2B\t30\v'), b) |
| 452 | for c in "\x09\x0A\x0B\x0C\x0D\x20": |
| 453 | self.assertEqual(self.type2test.fromhex(c), self.type2test()) |
| 454 | for c in "\x1C\x1D\x1E\x1F\x85\xa0\u2000\u2002\u2028": |
| 455 | self.assertRaises(ValueError, self.type2test.fromhex, c) |
| 456 | |
| 457 | self.assertEqual(self.type2test.fromhex('0000'), b'\0\0') |
| 458 | self.assertRaises(TypeError, self.type2test.fromhex, b'1B') |
| 459 | self.assertRaises(ValueError, self.type2test.fromhex, 'a') |
| 460 | self.assertRaises(ValueError, self.type2test.fromhex, 'rt') |
| 461 | self.assertRaises(ValueError, self.type2test.fromhex, '1a b cd') |
| 462 | self.assertRaises(ValueError, self.type2test.fromhex, '\x00') |
| 463 | self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34') |
| 464 | |
| 465 | for data, pos in ( |
| 466 | # invalid first hexadecimal character |
| 467 | ('12 x4 56', 3), |
| 468 | # invalid second hexadecimal character |
| 469 | ('12 3x 56', 4), |
| 470 | # two invalid hexadecimal characters |
| 471 | ('12 xy 56', 3), |
| 472 | # test non-ASCII string |
| 473 | ('12 3\xff 56', 4), |
| 474 | ): |
| 475 | with self.assertRaises(ValueError) as cm: |
| 476 | self.type2test.fromhex(data) |
| 477 | self.assertIn('at position %s' % pos, str(cm.exception)) |
| 478 | |
| 479 | def test_hex(self): |
| 480 | self.assertRaises(TypeError, self.type2test.hex) |
nothing calls this directly
no test coverage detected