[Python-checkins] python/nondist/sandbox/csv/test test_csv.py,1.29,1.30
montanaro@users.sourceforge.net
montanaro@users.sourceforge.net
Tue, 11 Feb 2003 06:48:36 -0800
Update of /cvsroot/python/python/nondist/sandbox/csv/test
In directory sc8-pr-cvs1:/tmp/cvs-serv10178
Modified Files:
test_csv.py
Log Message:
add some leakage tests (I think writerow() leaks)
Index: test_csv.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/csv/test/test_csv.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** test_csv.py 11 Feb 2003 14:14:02 -0000 1.29
--- test_csv.py 11 Feb 2003 14:48:32 -0000 1.30
***************
*** 6,9 ****
--- 6,10 ----
from StringIO import StringIO
import csv
+ import gc
class Test_Csv(unittest.TestCase):
***************
*** 446,449 ****
--- 447,516 ----
expected = ",".join(a)+"\r\n"
self.assertEqual(fileobj.getvalue(), expected)
+
+ if hasattr(sys, "gettotalrefcount"):
+ class TestLeaks(unittest.TestCase):
+ def test_create_read(self):
+ deltas = []
+ lastrc = sys.gettotalrefcount()
+ for i in xrange(20):
+ gc.collect()
+ self.assertEqual(gc.garbage, [])
+ rc = sys.gettotalrefcount()
+ csv.reader(["a,b,c\r\n"])
+ csv.reader(["a,b,c\r\n"])
+ csv.reader(["a,b,c\r\n"])
+ deltas.append(rc-lastrc)
+ lastrc = rc
+ # if csv.reader() leaks, delta should be 3 or more
+ self.assertEqual(deltas[-1] < 3, True)
+
+ def test_create_write(self):
+ deltas = []
+ lastrc = sys.gettotalrefcount()
+ s = StringIO()
+ for i in xrange(20):
+ gc.collect()
+ self.assertEqual(gc.garbage, [])
+ rc = sys.gettotalrefcount()
+ csv.writer(s)
+ csv.writer(s)
+ csv.writer(s)
+ deltas.append(rc-lastrc)
+ lastrc = rc
+ # if csv.writer() leaks, delta should be 3 or more
+ self.assertEqual(deltas[-1] < 3, True)
+
+ def test_read(self):
+ deltas = []
+ lastrc = sys.gettotalrefcount()
+ rows = ["a,b,c\r\n"]*5
+ for i in xrange(20):
+ gc.collect()
+ self.assertEqual(gc.garbage, [])
+ rc = sys.gettotalrefcount()
+ rdr = csv.reader(rows)
+ for row in rdr:
+ pass
+ deltas.append(rc-lastrc)
+ lastrc = rc
+ # if reader leaks during read, delta should be 5 or more
+ self.assertEqual(deltas[-1] < 5, True)
+
+ def test_write(self):
+ deltas = []
+ lastrc = sys.gettotalrefcount()
+ rows = [[1,2,3]]*5
+ s = StringIO()
+ for i in xrange(20):
+ gc.collect()
+ self.assertEqual(gc.garbage, [])
+ rc = sys.gettotalrefcount()
+ writer = csv.writer(s)
+ for row in rows:
+ writer.writerow(row)
+ deltas.append(rc-lastrc)
+ lastrc = rc
+ # if reader leaks during read, delta should be 5 or more
+ self.assertEqual(deltas[-1] < 5, True)
def _testclasses():