summaryrefslogtreecommitdiff
path: root/tests/test_copy.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-12-03 18:47:19 -0800
committerJon Dufresne <jon.dufresne@gmail.com>2017-12-10 10:51:07 -0800
commit1a8e992fcc87b2d15911b60cc9220ec50a70a4ff (patch)
treeb24d491d6ecff95cfbee78409a037a49f182b744 /tests/test_copy.py
parent9de46e416e5ac1be1c5ff170d1c1ada5b8d7278f (diff)
downloadpsycopg2-1a8e992fcc87b2d15911b60cc9220ec50a70a4ff.tar.gz
Use relative imports throughout tests
The tests relied on Python2 relative import semantics. Python3 changed import semantics to always search sys.path by default. To import using a relative path it must have a leading dot. Forward compatible with newer Pythons. Works towards the goal of moving tests outside of the installed package. For more information, see PEP-328: https://www.python.org/dev/peps/pep-0328/
Diffstat (limited to 'tests/test_copy.py')
-rwxr-xr-xtests/test_copy.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/tests/test_copy.py b/tests/test_copy.py
index 3201fb2..d8eba08 100755
--- a/tests/test_copy.py
+++ b/tests/test_copy.py
@@ -25,7 +25,7 @@
import sys
import string
import unittest
-from testutils import (ConnectingTestCase, decorate_all_tests,
+from .testutils import (ConnectingTestCase, decorate_all_tests,
skip_before_postgres, slow)
from cStringIO import StringIO
from itertools import cycle, izip
@@ -33,8 +33,8 @@ from subprocess import Popen, PIPE
import psycopg2
import psycopg2.extensions
-from testutils import skip_copy_if_green
-from testconfig import dsn
+from .testutils import skip_copy_if_green
+from .testconfig import dsn
if sys.version_info[0] < 3:
@@ -99,7 +99,7 @@ class CopyTests(ConnectingTestCase):
def test_copy_from_cols(self):
curs = self.conn.cursor()
f = StringIO()
- for i in xrange(10):
+ for i in range(10):
f.write("%s\n" % (i,))
f.seek(0)
@@ -111,7 +111,7 @@ class CopyTests(ConnectingTestCase):
def test_copy_from_cols_err(self):
curs = self.conn.cursor()
f = StringIO()
- for i in xrange(10):
+ for i in range(10):
f.write("%s\n" % (i,))
f.seek(0)
@@ -141,7 +141,7 @@ class CopyTests(ConnectingTestCase):
about = abin.decode('latin1').replace('\\', '\\\\')
else:
- abin = bytes(range(32, 127) + range(160, 256)).decode('latin1')
+ abin = bytes(list(range(32, 127)) + list(range(160, 256))).decode('latin1')
about = abin.replace('\\', '\\\\')
curs = self.conn.cursor()
@@ -162,7 +162,7 @@ class CopyTests(ConnectingTestCase):
abin = ''.join(map(chr, range(32, 127) + range(160, 255)))
about = abin.replace('\\', '\\\\')
else:
- abin = bytes(range(32, 127) + range(160, 255)).decode('latin1')
+ abin = bytes(list(range(32, 127)) + list(range(160, 255))).decode('latin1')
about = abin.replace('\\', '\\\\').encode('latin1')
curs = self.conn.cursor()
@@ -185,7 +185,7 @@ class CopyTests(ConnectingTestCase):
about = abin.replace('\\', '\\\\')
else:
- abin = bytes(range(32, 127) + range(160, 256)).decode('latin1')
+ abin = bytes(list(range(32, 127)) + list(range(160, 256))).decode('latin1')
about = abin.replace('\\', '\\\\')
import io
@@ -225,7 +225,7 @@ class CopyTests(ConnectingTestCase):
def _copy_from(self, curs, nrecs, srec, copykw):
f = StringIO()
- for i, c in izip(xrange(nrecs), cycle(string.ascii_letters)):
+ for i, c in zip(range(nrecs), cycle(string.ascii_letters)):
l = c * srec
f.write("%s\t%s\n" % (i, l))