summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-02-27 08:40:54 (GMT)
committerGeorg Brandl <georg@python.org>2007-02-27 08:40:54 (GMT)
commit0b9b9e04830c40c7866b4ba23d6fa1a0aa80f039 (patch)
treeb91b2c5de74b0941a4accd806b5d956a603e71a9 /Lib/test/test_bytes.py
parent88d65bd3e2229e38b4720bdc19493da17d851b62 (diff)
downloadcpython-0b9b9e04830c40c7866b4ba23d6fa1a0aa80f039.zip
cpython-0b9b9e04830c40c7866b4ba23d6fa1a0aa80f039.tar.gz
cpython-0b9b9e04830c40c7866b4ba23d6fa1a0aa80f039.tar.bz2
Implement bytes.fromhex(), with tests.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 83f6f93..b40d419 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -396,6 +396,21 @@ class BytesTest(unittest.TestCase):
seq.append(alloc)
#print seq
+ def test_fromhex(self):
+ self.assertRaises(TypeError, bytes.fromhex)
+ self.assertRaises(TypeError, bytes.fromhex, 1)
+ self.assertEquals(bytes.fromhex(''), bytes())
+ b = bytes([0x1a, 0x2b, 0x30])
+ self.assertEquals(bytes.fromhex('1a2B30'), b)
+ self.assertEquals(bytes.fromhex(' 1A 2B 30 '), b)
+ self.assertEquals(bytes.fromhex(buffer('')), bytes())
+ self.assertEquals(bytes.fromhex(buffer('0000')), bytes([0, 0]))
+ self.assertRaises(ValueError, bytes.fromhex, 'a')
+ self.assertRaises(ValueError, bytes.fromhex, 'rt')
+ self.assertRaises(ValueError, bytes.fromhex, '1a b cd')
+ self.assertRaises(ValueError, bytes.fromhex, '\x00')
+ self.assertRaises(ValueError, bytes.fromhex, '12 \x00 34')
+
def test_join(self):
self.assertEqual(bytes.join([]), bytes())
self.assertEqual(bytes.join([bytes()]), bytes())