mirror of
				https://github.com/psycopg/psycopg2.git
				synced 2025-10-30 23:37:29 +03:00 
			
		
		
		
	Test suite converted into a proper package.
Dropped cyclic import from modules to tests: they were only working because a second copy of the package was found in the project dir. Use relative import so that 2to3 can do a good conversion.
This commit is contained in:
		
							parent
							
								
									f697410ab4
								
							
						
					
					
						commit
						ade1b2cc7b
					
				|  | @ -1,37 +1,9 @@ | ||||||
| #!/usr/bin/env python | #!/usr/bin/env python | ||||||
| 
 | 
 | ||||||
| import os |  | ||||||
| import sys | import sys | ||||||
|  | from testconfig import dsn | ||||||
| from testutils import unittest | from testutils import unittest | ||||||
| 
 | 
 | ||||||
| dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test') |  | ||||||
| dbhost = os.environ.get('PSYCOPG2_TESTDB_HOST', None) |  | ||||||
| dbport = os.environ.get('PSYCOPG2_TESTDB_PORT', None) |  | ||||||
| dbuser = os.environ.get('PSYCOPG2_TESTDB_USER', None) |  | ||||||
| 
 |  | ||||||
| # Check if we want to test psycopg's green path. |  | ||||||
| green = os.environ.get('PSYCOPG2_TEST_GREEN', None) |  | ||||||
| if green: |  | ||||||
|     if green == '1': |  | ||||||
|         from psycopg2.extras import wait_select as wait_callback |  | ||||||
|     elif green == 'eventlet': |  | ||||||
|         from eventlet.support.psycopg2_patcher import eventlet_wait_callback \ |  | ||||||
|             as wait_callback |  | ||||||
|     else: |  | ||||||
|         raise ValueError("please set 'PSYCOPG2_TEST_GREEN' to a valid value") |  | ||||||
| 
 |  | ||||||
|     import psycopg2.extensions |  | ||||||
|     psycopg2.extensions.set_wait_callback(wait_callback) |  | ||||||
| 
 |  | ||||||
| # Construct a DSN to connect to the test database: |  | ||||||
| dsn = 'dbname=%s' % dbname |  | ||||||
| if dbhost is not None: |  | ||||||
|     dsn += ' host=%s' % dbhost |  | ||||||
| if dbport is not None: |  | ||||||
|     dsn += ' port=%s' % dbport |  | ||||||
| if dbuser is not None: |  | ||||||
|     dsn += ' user=%s' % dbuser |  | ||||||
| 
 |  | ||||||
| # If connection to test db fails, bail out early. | # If connection to test db fails, bail out early. | ||||||
| import psycopg2 | import psycopg2 | ||||||
| try: | try: | ||||||
|  | @ -81,4 +53,4 @@ def test_suite(): | ||||||
|     return suite |     return suite | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     unittest.main(defaultTest='test_suite') |     unittest.main(defaultTest=test_suite) | ||||||
|  |  | ||||||
|  | @ -6,18 +6,14 @@ import time | ||||||
| import unittest | import unittest | ||||||
| import gc | import gc | ||||||
| 
 | 
 | ||||||
| import sys | from testconfig import dsn | ||||||
| if sys.version_info < (3,): |  | ||||||
|     import tests |  | ||||||
| else: |  | ||||||
|     import py3tests as tests |  | ||||||
| 
 | 
 | ||||||
| class StolenReferenceTestCase(unittest.TestCase): | class StolenReferenceTestCase(unittest.TestCase): | ||||||
|     def test_stolen_reference_bug(self): |     def test_stolen_reference_bug(self): | ||||||
|         def fish(val, cur): |         def fish(val, cur): | ||||||
|             gc.collect() |             gc.collect() | ||||||
|             return 42 |             return 42 | ||||||
|         conn = psycopg2.connect(tests.dsn) |         conn = psycopg2.connect(dsn) | ||||||
|         UUID = psycopg2.extensions.new_type((2950,), "UUID", fish) |         UUID = psycopg2.extensions.new_type((2950,), "UUID", fish) | ||||||
|         psycopg2.extensions.register_type(UUID, conn) |         psycopg2.extensions.register_type(UUID, conn) | ||||||
|         curs = conn.cursor() |         curs = conn.cursor() | ||||||
|  |  | ||||||
|  | @ -17,15 +17,14 @@ | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extras | import psycopg2.extras | ||||||
| from testutils import unittest | from testutils import unittest | ||||||
| 
 | from testconfig import dsn | ||||||
