Commits

Anonymous committed 4a1f056

Pass byte strings into struct.{pack,unpack} instead of str strings when testing

  • Participants
  • Parent commits c2a09b9
  • Branches py3k-struct

Comments (0)

Files changed (2)

File lib-python/3/test/test_struct.py

 
         # format lists containing only count spec should result in an error
         self.assertRaises(struct.error, struct.pack, '12345')
-        self.assertRaises(struct.error, struct.unpack, '12345', '')
+        self.assertRaises(struct.error, struct.unpack, '12345', b'')
         self.assertRaises(struct.error, struct.pack_into, '12345', store, 0)
         self.assertRaises(struct.error, struct.unpack_from, '12345', store, 0)
 
         # Format lists with trailing count spec should result in an error
-        self.assertRaises(struct.error, struct.pack, 'c12345', 'x')
-        self.assertRaises(struct.error, struct.unpack, 'c12345', 'x')
+        self.assertRaises(struct.error, struct.pack, 'c12345', b'x')
+        self.assertRaises(struct.error, struct.unpack, 'c12345', b'x')
         self.assertRaises(struct.error, struct.pack_into, 'c12345', store, 0,
-                           'x')
+                           b'x')
         self.assertRaises(struct.error, struct.unpack_from, 'c12345', store,
                            0)
 
         # Mixed format tests
-        self.assertRaises(struct.error, struct.pack, '14s42', 'spam and eggs')
+        self.assertRaises(struct.error, struct.pack, '14s42', b'spam and eggs')
         self.assertRaises(struct.error, struct.unpack, '14s42',
-                          'spam and eggs')
+                          b'spam and eggs')
         self.assertRaises(struct.error, struct.pack_into, '14s42', store, 0,
-                          'spam and eggs')
+                          b'spam and eggs')
         self.assertRaises(struct.error, struct.unpack_from, '14s42', store, 0)
 
     def test_Struct_reinitialization(self):

File pypy/module/struct/test/test_struct.py

 
 
 class AppTestStruct(object):
-    spaceconfig = dict(usemodules=['struct'])
+    spaceconfig = dict(usemodules=['struct', 'array'])
 
     def setup_class(cls):
         """
         assert self.struct.unpack("ii", b) == (62, 12)
         raises(self.struct.error, self.struct.unpack, "i", b)
 
+    def test_trailing_counter(self):
+        import array
+        store = array.array('b', b' '*100)
+
+        # format lists containing only count spec should result in an error
+        raises(self.struct.error, self.struct.pack, '12345')
+        raises(self.struct.error, self.struct.unpack, '12345', b'')
+        raises(self.struct.error, self.struct.pack_into, '12345', store, 0)
+        raises(self.struct.error, self.struct.unpack_from, '12345', store, 0)
+
+        # Format lists with trailing count spec should result in an error
+        raises(self.struct.error, self.struct.pack, 'c12345', b'x')
+        raises(self.struct.error, self.struct.unpack, 'c12345', b'x')
+        raises(self.struct.error, self.struct.pack_into, 'c12345', store, 0,
+                           b'x')
+        raises(self.struct.error, self.struct.unpack_from, 'c12345', store,
+                           0)
+
+        # Mixed format tests
+        raises(self.struct.error, self.struct.pack, '14s42', b'spam and eggs')
+        raises(self.struct.error, self.struct.unpack, '14s42',
+                          b'spam and eggs')
+        raises(self.struct.error, self.struct.pack_into, '14s42', store, 0,
+                          b'spam and eggs')
+        raises(self.struct.error, self.struct.unpack_from, '14s42', store, 0)
+
+
 
 class AppTestStructBuffer(object):
     spaceconfig = dict(usemodules=['struct', '__pypy__'])