[Python-checkins] r77498 - in python/branches/py3k: Lib/test/test_binascii.py

antoine.pitrou python-checkins at python.org
Thu Jan 14 17:33:35 CET 2010


Author: antoine.pitrou
Date: Thu Jan 14 17:33:34 2010
New Revision: 77498

Log:
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.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_binascii.py

Modified: python/branches/py3k/Lib/test/test_binascii.py
==============================================================================
--- python/branches/py3k/Lib/test/test_binascii.py	(original)
+++ python/branches/py3k/Lib/test/test_binascii.py	Thu Jan 14 17:33:34 2010
@@ -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 @@
         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 @@
         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 @@
         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 @@
                   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()


More information about the Python-checkins mailing list