summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_binascii.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-12-20 12:58:41 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-12-20 12:58:41 (GMT)
commit08316769620c83e32a6913eee0a6555cd6e1efa9 (patch)
tree4e5f419fe6e92ebfa05f0115c8925f83969acb93 /Lib/test/test_binascii.py
parent8691bff6db78a45fd89a385401ece64921867500 (diff)
downloadcpython-08316769620c83e32a6913eee0a6555cd6e1efa9.zip
cpython-08316769620c83e32a6913eee0a6555cd6e1efa9.tar.gz
cpython-08316769620c83e32a6913eee0a6555cd6e1efa9.tar.bz2
Issue #13637: "a2b" functions in the binascii module now accept ASCII-only unicode strings.
Diffstat (limited to 'Lib/test/test_binascii.py')
-rw-r--r--Lib/test/test_binascii.py34
1 files changed, 31 insertions, 3 deletions
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py
index 1e9e888..04d8f9d 100644
--- a/Lib/test/test_binascii.py
+++ b/Lib/test/test_binascii.py
@@ -208,9 +208,9 @@ class BinASCIITest(unittest.TestCase):
except Exception as err:
self.fail("{}({!r}) raises {!r}".format(func, empty, err))
- def test_unicode_strings(self):
- # Unicode strings are not accepted.
- for func in all_functions:
+ def test_unicode_b2a(self):
+ # Unicode strings are not accepted by b2a_* functions.
+ for func in set(all_functions) - set(a2b_functions) | {'rledecode_hqx'}:
try:
self.assertRaises(TypeError, getattr(binascii, func), "test")
except Exception as err:
@@ -218,6 +218,34 @@ class BinASCIITest(unittest.TestCase):
# crc_hqx needs 2 arguments
self.assertRaises(TypeError, binascii.crc_hqx, "test", 0)
+ def test_unicode_a2b(self):
+ # Unicode strings are accepted by a2b_* functions.
+ MAX_ALL = 45
+ raw = self.rawdata[:MAX_ALL]
+ for fa, fb in zip(a2b_functions, b2a_functions):
+ if fa == 'rledecode_hqx':
+ # Takes non-ASCII data
+ continue
+ a2b = getattr(binascii, fa)
+ b2a = getattr(binascii, fb)
+ try:
+ a = b2a(self.type2test(raw))
+ binary_res = a2b(a)
+ a = a.decode('ascii')
+ res = a2b(a)
+ except Exception as err:
+ self.fail("{}/{} conversion raises {!r}".format(fb, fa, err))
+ if fb == 'b2a_hqx':
+ # b2a_hqx returns a tuple
+ res, _ = res
+ binary_res, _ = binary_res
+ self.assertEqual(res, raw, "{}/{} conversion: "
+ "{!r} != {!r}".format(fb, fa, res, raw))
+ self.assertEqual(res, binary_res)
+ self.assertIsInstance(res, bytes)
+ # non-ASCII string
+ self.assertRaises(ValueError, a2b, "\x80")
+
class ArrayBinASCIITest(BinASCIITest):
def type2test(self, s):