mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merge note: only the tests have been kept here, since the rest was already
a backport. Merged revisions 77497 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77497 | antoine.pitrou | 2010-01-14 17:27:09 +0100 (jeu., 14 janv. 2010) | 5 lines Issue #7703: Add support for the new buffer API to functions of the binascii module. Backported from py3k by Florent Xicluna, with some additional tests. ........
This commit is contained in:
parent
853c3bbc4c
commit
6d4b00ccc1
1 changed files with 24 additions and 7 deletions
|
@ -3,14 +3,19 @@
|
||||||
from test import support
|
from test import support
|
||||||
import unittest
|
import unittest
|
||||||
import binascii
|
import binascii
|
||||||
|
import array
|
||||||
|
|
||||||
class BinASCIITest(unittest.TestCase):
|
class BinASCIITest(unittest.TestCase):
|
||||||
|
|
||||||
|
type2test = bytes
|
||||||
# Create binary test data
|
# Create binary test data
|
||||||
data = b"The quick brown fox jumps over the lazy dog.\r\n"
|
rawdata = b"The quick brown fox jumps over the lazy dog.\r\n"
|
||||||
# Be slow so we don't depend on other modules
|
# Be slow so we don't depend on other modules
|
||||||
data += bytes(range(256))
|
rawdata += bytes(range(256))
|
||||||
data += b"\r\nHello world.\n"
|
rawdata += b"\r\nHello world.\n"
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.data = self.type2test(self.rawdata)
|
||||||
|
|
||||||
def test_exceptions(self):
|
def test_exceptions(self):
|
||||||
# Check module exceptions
|
# Check module exceptions
|
||||||
|
@ -44,7 +49,7 @@ class BinASCIITest(unittest.TestCase):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
b = binascii.a2b_base64(line)
|
b = binascii.a2b_base64(line)
|
||||||
res += b
|
res += b
|
||||||
self.assertEqual(res, self.data)
|
self.assertEqual(res, self.rawdata)
|
||||||
|
|
||||||
def test_base64invalid(self):
|
def test_base64invalid(self):
|
||||||
# Test base64 with random invalid characters sprinkled throughout
|
# Test base64 with random invalid characters sprinkled throughout
|
||||||
|
@ -76,7 +81,7 @@ class BinASCIITest(unittest.TestCase):
|
||||||
for line in map(addnoise, lines):
|
for line in map(addnoise, lines):
|
||||||
b = binascii.a2b_base64(line)
|
b = binascii.a2b_base64(line)
|
||||||
res += b
|
res += b
|
||||||
self.assertEqual(res, self.data)
|
self.assertEqual(res, self.rawdata)
|
||||||
|
|
||||||
# Test base64 with just invalid characters, which should return
|
# Test base64 with just invalid characters, which should return
|
||||||
# empty strings. TBD: shouldn't it raise an exception instead ?
|
# empty strings. TBD: shouldn't it raise an exception instead ?
|
||||||
|
@ -93,7 +98,7 @@ class BinASCIITest(unittest.TestCase):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
b = binascii.a2b_uu(line)
|
b = binascii.a2b_uu(line)
|
||||||
res += b
|
res += b
|
||||||
self.assertEqual(res, self.data)
|
self.assertEqual(res, self.rawdata)
|
||||||
|
|
||||||
self.assertEqual(binascii.a2b_uu(b"\x7f"), b"\x00"*31)
|
self.assertEqual(binascii.a2b_uu(b"\x7f"), b"\x00"*31)
|
||||||
self.assertEqual(binascii.a2b_uu(b"\x80"), b"\x00"*32)
|
self.assertEqual(binascii.a2b_uu(b"\x80"), b"\x00"*32)
|
||||||
|
@ -176,8 +181,20 @@ class BinASCIITest(unittest.TestCase):
|
||||||
binascii.crc_hqx, binascii.crc32):
|
binascii.crc_hqx, binascii.crc32):
|
||||||
self.assertRaises(TypeError, f, "test")
|
self.assertRaises(TypeError, f, "test")
|
||||||
|
|
||||||
|
|
||||||
|
class ArrayBinASCIITest(BinASCIITest):
|
||||||
|
def type2test(self, s):
|
||||||
|
return array.array('B', list(s))
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryviewBinASCIITest(BinASCIITest):
|
||||||
|
type2test = memoryview
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(BinASCIITest)
|
support.run_unittest(BinASCIITest,
|
||||||
|
ArrayBinASCIITest,
|
||||||
|
MemoryviewBinASCIITest)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_main()
|
test_main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue