From 6d4b00ccc15f46702e1ab9242f16f4a80003f95a Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Thu, 14 Jan 2010 16:33:34 +0000 Subject: 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. ........ --- Lib/test/test_binascii.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'Lib/test/test_binascii.py') diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 65de81b8c1..a631a6abbe 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -3,14 +3,19 @@ from test import support import unittest import binascii +import array class BinASCIITest(unittest.TestCase): + type2test = bytes # 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 - data += bytes(range(256)) - data += b"\r\nHello world.\n" + rawdata += bytes(range(256)) + rawdata += b"\r\nHello world.\n" + + def setUp(self): + self.data = self.type2test(self.rawdata) def test_exceptions(self): # Check module exceptions @@ -44,7 +49,7 @@ class BinASCIITest(unittest.TestCase): for line in lines: b = binascii.a2b_base64(line) res += b - self.assertEqual(res, self.data) + self.assertEqual(res, self.rawdata) def test_base64invalid(self): # Test base64 with random invalid characters sprinkled throughout @@ -76,7 +81,7 @@ class BinASCIITest(unittest.TestCase): for line in map(addnoise, lines): b = binascii.a2b_base64(line) res += b - self.assertEqual(res, self.data) + self.assertEqual(res, self.rawdata) # Test base64 with just invalid characters, which should return # empty strings. TBD: shouldn't it raise an exception instead ? @@ -93,7 +98,7 @@ class BinASCIITest(unittest.TestCase): for line in lines: b = binascii.a2b_uu(line) 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"\x80"), b"\x00"*32) @@ -176,8 +181,20 @@ class BinASCIITest(unittest.TestCase): binascii.crc_hqx, binascii.crc32): 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(): - support.run_unittest(BinASCIITest) + support.run_unittest(BinASCIITest, + ArrayBinASCIITest, + MemoryviewBinASCIITest) if __name__ == "__main__": test_main() -- cgit v1.2.1