summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-12-19 16:51:37 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-12-19 16:51:37 (GMT)
commitdd1da7f74ad7d625148dc8a8f4f30051bc2c3401 (patch)
treeafe9fa4899ecb9838fddfba858bea5ecb4253dbd /Lib/test/test_bytes.py
parentf76df278068252fe7637caeb2d7166f761f124fb (diff)
downloadcpython-dd1da7f74ad7d625148dc8a8f4f30051bc2c3401.zip
cpython-dd1da7f74ad7d625148dc8a8f4f30051bc2c3401.tar.gz
cpython-dd1da7f74ad7d625148dc8a8f4f30051bc2c3401.tar.bz2
Issue #28927: bytes.fromhex() and bytearray.fromhex() now ignore all ASCII
whitespace, not only spaces. Patch by Robert Xiao.
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 b396a76..278cfcc 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -293,6 +293,14 @@ class BaseBytesTest:
b = bytearray([0x1a, 0x2b, 0x30])
self.assertEqual(self.type2test.fromhex('1a2B30'), b)
self.assertEqual(self.type2test.fromhex(' 1A 2B 30 '), b)
+
+ # check that ASCII whitespace is ignored
+ self.assertEqual(self.type2test.fromhex(' 1A\n2B\t30\v'), b)
+ for c in "\x09\x0A\x0B\x0C\x0D\x20":
+ self.assertEqual(self.type2test.fromhex(c), self.type2test())
+ for c in "\x1C\x1D\x1E\x1F\x85\xa0\u2000\u2002\u2028":
+ self.assertRaises(ValueError, self.type2test.fromhex, c)
+
self.assertEqual(self.type2test.fromhex('0000'), b'\0\0')
self.assertRaises(TypeError, self.type2test.fromhex, b'1B')
self.assertRaises(ValueError, self.type2test.fromhex, 'a')