diff options
Diffstat (limited to 'Lib/test/test_binascii.py')
| -rw-r--r-- | Lib/test/test_binascii.py | 34 | 
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):  | 
