From 09143233280337583bb9dec019d885a8114b9e4d Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 6 May 2013 10:48:10 +0100 Subject: [PATCH] Added test to verify copysize handling in copy_expert Not an original psycopg2 bug but present in pure python implementation, e.g. ctypes issue #25 and cffi issue #5. https://github.com/mvantellingen/psycopg2-ctypes/issues/25 https://github.com/chtd/psycopg2cffi/pull/5 --- tests/test_copy.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_copy.py b/tests/test_copy.py index 4ed253e9..12930859 100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -212,6 +212,20 @@ class CopyTests(unittest.TestCase): f.seek(0) self.assertEqual(f.readline().rstrip(), about) + # same tests with setting size + f = io.StringIO() + f.write(about) + f.seek(0) + exp_size = 123 + # hack here to leave file as is, only check size when reading + real_read = f.read + def read(_size, f=f, exp_size=exp_size): + self.assertEqual(_size, exp_size) + return real_read(_size) + f.read = read + curs.copy_expert('COPY tcopy (data) FROM STDIN', f, size=exp_size) + curs.execute("select data from tcopy;") + self.assertEqual(curs.fetchone()[0], abin) def _copy_from(self, curs, nrecs, srec, copykw): f = StringIO()