summaryrefslogtreecommitdiff
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2015-04-25 23:22:26 +0000
committerGregory P. Smith <greg@krypto.org>2015-04-25 23:22:26 +0000
commit8cb6569fe14ba8e57ab1a2bea68594747852a9d1 (patch)
tree4391a41ff833b66e6482f5abbf7f0714f23ccf67 /Lib/test/test_bytes.py
parent644adc6adaecf5249de68211f70c0825a36fe6f7 (diff)
downloadcpython-git-8cb6569fe14ba8e57ab1a2bea68594747852a9d1.tar.gz
Implements issue #9951: Adds a hex() method to bytes, bytearray, & memoryview.
Also updates a few internal implementations of the same thing to use the new built-in code. Contributed by Arnon Yaari.
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index ad283002da..1c832aa9e6 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -301,6 +301,14 @@ class BaseBytesTest:
self.assertRaises(ValueError, self.type2test.fromhex, '\x00')
self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34')
+ def test_hex(self):
+ self.assertRaises(TypeError, self.type2test.hex)
+ self.assertRaises(TypeError, self.type2test.hex, 1)
+ self.assertEquals(self.type2test(b"").hex(), "")
+ self.assertEquals(bytearray([0x1a, 0x2b, 0x30]).hex(), '1a2b30')
+ self.assertEquals(self.type2test(b"\x1a\x2b\x30").hex(), '1a2b30')
+ self.assertEquals(memoryview(b"\x1a\x2b\x30").hex(), '1a2b30')
+
def test_join(self):
self.assertEqual(self.type2test(b"").join([]), b"")
self.assertEqual(self.type2test(b"").join([b""]), b"")