| import tests |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ExtrasDictCursorTests(unittest.TestCase): | class ExtrasDictCursorTests(unittest.TestCase): | ||||||
|     """Test if DictCursor extension class works.""" |     """Test if DictCursor extension class works.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         curs = self.conn.cursor() |         curs = self.conn.cursor() | ||||||
|         curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)") |         curs.execute("CREATE TEMPORARY TABLE ExtrasDictCursorTests (foo text)") | ||||||
|         curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')") |         curs.execute("INSERT INTO ExtrasDictCursorTests VALUES ('bar')") | ||||||
|  | @ -135,7 +134,7 @@ class NamedTupleCursorTest(unittest.TestCase): | ||||||
|             self.conn = None |             self.conn = None | ||||||
|             return |             return | ||||||
| 
 | 
 | ||||||
|         self.conn = psycopg2.connect(tests.dsn, |         self.conn = psycopg2.connect(dsn, | ||||||
|             connection_factory=NamedTupleConnection) |             connection_factory=NamedTupleConnection) | ||||||
|         curs = self.conn.cursor() |         curs = self.conn.cursor() | ||||||
|         curs.execute("CREATE TEMPORARY TABLE nttest (i int, s text)") |         curs.execute("CREATE TEMPORARY TABLE nttest (i int, s text)") | ||||||
|  | @ -207,7 +206,7 @@ class NamedTupleCursorTest(unittest.TestCase): | ||||||
|             try: |             try: | ||||||
|                 if self.conn is not None: |                 if self.conn is not None: | ||||||
|                     self.conn.close() |                     self.conn.close() | ||||||
|                 self.conn = psycopg2.connect(tests.dsn, |                 self.conn = psycopg2.connect(dsn, | ||||||
|                     connection_factory=NamedTupleConnection) |                     connection_factory=NamedTupleConnection) | ||||||
|                 curs = self.conn.cursor() |                 curs = self.conn.cursor() | ||||||
|                 curs.execute("select 1") |                 curs.execute("select 1") | ||||||
|  |  | ||||||
|  | @ -8,12 +8,7 @@ import time | ||||||
| import select | import select | ||||||
| import StringIO | import StringIO | ||||||
| 
 | 
 | ||||||
| import sys | from testconfig import dsn | ||||||
| if sys.version_info < (3,): |  | ||||||
|     import tests |  | ||||||
| else: |  | ||||||
|     import py3tests as tests |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| class PollableStub(object): | class PollableStub(object): | ||||||
|     """A 'pollable' wrapper allowing analysis of the `poll()` calls.""" |     """A 'pollable' wrapper allowing analysis of the `poll()` calls.""" | ||||||
|  | @ -33,8 +28,8 @@ class PollableStub(object): | ||||||
| class AsyncTests(unittest.TestCase): | class AsyncTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.sync_conn = psycopg2.connect(tests.dsn) |         self.sync_conn = psycopg2.connect(dsn) | ||||||
|         self.conn = psycopg2.connect(tests.dsn, async=True) |         self.conn = psycopg2.connect(dsn, async=True) | ||||||
| 
 | 
 | ||||||
|         self.wait(self.conn) |         self.wait(self.conn) | ||||||
| 
 | 
 | ||||||
|  | @ -309,7 +304,7 @@ class AsyncTests(unittest.TestCase): | ||||||
|             def __init__(self, dsn, async=0): |             def __init__(self, dsn, async=0): | ||||||
|                 psycopg2.extensions.connection.__init__(self, dsn, async=async) |                 psycopg2.extensions.connection.__init__(self, dsn, async=async) | ||||||
| 
 | 
 | ||||||
|         conn = psycopg2.connect(tests.dsn, connection_factory=MyConn, async=True) |         conn = psycopg2.connect(dsn, connection_factory=MyConn, async=True) | ||||||
|         self.assert_(isinstance(conn, MyConn)) |         self.assert_(isinstance(conn, MyConn)) | ||||||
|         self.assert_(conn.async) |         self.assert_(conn.async) | ||||||
|         conn.close() |         conn.close() | ||||||
|  |  | ||||||
|  | @ -2,18 +2,18 @@ | ||||||
| 
 | 
 | ||||||
| import time | import time | ||||||
| import threading | import threading | ||||||
| from testutils import unittest, skip_if_no_pg_sleep |  | ||||||
| 
 | 
 | ||||||
| import tests |  | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| from psycopg2 import extras | from psycopg2 import extras | ||||||
| 
 | 
 | ||||||
|  | from testconfig import dsn | ||||||
|  | from testutils import unittest, skip_if_no_pg_sleep | ||||||
| 
 | 
 | ||||||
| class CancelTests(unittest.TestCase): | class CancelTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         cur = self.conn.cursor() |         cur = self.conn.cursor() | ||||||
|         cur.execute(''' |         cur.execute(''' | ||||||
|             CREATE TEMPORARY TABLE table1 ( |             CREATE TEMPORARY TABLE table1 ( | ||||||
|  | @ -65,7 +65,7 @@ class CancelTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     @skip_if_no_pg_sleep('conn') |     @skip_if_no_pg_sleep('conn') | ||||||
|     def test_async_cancel(self): |     def test_async_cancel(self): | ||||||
|         async_conn = psycopg2.connect(tests.dsn, async=True) |         async_conn = psycopg2.connect(dsn, async=True) | ||||||
|         self.assertRaises(psycopg2.OperationalError, async_conn.cancel) |         self.assertRaises(psycopg2.OperationalError, async_conn.cancel) | ||||||
|         extras.wait_select(async_conn) |         extras.wait_select(async_conn) | ||||||
|         cur = async_conn.cursor() |         cur = async_conn.cursor() | ||||||
|  | @ -79,7 +79,7 @@ class CancelTests(unittest.TestCase): | ||||||
|         self.assertEqual(cur.fetchall(), [(1, )]) |         self.assertEqual(cur.fetchall(), [(1, )]) | ||||||
| 
 | 
 | ||||||
|     def test_async_connection_cancel(self): |     def test_async_connection_cancel(self): | ||||||
|         async_conn = psycopg2.connect(tests.dsn, async=True) |         async_conn = psycopg2.connect(dsn, async=True) | ||||||
|         async_conn.close() |         async_conn.close() | ||||||
|         self.assertTrue(async_conn.closed) |         self.assertTrue(async_conn.closed) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -7,12 +7,12 @@ from operator import attrgetter | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import tests | from testconfig import dsn, dbname | ||||||
| 
 | 
 | ||||||
| class ConnectionTests(unittest.TestCase): | class ConnectionTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         if not self.conn.closed: |         if not self.conn.closed: | ||||||
|  | @ -95,7 +95,7 @@ class ConnectionTests(unittest.TestCase): | ||||||
|     @skip_if_no_pg_sleep('conn') |     @skip_if_no_pg_sleep('conn') | ||||||
|     def test_concurrent_execution(self): |     def test_concurrent_execution(self): | ||||||
|         def slave(): |         def slave(): | ||||||
|             cnn = psycopg2.connect(tests.dsn) |             cnn = psycopg2.connect(dsn) | ||||||
|             cur = cnn.cursor() |             cur = cnn.cursor() | ||||||
|             cur.execute("select pg_sleep(2)") |             cur.execute("select pg_sleep(2)") | ||||||
|             cur.close() |             cur.close() | ||||||
|  | @ -141,7 +141,7 @@ class IsolationLevelsTestCase(unittest.TestCase): | ||||||
|                 conn.close() |                 conn.close() | ||||||
| 
 | 
 | ||||||
|     def connect(self): |     def connect(self): | ||||||
|         conn = psycopg2.connect(tests.dsn) |         conn = psycopg2.connect(dsn) | ||||||
|         self._conns.append(conn) |         self._conns.append(conn) | ||||||
|         return conn |         return conn | ||||||
| 
 | 
 | ||||||
|  | @ -333,7 +333,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         try: |         try: | ||||||
|             cur.execute( |             cur.execute( | ||||||
|                 "select gid from pg_prepared_xacts where database = %s", |                 "select gid from pg_prepared_xacts where database = %s", | ||||||
|                 (tests.dbname,)) |                 (dbname,)) | ||||||
|         except psycopg2.ProgrammingError: |         except psycopg2.ProgrammingError: | ||||||
|             cnn.rollback() |             cnn.rollback() | ||||||
|             cnn.close() |             cnn.close() | ||||||
|  | @ -362,7 +362,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         cur.execute(""" |         cur.execute(""" | ||||||
|             select count(*) from pg_prepared_xacts |             select count(*) from pg_prepared_xacts | ||||||
|             where database = %s;""", |             where database = %s;""", | ||||||
|             (tests.dbname,)) |             (dbname,)) | ||||||
|         rv = cur.fetchone()[0] |         rv = cur.fetchone()[0] | ||||||
|         cnn.close() |         cnn.close() | ||||||
|         return rv |         return rv | ||||||
|  | @ -377,7 +377,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         return rv |         return rv | ||||||
| 
 | 
 | ||||||
|     def connect(self): |     def connect(self): | ||||||
|         conn = psycopg2.connect(tests.dsn) |         conn = psycopg2.connect(dsn) | ||||||
|         self._conns.append(conn) |         self._conns.append(conn) | ||||||
|         return conn |         return conn | ||||||
| 
 | 
 | ||||||
|  | @ -540,13 +540,13 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|             select gid, prepared, owner, database |             select gid, prepared, owner, database | ||||||
|             from pg_prepared_xacts |             from pg_prepared_xacts | ||||||
|             where database = %s;""", |             where database = %s;""", | ||||||
|             (tests.dbname,)) |             (dbname,)) | ||||||
|         okvals = cur.fetchall() |         okvals = cur.fetchall() | ||||||
|         okvals.sort() |         okvals.sort() | ||||||
| 
 | 
 | ||||||
|         cnn = self.connect() |         cnn = self.connect() | ||||||
|         xids = cnn.tpc_recover() |         xids = cnn.tpc_recover() | ||||||
|         xids = [ xid for xid in xids if xid.database == tests.dbname ] |         xids = [ xid for xid in xids if xid.database == dbname ] | ||||||
|         xids.sort(key=attrgetter('gtrid')) |         xids.sort(key=attrgetter('gtrid')) | ||||||
| 
 | 
 | ||||||
|         # check the values returned |         # check the values returned | ||||||
|  | @ -566,7 +566,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         cnn = self.connect() |         cnn = self.connect() | ||||||
|         cur = cnn.cursor() |         cur = cnn.cursor() | ||||||
|         cur.execute("select gid from pg_prepared_xacts where database = %s;", |         cur.execute("select gid from pg_prepared_xacts where database = %s;", | ||||||
|             (tests.dbname,)) |             (dbname,)) | ||||||
|         self.assertEqual('42_Z3RyaWQ=_YnF1YWw=', cur.fetchone()[0]) |         self.assertEqual('42_Z3RyaWQ=_YnF1YWw=', cur.fetchone()[0]) | ||||||
| 
 | 
 | ||||||
|     def test_xid_roundtrip(self): |     def test_xid_roundtrip(self): | ||||||
|  | @ -583,7 +583,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|             cnn = self.connect() |             cnn = self.connect() | ||||||
|             xids = [ xid for xid in cnn.tpc_recover() |             xids = [ xid for xid in cnn.tpc_recover() | ||||||
|                 if xid.database == tests.dbname ] |                 if xid.database == dbname ] | ||||||
|             self.assertEqual(1, len(xids)) |             self.assertEqual(1, len(xids)) | ||||||
|             xid = xids[0] |             xid = xids[0] | ||||||
|             self.assertEqual(xid.format_id, fid) |             self.assertEqual(xid.format_id, fid) | ||||||
|  | @ -605,7 +605,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|             cnn = self.connect() |             cnn = self.connect() | ||||||
|             xids = [ xid for xid in cnn.tpc_recover() |             xids = [ xid for xid in cnn.tpc_recover() | ||||||
|                 if xid.database == tests.dbname ] |                 if xid.database == dbname ] | ||||||
|             self.assertEqual(1, len(xids)) |             self.assertEqual(1, len(xids)) | ||||||
|             xid = xids[0] |             xid = xids[0] | ||||||
|             self.assertEqual(xid.format_id, None) |             self.assertEqual(xid.format_id, None) | ||||||
|  | @ -651,7 +651,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         cnn.tpc_prepare() |         cnn.tpc_prepare() | ||||||
|         cnn.reset() |         cnn.reset() | ||||||
|         xid = [ xid for xid in cnn.tpc_recover() |         xid = [ xid for xid in cnn.tpc_recover() | ||||||
|             if xid.database == tests.dbname ][0] |             if xid.database == dbname ][0] | ||||||
|         self.assertEqual(10, xid.format_id) |         self.assertEqual(10, xid.format_id) | ||||||
|         self.assertEqual('uni', xid.gtrid) |         self.assertEqual('uni', xid.gtrid) | ||||||
|         self.assertEqual('code', xid.bqual) |         self.assertEqual('code', xid.bqual) | ||||||
|  | @ -667,7 +667,7 @@ class ConnectionTwoPhaseTests(unittest.TestCase): | ||||||
|         cnn.reset() |         cnn.reset() | ||||||
| 
 | 
 | ||||||
|         xid = [ xid for xid in cnn.tpc_recover() |         xid = [ xid for xid in cnn.tpc_recover() | ||||||
|             if xid.database == tests.dbname ][0] |             if xid.database == dbname ][0] | ||||||
|         self.assertEqual(None, xid.format_id) |         self.assertEqual(None, xid.format_id) | ||||||
|         self.assertEqual('transaction-id', xid.gtrid) |         self.assertEqual('transaction-id', xid.gtrid) | ||||||
|         self.assertEqual(None, xid.bqual) |         self.assertEqual(None, xid.bqual) | ||||||
|  |  | ||||||
|  | @ -7,11 +7,11 @@ from itertools import cycle, izip | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import tests | from testconfig import dsn, green | ||||||
| 
 | 
 | ||||||
| def skip_if_green(f): | def skip_if_green(f): | ||||||
|     def skip_if_green_(self): |     def skip_if_green_(self): | ||||||
|         if tests.green: |         if green: | ||||||
|             return self.skipTest("copy in async mode currently not supported") |             return self.skipTest("copy in async mode currently not supported") | ||||||
|         else: |         else: | ||||||
|             return f(self) |             return f(self) | ||||||
|  | @ -42,7 +42,7 @@ class MinimalWrite(object): | ||||||
| class CopyTests(unittest.TestCase): | class CopyTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         curs = self.conn.cursor() |         curs = self.conn.cursor() | ||||||
|         curs.execute(''' |         curs.execute(''' | ||||||
|             CREATE TEMPORARY TABLE tcopy ( |             CREATE TEMPORARY TABLE tcopy ( | ||||||
|  |  | ||||||
|  | @ -3,12 +3,12 @@ | ||||||
| import unittest | import unittest | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| class CursorTests(unittest.TestCase): | class CursorTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  |  | ||||||
|  | @ -2,9 +2,9 @@ | ||||||
| 
 | 
 | ||||||
| import math | import math | ||||||
| import unittest | import unittest | ||||||
| import tests |  | ||||||
| import psycopg2 | import psycopg2 | ||||||
| from psycopg2.tz import FixedOffsetTimezone | from psycopg2.tz import FixedOffsetTimezone | ||||||
|  | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| class CommonDatetimeTestsMixin: | class CommonDatetimeTestsMixin: | ||||||
| 
 | 
 | ||||||
|  | @ -75,7 +75,7 @@ class DatetimeTests(unittest.TestCase, CommonDatetimeTestsMixin): | ||||||
|     """Tests for the datetime based date handling in psycopg2.""" |     """Tests for the datetime based date handling in psycopg2.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         self.curs = self.conn.cursor() |         self.curs = self.conn.cursor() | ||||||
|         self.DATE = psycopg2._psycopg.PYDATE |         self.DATE = psycopg2._psycopg.PYDATE | ||||||
|         self.TIME = psycopg2._psycopg.PYTIME |         self.TIME = psycopg2._psycopg.PYTIME | ||||||
|  | @ -293,7 +293,7 @@ class mxDateTimeTests(unittest.TestCase, CommonDatetimeTestsMixin): | ||||||
|     """Tests for the mx.DateTime based date handling in psycopg2.""" |     """Tests for the mx.DateTime based date handling in psycopg2.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         self.curs = self.conn.cursor() |         self.curs = self.conn.cursor() | ||||||
|         self.DATE = psycopg2._psycopg.MXDATE |         self.DATE = psycopg2._psycopg.MXDATE | ||||||
|         self.TIME = psycopg2._psycopg.MXTIME |         self.TIME = psycopg2._psycopg.MXTIME | ||||||
|  |  | ||||||
|  | @ -4,7 +4,7 @@ import unittest | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import psycopg2.extras | import psycopg2.extras | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| class ConnectionStub(object): | class ConnectionStub(object): | ||||||
|     """A `connection` wrapper allowing analysis of the `poll()` calls.""" |     """A `connection` wrapper allowing analysis of the `poll()` calls.""" | ||||||
|  | @ -24,7 +24,7 @@ class GreenTests(unittest.TestCase): | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self._cb = psycopg2.extensions.get_wait_callback() |         self._cb = psycopg2.extensions.get_wait_callback() | ||||||
|         psycopg2.extensions.set_wait_callback(psycopg2.extras.wait_select) |         psycopg2.extensions.set_wait_callback(psycopg2.extras.wait_select) | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  |  | ||||||
|  | @ -2,11 +2,11 @@ | ||||||
| import os | import os | ||||||
| import shutil | import shutil | ||||||
| import tempfile | import tempfile | ||||||
| from testutils import unittest, decorate_all_tests |  | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import tests | from testconfig import dsn, green | ||||||
|  | from testutils import unittest, decorate_all_tests | ||||||
| 
 | 
 | ||||||
| def skip_if_no_lo(f): | def skip_if_no_lo(f): | ||||||
|     def skip_if_no_lo_(self): |     def skip_if_no_lo_(self): | ||||||
|  | @ -19,7 +19,7 @@ def skip_if_no_lo(f): | ||||||
| 
 | 
 | ||||||
| def skip_if_green(f): | def skip_if_green(f): | ||||||
|     def skip_if_green_(self): |     def skip_if_green_(self): | ||||||
|         if tests.green: |         if green: | ||||||
|             return self.skipTest("libpq doesn't support LO in async mode") |             return self.skipTest("libpq doesn't support LO in async mode") | ||||||
|         else: |         else: | ||||||
|             return f(self) |             return f(self) | ||||||
|  | @ -30,7 +30,7 @@ def skip_if_green(f): | ||||||
| class LargeObjectMixin(object): | class LargeObjectMixin(object): | ||||||
|     # doesn't derive from TestCase to avoid repeating tests twice. |     # doesn't derive from TestCase to avoid repeating tests twice. | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         self.lo_oid = None |         self.lo_oid = None | ||||||
|         self.tmpdir = None |         self.tmpdir = None | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,23 +3,19 @@ from testutils import unittest | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| from psycopg2 import extensions | from psycopg2 import extensions | ||||||
|  | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
|  | import sys | ||||||
| import time | import time | ||||||
| import select | import select | ||||||
| import signal | import signal | ||||||
| from subprocess import Popen, PIPE | from subprocess import Popen, PIPE | ||||||
| 
 | 
 | ||||||
| import sys |  | ||||||
| if sys.version_info < (3,): |  | ||||||
|     import tests |  | ||||||
| else: |  | ||||||
|     import py3tests as tests |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| class NotifiesTests(unittest.TestCase): | class NotifiesTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  | @ -54,7 +50,7 @@ curs.execute("NOTIFY " %(name)r %(payload)r) | ||||||
| curs.close() | curs.close() | ||||||
| conn.close() | conn.close() | ||||||
| """ | """ | ||||||
|             % { 'dsn': tests.dsn, 'sec': sec, 'name': name, 'payload': payload}) |             % { 'dsn': dsn, 'sec': sec, 'name': name, 'payload': payload}) | ||||||
| 
 | 
 | ||||||
|         return Popen([sys.executable, '-c', script], stdout=PIPE) |         return Popen([sys.executable, '-c', script], stdout=PIPE) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,12 +5,12 @@ from test_connection import skip_if_tpc_disabled | ||||||
| from testutils import unittest, decorate_all_tests | from testutils import unittest, decorate_all_tests | ||||||
| import psycopg2 | import psycopg2 | ||||||
| 
 | 
 | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| class Psycopg2Tests(dbapi20.DatabaseAPI20Test): | class Psycopg2Tests(dbapi20.DatabaseAPI20Test): | ||||||
|     driver = psycopg2 |     driver = psycopg2 | ||||||
|     connect_args = () |     connect_args = () | ||||||
|     connect_kw_args = {'dsn': tests.dsn} |     connect_kw_args = {'dsn': dsn} | ||||||
| 
 | 
 | ||||||
|     lower_func = 'lower' # For stored procedure test |     lower_func = 'lower' # For stored procedure test | ||||||
| 
 | 
 | ||||||
|  | @ -27,7 +27,7 @@ class Psycopg2TPCTests(dbapi20_tpc.TwoPhaseCommitTests, unittest.TestCase): | ||||||
|     driver = psycopg2 |     driver = psycopg2 | ||||||
| 
 | 
 | ||||||
|     def connect(self): |     def connect(self): | ||||||
|         return psycopg2.connect(dsn=tests.dsn) |         return psycopg2.connect(dsn=dsn) | ||||||
| 
 | 
 | ||||||
| decorate_all_tests(Psycopg2TPCTests, skip_if_tpc_disabled) | decorate_all_tests(Psycopg2TPCTests, skip_if_tpc_disabled) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,7 +3,7 @@ from testutils import unittest | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extensions | import psycopg2.extensions | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| class QuotingTestCase(unittest.TestCase): | class QuotingTestCase(unittest.TestCase): | ||||||
|     r"""Checks the correct quoting of strings and binary objects. |     r"""Checks the correct quoting of strings and binary objects. | ||||||
|  | @ -24,7 +24,7 @@ class QuotingTestCase(unittest.TestCase): | ||||||
|     http://www.postgresql.org/docs/8.1/static/runtime-config-compatible.html |     http://www.postgresql.org/docs/8.1/static/runtime-config-compatible.html | ||||||
|     """ |     """ | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  |  | ||||||
|  | @ -5,13 +5,12 @@ from testutils import unittest, skip_if_no_pg_sleep | ||||||
| import psycopg2 | import psycopg2 | ||||||
| from psycopg2.extensions import ( | from psycopg2.extensions import ( | ||||||
|     ISOLATION_LEVEL_SERIALIZABLE, STATUS_BEGIN, STATUS_READY) |     ISOLATION_LEVEL_SERIALIZABLE, STATUS_BEGIN, STATUS_READY) | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| class TransactionTests(unittest.TestCase): | class TransactionTests(unittest.TestCase): | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) |         self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) | ||||||
|         curs = self.conn.cursor() |         curs = self.conn.cursor() | ||||||
|         curs.execute(''' |         curs.execute(''' | ||||||
|  | @ -75,7 +74,7 @@ class DeadlockSerializationTests(unittest.TestCase): | ||||||
|     """Test deadlock and serialization failure errors.""" |     """Test deadlock and serialization failure errors.""" | ||||||
| 
 | 
 | ||||||
|     def connect(self): |     def connect(self): | ||||||
|         conn = psycopg2.connect(tests.dsn) |         conn = psycopg2.connect(dsn) | ||||||
|         conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) |         conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) | ||||||
|         return conn |         return conn | ||||||
| 
 | 
 | ||||||
|  | @ -208,7 +207,7 @@ class QueryCancellationTests(unittest.TestCase): | ||||||
|     """Tests for query cancellation.""" |     """Tests for query cancellation.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
|         self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) |         self.conn.set_isolation_level(ISOLATION_LEVEL_SERIALIZABLE) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|  |  | ||||||
							
								
								
									
										33
									
								
								tests/testconfig.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								tests/testconfig.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | ||||||
