From 1e94018473e33f53c251dd99cd8b49f58ed5813f 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 fd6c14a1..7764be62 100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -199,6 +199,20 @@ class CopyTests(ConnectingTestCase): 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()