summaryrefslogtreecommitdiff
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:55:58 -0800
commit389f6c08d9536060184bfd5c8ea2491a4a91c2fb (patch)
treef85e494ab9c681494616ec6bb9b9d01852c62f90
parentc86e682153f4cb8d99e490b2af964f3f11e3489f (diff)
downloadpsycopg2-389f6c08d9536060184bfd5c8ea2491a4a91c2fb.tar.gz
Avoid installing tests to site-packages
For library end users, there is no need to install tests alongside the package itself. This keeps the tests available for development without adding extra packages to user's site-packages directory. Reduces the size of the installed package. Avoids accidental execution of test code by an installed package.
-rw-r--r--.appveyor.yml3
-rw-r--r--.travis.yml1
-rw-r--r--Makefile5
-rw-r--r--NEWS3
-rw-r--r--doc/src/install.rst4
-rwxr-xr-xscripts/refcounter.py4
-rwxr-xr-xscripts/travis_test.sh4
-rw-r--r--setup.py4
-rwxr-xr-xtests/test_async.py5
-rwxr-xr-xtests/test_copy.py5
-rwxr-xr-xtests/test_cursor.py2
-rwxr-xr-xtests/test_errcodes.py4
-rwxr-xr-xtests/test_extras_dictcursor.py2
-rwxr-xr-xtests/test_module.py3
-rwxr-xr-xtests/test_quote.py2
-rwxr-xr-xtests/test_sql.py4
-rwxr-xr-xtests/test_types_basic.py6
-rwxr-xr-xtests/test_types_extras.py16
-rw-r--r--tests/testutils.py17
19 files changed, 56 insertions, 38 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 44dbdbd..a49c802 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -238,6 +238,7 @@ build_script:
- "%PYTHON%\\python.exe setup.py build_ext --have-ssl --pg-config %PGTOP%\\bin\\pg_config.exe -l libpgcommon -l libpgport -L %OPENSSLTOP%\\lib -I %OPENSSLTOP%\\include"
- "%PYTHON%\\python.exe setup.py build"
- "%PYTHON%\\python.exe setup.py install"
+ - RD /S /Q psycopg2.egg-info
#after_build:
@@ -251,4 +252,4 @@ test_script:
- "%PYTHON%\\python.exe -c \"import psycopg2; print(psycopg2.__version__)\""
- "%PYTHON%\\python.exe -c \"import psycopg2; print(psycopg2.__libpq_version__)\""
- "%PYTHON%\\python.exe -c \"import psycopg2; print(psycopg2.extensions.libpq_version())\""
- - "%PYTHON%\\python.exe -c \"from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')\" --verbose"
+ - "%PYTHON%\\python.exe -c \"import tests; tests.unittest.main(defaultTest='tests.test_suite')\" --verbose"
diff --git a/.travis.yml b/.travis.yml
index e6182a7..2fbf701 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,6 +12,7 @@ python:
install:
- python setup.py install
+ - rm -rf psycopg2.egg-info
- sudo scripts/travis_prepare.sh
script:
diff --git a/Makefile b/Makefile
index a8f491e..07fbc21 100644
--- a/Makefile
+++ b/Makefile
@@ -29,8 +29,7 @@ SOURCE := $(SOURCE_C) $(SOURCE_PY) $(SOURCE_TESTS) $(SOURCE_DOC)
PACKAGE := $(BUILD_DIR)/psycopg2
PLATLIB := $(PACKAGE)/_psycopg.so
-PURELIB := $(patsubst lib/%,$(PACKAGE)/%,$(SOURCE_PY)) \
- $(patsubst tests/%,$(PACKAGE)/tests/%,$(SOURCE_TESTS))
+PURELIB := $(patsubst lib/%,$(PACKAGE)/%,$(SOURCE_PY))
BUILD_OPT := --build-lib=$(BUILD_DIR)
BUILD_EXT_OPT := --build-lib=$(BUILD_DIR)
@@ -66,7 +65,7 @@ env:
$(MAKE) -C doc $@
check:
- PYTHONPATH=$(BUILD_DIR):$(PYTHONPATH) $(PYTHON) -c "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
+ PYTHONPATH=$(BUILD_DIR):$(PYTHONPATH) $(PYTHON) -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
testdb:
@echo "* Creating $(TESTDB)"
diff --git a/NEWS b/NEWS
index fe77027..a108525 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@ Other changes:
- Dropped support for Python 2.6, 3.2, 3.3.
- Dropped `psycopg1` module.
- Dropped deprecated ``register_tstz_w_secs()`` (was previously a no-op).
+- The ``psycopg2.test`` package is no longer installed by ``python setup.py
+ install``. The test source files now are compatible with Python 2 and 3
+ without using 2to3.
What's new in psycopg 2.7.4
diff --git a/doc/src/install.rst b/doc/src/install.rst
index 8b6651d..6d30e34 100644
--- a/doc/src/install.rst
+++ b/doc/src/install.rst
@@ -267,11 +267,11 @@ Running the test suite
----------------------
Once `!psycopg2` is installed you can run the test suite to verify it is
-working correctly. You can run:
+working correctly. From the source directory, you can run:
.. code-block:: console
- $ python -c "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
+ $ python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')" --verbose
The tests run against a database called ``psycopg2_test`` on UNIX socket and
the standard port. You can configure a different database to run the test by
diff --git a/scripts/refcounter.py b/scripts/refcounter.py
index f1642e7..f41dc21 100755
--- a/scripts/refcounter.py
+++ b/scripts/refcounter.py
@@ -30,8 +30,8 @@ from collections import defaultdict
def main():
opt = parse_args()
- import psycopg2.tests
- test = psycopg2.tests
+ import tests
+ test = tests
if opt.suite:
test = getattr(test, opt.suite)
diff --git a/scripts/travis_test.sh b/scripts/travis_test.sh
index 033482b..0320654 100755
--- a/scripts/travis_test.sh
+++ b/scripts/travis_test.sh
@@ -34,13 +34,13 @@ run_test () {
export PSYCOPG2_TEST_REPL_DSN=
unset PSYCOPG2_TEST_GREEN
python -c \
- "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
+ "import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
$VERBOSE
printf "\n\nRunning tests against PostgreSQL $VERSION (green mode)\n\n"
export PSYCOPG2_TEST_GREEN=1
python -c \
- "from psycopg2 import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
+ "import tests; tests.unittest.main(defaultTest='tests.test_suite')" \
$VERBOSE
}
diff --git a/setup.py b/setup.py
index e6144af..0e21462 100644
--- a/setup.py
+++ b/setup.py
@@ -624,8 +624,8 @@ setup(name="psycopg2",
long_description="\n".join(readme.split("\n")[2:]).lstrip(),
classifiers=[x for x in classifiers.split("\n") if x],
data_files=data_files,
- package_dir={'psycopg2': 'lib', 'psycopg2.tests': 'tests'},
- packages=['psycopg2', 'psycopg2.tests'],
+ package_dir={'psycopg2': 'lib'},
+ packages=['psycopg2'],
cmdclass={
'build_ext': psycopg_build_ext,
'build_py': build_py, },
diff --git a/tests/test_async.py b/tests/test_async.py
index 6469a25..ce5e9b1 100755
--- a/tests/test_async.py
+++ b/tests/test_async.py
@@ -30,9 +30,8 @@ import psycopg2
from psycopg2 import extensions as ext
import time
-import StringIO
-from .testutils import ConnectingTestCase
+from .testutils import ConnectingTestCase, StringIO
class PollableStub(object):
@@ -241,7 +240,7 @@ class AsyncTests(ConnectingTestCase):
# copy should fail
self.assertRaises(psycopg2.ProgrammingError,
cur.copy_from,
- StringIO.StringIO("1\n3\n5\n\\.\n"), "table1")
+ StringIO("1\n3\n5\n\\.\n"), "table1")
def test_lobject_while_async(self):
# large objects should be prohibited
diff --git a/tests/test_copy.py b/tests/test_copy.py
index d8eba08..b16e1dd 100755
--- a/tests/test_copy.py
+++ b/tests/test_copy.py
@@ -26,9 +26,8 @@ import sys
import string
import unittest
from .testutils import (ConnectingTestCase, decorate_all_tests,
- skip_before_postgres, slow)
-from cStringIO import StringIO
-from itertools import cycle, izip
+ skip_before_postgres, slow, StringIO)
+from itertools import cycle
from subprocess import Popen, PIPE
import psycopg2
diff --git a/tests/test_cursor.py b/tests/test_cursor.py
index 840819a..ec76918 100755
--- a/tests/test_cursor.py
+++ b/tests/test_cursor.py
@@ -29,7 +29,7 @@ import psycopg2.extensions
import unittest
from .testutils import (ConnectingTestCase, skip_before_postgres,
skip_if_no_getrefcount, slow, skip_if_no_superuser,
- skip_if_windows)
+ skip_if_windows, unicode)
import psycopg2.extras
diff --git a/tests/test_errcodes.py b/tests/test_errcodes.py
index 6775d83..5ce2cef 100755
--- a/tests/test_errcodes.py
+++ b/tests/test_errcodes.py
@@ -23,7 +23,7 @@
# License for more details.
import unittest
-from .testutils import ConnectingTestCase, slow
+from .testutils import ConnectingTestCase, slow, reload
try:
reload
@@ -52,7 +52,7 @@ class ErrocodeTests(ConnectingTestCase):
except Exception as e:
errs.append(e)
- for __ in xrange(MAX_CYCLES):
+ for __ in range(MAX_CYCLES):
reload(errorcodes)
(t1, t2) = (Thread(target=f), Thread(target=f))
(t1.start(), t2.start())
diff --git a/tests/test_extras_dictcursor.py b/tests/test_extras_dictcursor.py
index 5a726ec..75c2277 100755
--- a/tests/test_extras_dictcursor.py
+++ b/tests/test_extras_dictcursor.py
@@ -390,7 +390,7 @@ class NamedTupleCursorTest(ConnectingTestCase):
recs.extend(curs.fetchmany(5))
recs.append(curs.fetchone())
recs.extend(curs.fetchall())
- self.assertEqual(range(10), [t.i for t in recs])
+ self.assertEqual(list(range(10)), [t.i for t in recs])
def test_named_fetchone(self):
curs = self.conn.cursor('tmp')
diff --git a/tests/test_module.py b/tests/test_module.py
index e1c065d..ddd6b02 100755
--- a/tests/test_module.py
+++ b/tests/test_module.py
@@ -28,7 +28,7 @@ from subprocess import Popen
import unittest
from .testutils import (skip_before_postgres,
- ConnectingTestCase, skip_copy_if_green, slow)
+ ConnectingTestCase, skip_copy_if_green, slow, StringIO)
import psycopg2
@@ -217,7 +217,6 @@ class ExceptionsTestCase(ConnectingTestCase):
@skip_copy_if_green
def test_diagnostics_copy(self):
- from StringIO import StringIO
f = StringIO()
cur = self.conn.cursor()
try:
diff --git a/tests/test_quote.py b/tests/test_quote.py
index a79bb56..fad6cee 100755
--- a/tests/test_quote.py
+++ b/tests/test_quote.py
@@ -25,7 +25,7 @@
import sys
from . import testutils
import unittest
-from .testutils import ConnectingTestCase
+from .testutils import ConnectingTestCase, unichr
import psycopg2
import psycopg2.extensions
diff --git a/tests/test_sql.py b/tests/test_sql.py
index 6cb978f..1c20997 100755
--- a/tests/test_sql.py
+++ b/tests/test_sql.py
@@ -23,10 +23,10 @@
# License for more details.
import datetime as dt
-from cStringIO import StringIO
import unittest
from .testutils import (ConnectingTestCase,
- skip_before_postgres, skip_before_python, skip_copy_if_green)
+ skip_before_postgres, skip_before_python, skip_copy_if_green,
+ unicode, StringIO)
import psycopg2
from psycopg2 import sql
diff --git a/tests/test_types_basic.py b/tests/test_types_basic.py
index 6e34a47..a93265d 100755
--- a/tests/test_types_basic.py
+++ b/tests/test_types_basic.py
@@ -28,7 +28,7 @@ import sys
from functools import wraps
from . import testutils
import unittest
-from .testutils import ConnectingTestCase, decorate_all_tests
+from .testutils import ConnectingTestCase, decorate_all_tests, long
import psycopg2
@@ -54,8 +54,8 @@ class TypesBasicTests(ConnectingTestCase):
def testNumber(self):
s = self.execute("SELECT %s AS foo", (1971,))
self.failUnless(s == 1971, "wrong integer quoting: " + str(s))
- s = self.execute("SELECT %s AS foo", (1971L,))
- self.failUnless(s == 1971L, "wrong integer quoting: " + str(s))
+ s = self.execute("SELECT %s AS foo", (long(1971),))
+ self.failUnless(s == long(1971), "wrong integer quoting: " + str(s))
def testBoolean(self):
x = self.execute("SELECT %s as foo", (False,))
diff --git a/tests/test_types_extras.py b/tests/test_types_extras.py
index abe0610..5cb1353 100755
--- a/tests/test_types_extras.py
+++ b/tests/test_types_extras.py
@@ -181,7 +181,7 @@ class HstoreTestCase(ConnectingTestCase):
kk = m.group(1).split(b", ")
vv = m.group(2).split(b", ")
- ii = zip(kk, vv)
+ ii = list(zip(kk, vv))
ii.sort()
self.assertEqual(len(ii), len(o))
@@ -306,7 +306,7 @@ class HstoreTestCase(ConnectingTestCase):
ok({})
ok({'a': 'b', 'c': None})
- ab = map(chr, range(32, 128))
+ ab = list(map(chr, range(32, 128)))
ok(dict(zip(ab, ab)))
ok({''.join(ab): ''.join(ab)})
@@ -314,7 +314,7 @@ class HstoreTestCase(ConnectingTestCase):
if sys.version_info[0] < 3:
ab = map(chr, range(32, 127) + range(160, 255))
else:
- ab = bytes(range(32, 127) + range(160, 255)).decode('latin1')
+ ab = bytes(list(range(32, 127)) + list(range(160, 255))).decode('latin1')
ok({''.join(ab): ''.join(ab)})
ok(dict(zip(ab, ab)))
@@ -371,7 +371,7 @@ class HstoreTestCase(ConnectingTestCase):
ds = [{}, {'a': 'b', 'c': None}]
- ab = map(chr, range(32, 128))
+ ab = list(map(chr, range(32, 128)))
ds.append(dict(zip(ab, ab)))
ds.append({''.join(ab): ''.join(ab)})
@@ -379,7 +379,7 @@ class HstoreTestCase(ConnectingTestCase):
if sys.version_info[0] < 3:
ab = map(chr, range(32, 127) + range(160, 255))
else:
- ab = bytes(range(32, 127) + range(160, 255)).decode('latin1')
+ ab = bytes(list(range(32, 127)) + list(range(160, 255))).decode('latin1')
ds.append({''.join(ab): ''.join(ab)})
ds.append(dict(zip(ab, ab)))
@@ -514,7 +514,7 @@ class AdaptTypeTestCase(ConnectingTestCase):
'@,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,[,"\\\\",],'
'^,_,`,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,{,|,},'
'~,\x7f)',
- map(chr, range(1, 128)))
+ list(map(chr, range(1, 128))))
ok('(,"\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !'
'""#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]'
@@ -1641,8 +1641,8 @@ class RangeCasterTestCase(ConnectingTestCase):
bounds = ['[)', '(]', '()', '[]']
ranges = [TextRange(low, up, bounds[i % 4])
for i, (low, up) in enumerate(zip(
- [None] + map(chr, range(1, 128)),
- map(chr, range(1, 128)) + [None],
+ [None] + list(map(chr, range(1, 128))),
+ list(map(chr, range(1, 128))) + [None],
))]
ranges.append(TextRange())
ranges.append(TextRange(empty=True))
diff --git a/tests/testutils.py b/tests/testutils.py
index e1744c8..d70e091 100644
--- a/tests/testutils.py
+++ b/tests/testutils.py
@@ -31,6 +31,23 @@ import unittest
from functools import wraps
from .testconfig import dsn, repl_dsn
+# Python 2/3 compatibility
+
+if sys.version_info[0] == 2:
+ # Python 2
+ from StringIO import StringIO
+ long = long
+ reload = reload
+ unichr = unichr
+ unicode = unicode
+else:
+ # Python 3
+ from io import StringIO
+ from importlib import reload
+ long = int
+ unichr = chr
+ unicode = str
+
# Silence warnings caused by the stubbornness of the Python unittest
# maintainers