diff --git a/tests/test_copy.py b/tests/test_copy.py index e800aed0..639c1691 100755 --- a/tests/test_copy.py +++ b/tests/test_copy.py @@ -31,17 +31,11 @@ from subprocess import Popen, PIPE import psycopg2 import psycopg2.extensions -from .testutils import skip_copy_if_green +from .testutils import skip_copy_if_green, TextIOBase from .testconfig import dsn -if sys.version_info[0] < 3: - _base = object -else: - from io import TextIOBase as _base - - -class MinimalRead(_base): +class MinimalRead(TextIOBase): """A file wrapper exposing the minimal interface to copy from.""" def __init__(self, f): self.f = f @@ -53,7 +47,7 @@ class MinimalRead(_base): return self.f.readline() -class MinimalWrite(_base): +class MinimalWrite(TextIOBase): """A file wrapper exposing the minimal interface to copy to.""" def __init__(self, f): self.f = f @@ -351,7 +345,7 @@ conn.close() self.assertEqual(0, proc.returncode) def test_copy_from_propagate_error(self): - class BrokenRead(_base): + class BrokenRead(TextIOBase): def read(self, size): return 1 / 0 @@ -368,7 +362,7 @@ conn.close() self.assert_('ZeroDivisionError' in str(e)) def test_copy_to_propagate_error(self): - class BrokenWrite(_base): + class BrokenWrite(TextIOBase): def write(self, data): return 1 / 0 diff --git a/tests/testutils.py b/tests/testutils.py index 8dab1b63..24b99e52 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -43,12 +43,15 @@ from .testconfig import green if sys.version_info[0] == 2: # Python 2 from StringIO import StringIO + TextIOBase = object long = long reload = reload unichr = unichr + else: # Python 3 from io import StringIO # noqa + from io import TextIOBase # noqa from importlib import reload # noqa long = int unichr = chr