[pypy-commit] pypy py3k-struct: Pass byte strings into struct.{pack, unpack} instead of str strings when testing
Jason Chu
noreply at buildbot.pypy.org
Wed Mar 20 01:02:03 CET 2013
Author: Jason Chu <jason.chu at yougov.com>
Branch: py3k-struct
Changeset: r62517:4a1f0569d60f
Date: 2013-03-19 13:21 -0700
http://bitbucket.org/pypy/pypy/changeset/4a1f0569d60f/
Log: Pass byte strings into struct.{pack,unpack} instead of str strings
when testing
diff --git a/lib-python/3/test/test_struct.py b/lib-python/3/test/test_struct.py
--- a/lib-python/3/test/test_struct.py
+++ b/lib-python/3/test/test_struct.py
@@ -529,24 +529,24 @@
# 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):
diff --git a/pypy/module/struct/test/test_struct.py b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -7,7 +7,7 @@
class AppTestStruct(object):
- spaceconfig = dict(usemodules=['struct'])
+ spaceconfig = dict(usemodules=['struct', 'array'])
def setup_class(cls):
"""
@@ -386,6 +386,33 @@
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__'])
More information about the pypy-commit
mailing list