예제 #1
0
 def test_empty_string(self):
     # A test for SF bug #1022953.  Make sure SystemError is not raised.
     empty = self.type2test(b'')
     for func in all_functions:
         if func == 'crc_hqx':
             # crc_hqx needs 2 arguments
             binascii.crc_hqx(empty, 0)
             continue
         f = getattr(binascii, func)
         try:
             f(empty)
         except Exception as err:
             self.fail("{}({!r}) raises {!r}".format(func, empty, err))
예제 #2
0
 def test_returned_value(self):
     # Limit to the minimum of all limits (b2a_uu)
     MAX_ALL = 45
     raw = self.rawdata[:MAX_ALL]
     for fa, fb in zip(a2b_functions, b2a_functions):
         a2b = getattr(binascii, fa)
         b2a = getattr(binascii, fb)
         try:
             a = b2a(self.type2test(raw))
             res = a2b(self.type2test(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
         self.assertEqual(res, raw, "{}/{} conversion: "
                          "{!r} != {!r}".format(fb, fa, res, raw))
         self.assertIsInstance(res, bytes)
         self.assertIsInstance(a, bytes)
         self.assertLess(max(a), 128)
     self.assertIsInstance(binascii.crc_hqx(raw, 0), int)
     self.assertIsInstance(binascii.crc32(raw), int)