Re: Setting connection parameters in tests
Jorgen Austvik - Sun Norway <Jorgen.Austvik-UdXhSnd/[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
James Henstridge wrote:
> Hi Jorgen,
>
> I've made some changes to the test suite since 2.0.6 that make it
> easier to run the entire test suite in one go. It uses the
> PSYCOPG2_TESTDB environment variable to pick which database to use for
> the tests, defaulting to "psycopg2_test".
The new tests and way to start them looks very good!
> Is this enough for your uses, or do you need the other environment
> variables? If so, could you produce a patch against the current
> Subversion sources? You can make a checkout with:
Patch attached.
[ja155679@khepri02:psycopg2] svn diff | diffstat
__init__.py | 3 +++
extras_dictcursor.py | 2 +-
test_connection.py | 2 +-
test_dates.py | 2 +-
test_psycopg2_dbapi20.py | 3 ++-
test_quote.py | 2 +-
test_transaction.py | 6 +++---
types_basic.py | 2 +-
8 files changed, 13 insertions(+), 9 deletions(-)
> There has been a fair amount of work since 2.0.6, so patches against
> subversion head are more useful than those against the last tarball at
> this point.
Thanks for the great work!
Applied patch is tested with one error (which I don't think is related):
[ja155679@khepri02:psycopg2] PSYCOPG2_TESTDB=postgres python runtests.py
...........................................................E...............
======================================================================
ERROR: test_unicode (tests.test_quote.QuotingTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/ja155679/devel/psycopg2/tests/test_quote.py", line 67, in
test_unicode
curs.execute("SELECT %s::text;", (data,))
DataError: character 0xe282ac of encoding "UTF8" has no equivalent in
"LATIN1"
----------------------------------------------------------------------
Ran 75 tests in 1.572s
FAILED (errors=1)
-J
--
Jørgen Austvik, Software Engineering - QA
Sun Microsystems Database Technology Group
Sun Microsystems AS
Haakon VII gt. 7b
N-7485 Trondheim, Norway
Phone +47 73 84 21 10
Fax +47 73 84 21 01
Mobile +47 90 19 78 86
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
psycopg2_test_parameters.patch
(text/x-patch, 5.1 KB)
Index: tests/test_quote.py
===================================================================
--- tests/test_quote.py (revision 949)
+++ tests/test_quote.py (working copy)
@@ -23,7 +23,7 @@
http://www.postgresql.org/docs/8.1/static/runtime-config-compatible.html
"""
def setUp(self):
- self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
def tearDown(self):
self.conn.close()
Index: tests/test_connection.py
===================================================================
--- tests/test_connection.py (revision 949)
+++ tests/test_connection.py (working copy)
@@ -8,7 +8,7 @@
class ConnectionTests(unittest.TestCase):
def connect(self):
- return psycopg2.connect("dbname=%s" % tests.dbname)
+ return psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
def test_closed_attribute(self):
conn = self.connect()
Index: tests/__init__.py
===================================================================
--- tests/__init__.py (revision 949)
+++ tests/__init__.py (working copy)
@@ -3,6 +3,9 @@
import unittest
dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test')
+dbhost = os.environ.get('PSYCOPG2_TESTDB_HOST', 'localhost')
+dbport = os.environ.get('PSYCOPG2_TESTDB_PORT', 5432)
+dbuser = os.environ.get('PSYCOPG2_TESTDB_USER', 'postgres')
import bugX000
import extras_dictcursor
Index: tests/test_dates.py
===================================================================
--- tests/test_dates.py (revision 949)
+++ tests/test_dates.py (working copy)
@@ -9,7 +9,7 @@
class CommonDatetimeTestsMixin:
def execute(self, *args):
- conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
curs = conn.cursor()
curs.execute(*args)
return curs.fetchone()[0]
Index: tests/test_transaction.py
===================================================================
--- tests/test_transaction.py (revision 949)
+++ tests/test_transaction.py (working copy)
@@ -11,7 +11,7 @@
class TransactionTests(unittest.TestCase):
def setUp(self):
- self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
curs = self.conn.cursor()
curs.execute('''
@@ -75,7 +75,7 @@
"""Test deadlock and serialization failure errors."""
def connect(self):
- conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
return conn
@@ -208,7 +208,7 @@
"""Tests for query cancelation."""
def setUp(self):
- self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE)
def test_statement_timeout(self):
Index: tests/types_basic.py
===================================================================
--- tests/types_basic.py (revision 949)
+++ tests/types_basic.py (working copy)
@@ -28,7 +28,7 @@
"""Test presence of mandatory attributes and methods."""
def setUp(self):
- self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
def execute(self, *args):
curs = self.conn.cursor()
Index: tests/test_psycopg2_dbapi20.py
===================================================================
--- tests/test_psycopg2_dbapi20.py (revision 949)
+++ tests/test_psycopg2_dbapi20.py (working copy)
@@ -8,8 +8,9 @@
class Psycopg2TestCase(dbapi20.DatabaseAPI20Test):
driver = psycopg2
+ dsn = "dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser)
connect_args = ()
- connect_kw_args = {'dsn': 'dbname=%s' % tests.dbname}
+ connect_kw_args = {'dsn': dsn}
lower_func = 'lower' # For stored procedure test
Index: tests/extras_dictcursor.py
===================================================================
--- tests/extras_dictcursor.py (revision 949)
+++ tests/extras_dictcursor.py (working copy)
@@ -24,7 +24,7 @@
"""Test if DictCursor extension class works."""
def setUp(self):
- self.conn = psycopg2.connect("dbname=%s" % tests.dbname)
+ self.conn = psycopg2.connect("dbname=%s host=%s port=%s user=%s" %(tests.dbname, tests.dbhost, tests.dbport, tests.dbuser))
curs = self.conn.cursor()
curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)")
jorgen_austvik.vcf
(text/x-vcard, 411 B)
begin:vcard fn;quoted-printable:J=C3=B8rgen Austvik n;quoted-printable:Austvik;J=C3=B8rgen org:Sun Microsystems;Database Technology Group adr:;;Haakon VII gt. 7b;Trondheim;;NO-7485;Norway email;internet:[email protected] title:Senior Engineer tel;work:+47 73 84 21 10 tel;fax:+47 73 84 21 01 tel;cell:+47 901 97 886 x-mozilla-html:FALSE url:http://www.sun.com/ version:2.1 end:vcard