|  | # Configure the test suite from the env variables. | ||||||
|  | 
 | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | dbname = os.environ.get('PSYCOPG2_TESTDB', 'psycopg2_test') | ||||||
|  | dbhost = os.environ.get('PSYCOPG2_TESTDB_HOST', None) | ||||||
|  | dbport = os.environ.get('PSYCOPG2_TESTDB_PORT', None) | ||||||
|  | dbuser = os.environ.get('PSYCOPG2_TESTDB_USER', None) | ||||||
|  | 
 | ||||||
|  | # Check if we want to test psycopg's green path. | ||||||
|  | green = os.environ.get('PSYCOPG2_TEST_GREEN', None) | ||||||
|  | if green: | ||||||
|  |     if green == '1': | ||||||
|  |         from psycopg2.extras import wait_select as wait_callback | ||||||
|  |     elif green == 'eventlet': | ||||||
|  |         from eventlet.support.psycopg2_patcher import eventlet_wait_callback \ | ||||||
|  |             as wait_callback | ||||||
|  |     else: | ||||||
|  |         raise ValueError("please set 'PSYCOPG2_TEST_GREEN' to a valid value") | ||||||
|  | 
 | ||||||
|  |     import psycopg2.extensions | ||||||
|  |     psycopg2.extensions.set_wait_callback(wait_callback) | ||||||
|  | 
 | ||||||
|  | # Construct a DSN to connect to the test database: | ||||||
|  | dsn = 'dbname=%s' % dbname | ||||||
|  | if dbhost is not None: | ||||||
|  |     dsn += ' host=%s' % dbhost | ||||||
|  | if dbport is not None: | ||||||
|  |     dsn += ' port=%s' % dbport | ||||||
|  | if dbuser is not None: | ||||||
|  |     dsn += ' user=%s' % dbuser | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | @ -30,14 +30,14 @@ import sys | ||||||
| from testutils import unittest | from testutils import unittest | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class TypesBasicTests(unittest.TestCase): | class TypesBasicTests(unittest.TestCase): | ||||||
|     """Test that all type conversions are working.""" |     """Test that all type conversions are working.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  |  | ||||||
|  | @ -24,7 +24,7 @@ from testutils import unittest | ||||||
| 
 | 
 | ||||||
| import psycopg2 | import psycopg2 | ||||||
| import psycopg2.extras | import psycopg2.extras | ||||||
| import tests | from testconfig import dsn | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def skip_if_no_uuid(f): | def skip_if_no_uuid(f): | ||||||
|  | @ -58,7 +58,7 @@ class TypesExtrasTests(unittest.TestCase): | ||||||
|     """Test that all type conversions are working.""" |     """Test that all type conversions are working.""" | ||||||
| 
 | 
 | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  | @ -145,7 +145,7 @@ def skip_if_no_hstore(f): | ||||||
| 
 | 
 | ||||||
| class HstoreTestCase(unittest.TestCase): | class HstoreTestCase(unittest.TestCase): | ||||||
|     def setUp(self): |     def setUp(self): | ||||||
|         self.conn = psycopg2.connect(tests.dsn) |         self.conn = psycopg2.connect(dsn) | ||||||
| 
 | 
 | ||||||
|     def tearDown(self): |     def tearDown(self): | ||||||
|         self.conn.close() |         self.conn.close() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user