[pypy-commit] pypy default: More tests
arigo
noreply at buildbot.pypy.org
Mon Sep 24 18:10:24 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r57500:cc7d7bec8896
Date: 2012-09-24 15:50 +0200
http://bitbucket.org/pypy/pypy/changeset/cc7d7bec8896/
Log: More tests
diff --git a/pypy/module/_csv/interp_reader.py b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -40,8 +40,8 @@
try:
ff = string_to_float(field)
except ParseStringError, e:
- raise OperationError(space.w_ValueError,
- space.wrap(e.msg))
+ raise OperationError(self.space.w_ValueError,
+ self.space.wrap(e.msg))
w_obj = self.space.wrap(ff)
else:
w_obj = self.space.wrap(field)
diff --git a/pypy/module/_csv/test/test_reader.py b/pypy/module/_csv/test/test_reader.py
--- a/pypy/module/_csv/test/test_reader.py
+++ b/pypy/module/_csv/test/test_reader.py
@@ -31,3 +31,55 @@
# cannot handle null bytes for the moment
self._read_test(['ab\0c'], 'Error', strict = 1)
self._read_test(['"ab"c'], [['abc']], doublequote = 0)
+
+ def test_read_eol(self):
+ self._read_test(['a,b'], [['a','b']])
+ self._read_test(['a,b\n'], [['a','b']])
+ self._read_test(['a,b\r\n'], [['a','b']])
+ self._read_test(['a,b\r'], [['a','b']])
+ self._read_test(['a,b\rc,d'], 'Error')
+ self._read_test(['a,b\nc,d'], 'Error')
+ self._read_test(['a,b\r\nc,d'], 'Error')
+
+ def test_read_escape(self):
+ self._read_test(['a,\\b,c'], [['a', 'b', 'c']], escapechar='\\')
+ self._read_test(['a,b\\,c'], [['a', 'b,c']], escapechar='\\')
+ self._read_test(['a,"b\\,c"'], [['a', 'b,c']], escapechar='\\')
+ self._read_test(['a,"b,\\c"'], [['a', 'b,c']], escapechar='\\')
+ self._read_test(['a,"b,c\\""'], [['a', 'b,c"']], escapechar='\\')
+ self._read_test(['a,"b,c"\\'], [['a', 'b,c\\']], escapechar='\\')
+
+ def test_read_quoting(self):
+ import _csv as csv
+ self._read_test(['1,",3,",5'], [['1', ',3,', '5']])
+ self._read_test(['1,",3,",5'], [['1', '"', '3', '"', '5']],
+ quotechar=None, escapechar='\\')
+ self._read_test(['1,",3,",5'], [['1', '"', '3', '"', '5']],
+ quoting=csv.QUOTE_NONE, escapechar='\\')
+ # will this fail where locale uses comma for decimals?
+ self._read_test([',3,"5",7.3, 9'], [['', 3, '5', 7.3, 9]],
+ quoting=csv.QUOTE_NONNUMERIC)
+ self._read_test(['"a\nb", 7'], [['a\nb', ' 7']])
+ raises(ValueError, self._read_test,
+ ['abc,3'], [[]],
+ quoting=csv.QUOTE_NONNUMERIC)
+
+ def test_read_bigfield(self):
+ # This exercises the buffer realloc functionality and field size
+ # limits.
+ import _csv as csv
+ limit = csv.field_size_limit()
+ try:
+ size = 50
+ bigstring = 'X' * size
+ bigline = '%s,%s' % (bigstring, bigstring)
+ self._read_test([bigline], [[bigstring, bigstring]])
+ csv.field_size_limit(size)
+ self._read_test([bigline], [[bigstring, bigstring]])
+ assert csv.field_size_limit() == size
+ csv.field_size_limit(size-1)
+ self._read_test([bigline], 'Error')
+ raises(TypeError, csv.field_size_limit, None)
+ raises(TypeError, csv.field_size_limit, 1, None)
+ finally:
+ csv.field_size_limit(limit)
More information about the pypy-commit
mailing list