mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
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.
This commit is contained in:
parent
c86e682153
commit
389f6c08d9
|
@ -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"
|
||||
|
|
|
@ -12,6 +12,7 @@ python:
|
|||
|
||||
install:
|
||||
- python setup.py install
|
||||
- rm -rf psycopg2.egg-info
|
||||
- sudo scripts/travis_prepare.sh
|
||||
|
||||
script:
|
||||
|
|
5
Makefile
5
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)"
|
||||
|
|
3
NEWS
3
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
4
setup.py
4
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, },
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,))
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user