mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
Add a test to make sure zlib.crc32 and binascii.crc32 return the same thing.
Fix a buglet in binascii.crc32, the second optional argument could previously have a signedness mismatch with the C variable its going into.
This commit is contained in:
parent
6a644f92ef
commit
c856fa811d
2 changed files with 7 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
from test import test_support
|
from test import test_support
|
||||||
import zlib
|
import zlib
|
||||||
|
import binascii
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +48,11 @@ class ChecksumTestCase(unittest.TestCase):
|
||||||
self.assertEqual(zlib.adler32(foo+foo), -721416943)
|
self.assertEqual(zlib.adler32(foo+foo), -721416943)
|
||||||
self.assertEqual(zlib.adler32('spam'), 72286642)
|
self.assertEqual(zlib.adler32('spam'), 72286642)
|
||||||
|
|
||||||
|
def test_same_as_binascii_crc32(self):
|
||||||
|
foo = 'abcdefghijklmnop'
|
||||||
|
self.assertEqual(binascii.crc32(foo), zlib.crc32(foo))
|
||||||
|
self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ExceptionTestCase(unittest.TestCase):
|
class ExceptionTestCase(unittest.TestCase):
|
||||||
|
|
|
@ -874,7 +874,7 @@ binascii_crc32(PyObject *self, PyObject *args)
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
long result;
|
long result;
|
||||||
|
|
||||||
if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
|
if ( !PyArg_ParseTuple(args, "s#|k:crc32", &bin_data, &len, &crc) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
crc = ~ crc;
|
crc = ~ crc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue