diff options
Diffstat (limited to 'test/engine')
| -rw-r--r-- | test/engine/test_bind.py | 6 | ||||
| -rw-r--r-- | test/engine/test_ddlemit.py | 2 | ||||
| -rw-r--r-- | test/engine/test_ddlevents.py | 2 | ||||
| -rw-r--r-- | test/engine/test_execute.py | 32 | ||||
| -rw-r--r-- | test/engine/test_parseconnect.py | 12 | ||||
| -rw-r--r-- | test/engine/test_pool.py | 30 | ||||
| -rw-r--r-- | test/engine/test_processors.py | 4 | ||||
| -rw-r--r-- | test/engine/test_reconnect.py | 24 | ||||
| -rw-r--r-- | test/engine/test_reflection.py | 18 | ||||
| -rw-r--r-- | test/engine/test_transaction.py | 20 |
10 files changed, 75 insertions, 75 deletions
diff --git a/test/engine/test_bind.py b/test/engine/test_bind.py index f76350fcc..973cf4d84 100644 --- a/test/engine/test_bind.py +++ b/test/engine/test_bind.py @@ -1,6 +1,6 @@ """tests the "bind" attribute/argument across schema and SQL, including the deprecated versions of these arguments""" -from __future__ import with_statement + from sqlalchemy.testing import eq_, assert_raises from sqlalchemy import engine, exc from sqlalchemy import MetaData, ThreadLocalMetaData @@ -61,7 +61,7 @@ class BindTest(fixtures.TestBase): try: meth() assert False - except exc.UnboundExecutionError, e: + except exc.UnboundExecutionError as e: eq_(str(e), "The MetaData is not bound to an Engine or " "Connection. Execution can not proceed without a " @@ -82,7 +82,7 @@ class BindTest(fixtures.TestBase): try: meth() assert False - except exc.UnboundExecutionError, e: + except exc.UnboundExecutionError as e: eq_( str(e), "The Table 'test_table' " diff --git a/test/engine/test_ddlemit.py b/test/engine/test_ddlemit.py index 3dbd5756a..deaf09cf7 100644 --- a/test/engine/test_ddlemit.py +++ b/test/engine/test_ddlemit.py @@ -47,7 +47,7 @@ class EmitDDLTest(fixtures.TestBase): return (m, ) + tuple( Table('t%d' % i, m, Column('x', Integer)) - for i in xrange(1, 6) + for i in range(1, 6) ) def _table_seq_fixture(self): diff --git a/test/engine/test_ddlevents.py b/test/engine/test_ddlevents.py index 71379ec7e..6cc652baf 100644 --- a/test/engine/test_ddlevents.py +++ b/test/engine/test_ddlevents.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + from sqlalchemy.testing import assert_raises, assert_raises_message from sqlalchemy.schema import DDL, CheckConstraint, AddConstraint, \ DropConstraint diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 203d7bd71..e737accdb 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -1,4 +1,4 @@ -from __future__ import with_statement + from sqlalchemy.testing import eq_, assert_raises, assert_raises_message, \ config, is_ @@ -18,7 +18,7 @@ from sqlalchemy.dialects.oracle.zxjdbc import ReturningParam from sqlalchemy.engine import result as _result, default from sqlalchemy.engine.base import Connection, Engine from sqlalchemy.testing import fixtures -import StringIO +import io users, metadata, users_autoinc = None, None, None class ExecuteTest(fixtures.TestBase): @@ -256,7 +256,7 @@ class ExecuteTest(fixtures.TestBase): try: cursor = raw.cursor() cursor.execute("SELECTINCORRECT") - except testing.db.dialect.dbapi.DatabaseError, orig: + except testing.db.dialect.dbapi.DatabaseError as orig: # py3k has "orig" in local scope... the_orig = orig finally: @@ -622,7 +622,7 @@ class LogParamsTest(fixtures.TestBase): def test_log_large_dict(self): self.eng.execute( "INSERT INTO foo (data) values (:data)", - [{"data":str(i)} for i in xrange(100)] + [{"data":str(i)} for i in range(100)] ) eq_( self.buf.buffer[1].message, @@ -635,7 +635,7 @@ class LogParamsTest(fixtures.TestBase): def test_log_large_list(self): self.eng.execute( "INSERT INTO foo (data) values (?)", - [(str(i), ) for i in xrange(100)] + [(str(i), ) for i in range(100)] ) eq_( self.buf.buffer[1].message, @@ -654,7 +654,7 @@ class LogParamsTest(fixtures.TestBase): "100 total bound parameter sets ... {'data': '98'}, {'data': '99'}\]", lambda: self.eng.execute( "INSERT INTO nonexistent (data) values (:data)", - [{"data":str(i)} for i in xrange(100)] + [{"data":str(i)} for i in range(100)] ) ) @@ -668,7 +668,7 @@ class LogParamsTest(fixtures.TestBase): "\('98',\), \('99',\)\]", lambda: self.eng.execute( "INSERT INTO nonexistent (data) values (?)", - [(str(i), ) for i in xrange(100)] + [(str(i), ) for i in range(100)] ) ) @@ -834,9 +834,9 @@ class EchoTest(fixtures.TestBase): class MockStrategyTest(fixtures.TestBase): def _engine_fixture(self): - buf = StringIO.StringIO() + buf = io.StringIO() def dump(sql, *multiparams, **params): - buf.write(unicode(sql.compile(dialect=engine.dialect))) + buf.write(str(sql.compile(dialect=engine.dialect))) engine = create_engine('postgresql://', strategy='mock', executor=dump) return engine, buf @@ -939,7 +939,7 @@ class ResultProxyTest(fixtures.TestBase): def test_row_c_sequence_check(self): import csv import collections - from StringIO import StringIO + from io import StringIO metadata = MetaData() metadata.bind = 'sqlite://' @@ -1026,7 +1026,7 @@ class AlternateResultProxyTest(fixtures.TestBase): ) m.create_all(engine) engine.execute(t.insert(), [ - {'x':i, 'y':"t_%d" % i} for i in xrange(1, 12) + {'x':i, 'y':"t_%d" % i} for i in range(1, 12) ]) def _test_proxy(self, cls): @@ -1039,13 +1039,13 @@ class AlternateResultProxyTest(fixtures.TestBase): assert isinstance(r, cls) for i in range(5): rows.append(r.fetchone()) - eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) + eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) rows = r.fetchmany(3) - eq_(rows, [(i, "t_%d" % i) for i in xrange(6, 9)]) + eq_(rows, [(i, "t_%d" % i) for i in range(6, 9)]) rows = r.fetchall() - eq_(rows, [(i, "t_%d" % i) for i in xrange(9, 12)]) + eq_(rows, [(i, "t_%d" % i) for i in range(9, 12)]) r = self.engine.execute(select([self.table])) rows = r.fetchmany(None) @@ -1059,7 +1059,7 @@ class AlternateResultProxyTest(fixtures.TestBase): r = self.engine.execute(select([self.table]).limit(5)) rows = r.fetchmany(6) - eq_(rows, [(i, "t_%d" % i) for i in xrange(1, 6)]) + eq_(rows, [(i, "t_%d" % i) for i in range(1, 6)]) def test_plain(self): self._test_proxy(_result.ResultProxy) @@ -1184,7 +1184,7 @@ class EngineEventsTest(fixtures.TestBase): try: conn.execute("SELECT FOO FROM I_DONT_EXIST") assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert canary[0][2] is e.orig assert canary[0][0] == "SELECT FOO FROM I_DONT_EXIST" diff --git a/test/engine/test_parseconnect.py b/test/engine/test_parseconnect.py index a00a942cb..3d99fd509 100644 --- a/test/engine/test_parseconnect.py +++ b/test/engine/test_parseconnect.py @@ -1,6 +1,6 @@ from sqlalchemy.testing import assert_raises, assert_raises_message, eq_ -import ConfigParser -import StringIO +import configparser +import io import sqlalchemy.engine.url as url from sqlalchemy import create_engine, engine_from_config, exc, pool from sqlalchemy.engine.util import _coerce_config @@ -103,8 +103,8 @@ pool_size=2 pool_threadlocal=1 pool_timeout=10 """ - ini = ConfigParser.ConfigParser() - ini.readfp(StringIO.StringIO(raw)) + ini = configparser.ConfigParser() + ini.readfp(io.StringIO(raw)) expected = { 'url': 'postgresql://scott:tiger@somehost/test?fooz=somevalue', @@ -234,7 +234,7 @@ pool_timeout=10 : True}, convert_unicode=True) try: e.connect() - except tsa.exc.DBAPIError, de: + except tsa.exc.DBAPIError as de: assert not de.connection_invalidated def test_ensure_dialect_does_is_disconnect_no_conn(self): @@ -266,7 +266,7 @@ pool_timeout=10 try: create_engine('sqlite://', module=ThrowOnConnect()).connect() assert False - except tsa.exc.DBAPIError, de: + except tsa.exc.DBAPIError as de: assert de.connection_invalidated def test_urlattr(self): diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index c01d14c4f..1d31c16b5 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -525,23 +525,23 @@ class DeprecatedPoolListenerTest(PoolTestBase): self.assert_((item in innerself.checked_out) == in_cout) self.assert_((item in innerself.checked_in) == in_cin) def inst_connect(self, con, record): - print "connect(%s, %s)" % (con, record) + print("connect(%s, %s)" % (con, record)) assert con is not None assert record is not None self.connected.append(con) def inst_first_connect(self, con, record): - print "first_connect(%s, %s)" % (con, record) + print("first_connect(%s, %s)" % (con, record)) assert con is not None assert record is not None self.first_connected.append(con) def inst_checkout(self, con, record, proxy): - print "checkout(%s, %s, %s)" % (con, record, proxy) + print("checkout(%s, %s, %s)" % (con, record, proxy)) assert con is not None assert record is not None assert proxy is not None self.checked_out.append(con) def inst_checkin(self, con, record): - print "checkin(%s, %s)" % (con, record) + print("checkin(%s, %s)" % (con, record)) # con can be None if invalidated assert record is not None self.checked_in.append(con) @@ -738,8 +738,8 @@ class QueuePoolTest(PoolTestBase): def status(pool): tup = pool.size(), pool.checkedin(), pool.overflow(), \ pool.checkedout() - print 'Pool size: %d Connections in pool: %d Current '\ - 'Overflow: %d Current Checked out connections: %d' % tup + print('Pool size: %d Connections in pool: %d Current '\ + 'Overflow: %d Current Checked out connections: %d' % tup) return tup c1 = p.connect() @@ -794,7 +794,7 @@ class QueuePoolTest(PoolTestBase): try: c4 = p.connect() assert False - except tsa.exc.TimeoutError, e: + except tsa.exc.TimeoutError as e: assert int(time.time() - now) == 2 def test_timeout_race(self): @@ -812,18 +812,18 @@ class QueuePoolTest(PoolTestBase): max_overflow = 1, use_threadlocal = False, timeout=3) timeouts = [] def checkout(): - for x in xrange(1): + for x in range(1): now = time.time() try: c1 = p.connect() - except tsa.exc.TimeoutError, e: + except tsa.exc.TimeoutError as e: timeouts.append(time.time() - now) continue time.sleep(4) c1.close() threads = [] - for i in xrange(10): + for i in range(10): th = threading.Thread(target=checkout) th.start() threads.append(th) @@ -860,7 +860,7 @@ class QueuePoolTest(PoolTestBase): except tsa.exc.TimeoutError: pass threads = [] - for i in xrange(thread_count): + for i in range(thread_count): th = threading.Thread(target=whammy) th.start() threads.append(th) @@ -1007,8 +1007,8 @@ class QueuePoolTest(PoolTestBase): strong_refs.add(c.connection) return c - for j in xrange(5): - conns = [_conn() for i in xrange(4)] + for j in range(5): + conns = [_conn() for i in range(4)] for c in conns: c.close() @@ -1152,7 +1152,7 @@ class SingletonThreadPoolTest(PoolTestBase): return p.connect() def checkout(): - for x in xrange(10): + for x in range(10): c = _conn() assert c c.cursor() @@ -1160,7 +1160,7 @@ class SingletonThreadPoolTest(PoolTestBase): time.sleep(.1) threads = [] - for i in xrange(10): + for i in range(10): th = threading.Thread(target=checkout) th.start() threads.append(th) diff --git a/test/engine/test_processors.py b/test/engine/test_processors.py index bc9af7305..b1c482f09 100644 --- a/test/engine/test_processors.py +++ b/test/engine/test_processors.py @@ -53,7 +53,7 @@ class PyDateProcessorTest(_DateProcessorTest): cls.module = type("util", (object,), dict( (k, staticmethod(v)) - for k, v in processors.py_fallback().items() + for k, v in list(processors.py_fallback().items()) ) ) @@ -156,7 +156,7 @@ class PyDistillArgsTest(_DistillArgsTest): cls.module = type("util", (object,), dict( (k, staticmethod(v)) - for k, v in util.py_fallback().items() + for k, v in list(util.py_fallback().items()) ) ) diff --git a/test/engine/test_reconnect.py b/test/engine/test_reconnect.py index 9aecb81a9..d75ef3b75 100644 --- a/test/engine/test_reconnect.py +++ b/test/engine/test_reconnect.py @@ -173,7 +173,7 @@ class MockReconnectTest(fixtures.TestBase): try: trans.commit() assert False - except tsa.exc.InvalidRequestError, e: + except tsa.exc.InvalidRequestError as e: assert str(e) \ == "Can't reconnect until invalid transaction is "\ "rolled back" @@ -370,7 +370,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise @@ -386,7 +386,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert conn.invalidated @@ -407,7 +407,7 @@ class RealReconnectTest(fixtures.TestBase): try: c1.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert e.connection_invalidated p2 = engine.pool @@ -415,7 +415,7 @@ class RealReconnectTest(fixtures.TestBase): try: c2.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: assert e.connection_invalidated # pool isn't replaced @@ -503,7 +503,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert not conn.closed @@ -523,7 +523,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise @@ -542,7 +542,7 @@ class RealReconnectTest(fixtures.TestBase): try: conn.execute(select([1])) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert not conn.closed @@ -558,7 +558,7 @@ class RealReconnectTest(fixtures.TestBase): try: trans.commit() assert False - except tsa.exc.InvalidRequestError, e: + except tsa.exc.InvalidRequestError as e: assert str(e) \ == "Can't reconnect until invalid transaction is "\ "rolled back" @@ -634,13 +634,13 @@ class InvalidateDuringResultTest(fixtures.TestBase): def test_invalidate_on_results(self): conn = engine.connect() result = conn.execute('select * from sometable') - for x in xrange(20): + for x in range(20): result.fetchone() engine.test_shutdown() try: - print 'ghost result: %r' % result.fetchone() + print('ghost result: %r' % result.fetchone()) assert False - except tsa.exc.DBAPIError, e: + except tsa.exc.DBAPIError as e: if not e.connection_invalidated: raise assert conn.invalidated diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index 86df92987..c2e3493f3 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -811,7 +811,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): try: m4.reflect(only=['rt_a', 'rt_f']) self.assert_(False) - except sa.exc.InvalidRequestError, e: + except sa.exc.InvalidRequestError as e: self.assert_(e.args[0].endswith('(rt_f)')) m5 = MetaData(testing.db) @@ -833,7 +833,7 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): ) if existing: - print "Other tables present in database, skipping some checks." + print("Other tables present in database, skipping some checks.") else: baseline.drop_all() m9 = MetaData(testing.db) @@ -1041,19 +1041,19 @@ class UnicodeReflectionTest(fixtures.TestBase): cls.metadata = metadata = MetaData() no_multibyte_period = set([ - (u'plain', u'col_plain', u'ix_plain') + ('plain', 'col_plain', 'ix_plain') ]) no_has_table = [ - (u'no_has_table_1', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), - (u'no_has_table_2', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), + ('no_has_table_1', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), + ('no_has_table_2', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), ] no_case_sensitivity = [ - (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), - (u'unit\u00e9ble', u'col_unit\u00e9ble', u'ix_unit\u00e9ble'), + ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), + ('unit\u00e9ble', 'col_unit\u00e9ble', 'ix_unit\u00e9ble'), ] full = [ - (u'Unit\u00e9ble', u'col_Unit\u00e9ble', u'ix_Unit\u00e9ble'), - (u'\u6e2c\u8a66', u'col_\u6e2c\u8a66', u'ix_\u6e2c\u8a66'), + ('Unit\u00e9ble', 'col_Unit\u00e9ble', 'ix_Unit\u00e9ble'), + ('\u6e2c\u8a66', 'col_\u6e2c\u8a66', 'ix_\u6e2c\u8a66'), ] # as you can see, our options for this kind of thing diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 5558ff778..2d7f39253 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -74,8 +74,8 @@ class TransactionTest(fixtures.TestBase): connection.execute(users.insert(), user_id=1, user_name='user3') transaction.commit() assert False - except Exception , e: - print "Exception: ", e + except Exception as e: + print("Exception: ", e) transaction.rollback() result = connection.execute("select * from query_users") @@ -121,10 +121,10 @@ class TransactionTest(fixtures.TestBase): trans2.rollback() raise transaction.rollback() - except Exception, e: + except Exception as e: transaction.rollback() raise - except Exception, e: + except Exception as e: try: assert str(e) == 'uh oh' # and not "This transaction is # inactive" @@ -167,7 +167,7 @@ class TransactionTest(fixtures.TestBase): connection.execute(users.insert(), user_id=2, user_name='user2') try: connection.execute(users.insert(), user_id=2, user_name='user2.5') - except Exception, e: + except Exception as e: trans.__exit__(*sys.exc_info()) assert not trans.is_active @@ -1019,7 +1019,7 @@ class ForUpdateTest(fixtures.TestBase): con = testing.db.connect() sel = counters.select(for_update=update_style, whereclause=counters.c.counter_id == 1) - for i in xrange(count): + for i in range(count): trans = con.begin() try: existing = con.execute(sel).first() @@ -1033,7 +1033,7 @@ class ForUpdateTest(fixtures.TestBase): raise AssertionError('Got %s post-update, expected ' '%s' % (readback['counter_value'], incr)) trans.commit() - except Exception, e: + except Exception as e: trans.rollback() errors.append(e) break @@ -1057,7 +1057,7 @@ class ForUpdateTest(fixtures.TestBase): db.execute(counters.insert(), counter_id=1, counter_value=0) iterations, thread_count = 10, 5 threads, errors = [], [] - for i in xrange(thread_count): + for i in range(thread_count): thrd = threading.Thread(target=self.increment, args=(iterations, ), kwargs={'errors': errors, @@ -1088,7 +1088,7 @@ class ForUpdateTest(fixtures.TestBase): rows = con.execute(sel).fetchall() time.sleep(0.25) trans.commit() - except Exception, e: + except Exception as e: trans.rollback() errors.append(e) con.close() @@ -1105,7 +1105,7 @@ class ForUpdateTest(fixtures.TestBase): db.execute(counters.insert(), counter_id=cid + 1, counter_value=0) errors, threads = [], [] - for i in xrange(thread_count): + for i in range(thread_count): thrd = threading.Thread(target=self.overlap, args=(groups.pop(0), errors, update_style)) |
