diff options
Diffstat (limited to 'lib/sqlalchemy/testing/suite')
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_ddl.py | 14 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_insert.py | 77 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 144 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_results.py | 86 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_select.py | 23 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_sequence.py | 28 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_types.py | 144 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_update_delete.py | 12 |
8 files changed, 261 insertions, 267 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_ddl.py b/lib/sqlalchemy/testing/suite/test_ddl.py index 2dca1443d..1d8010c8a 100644 --- a/lib/sqlalchemy/testing/suite/test_ddl.py +++ b/lib/sqlalchemy/testing/suite/test_ddl.py @@ -12,15 +12,17 @@ class TableDDLTest(fixtures.TestBase): def _simple_fixture(self): return Table('test_table', self.metadata, - Column('id', Integer, primary_key=True, autoincrement=False), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, + autoincrement=False), + Column('data', String(50)) + ) def _underscore_fixture(self): return Table('_test_table', self.metadata, - Column('id', Integer, primary_key=True, autoincrement=False), - Column('_data', String(50)) - ) + Column('id', Integer, primary_key=True, + autoincrement=False), + Column('_data', String(50)) + ) def _simple_roundtrip(self, table): with config.db.begin() as conn: diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py index 3444e15c8..92d3d93e5 100644 --- a/lib/sqlalchemy/testing/suite/test_insert.py +++ b/lib/sqlalchemy/testing/suite/test_insert.py @@ -21,15 +21,15 @@ class LastrowidTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('autoinc_pk', metadata, - Column('id', Integer, primary_key=True, - test_needs_autoincrement=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('data', String(50)) + ) Table('manual_pk', metadata, - Column('id', Integer, primary_key=True, autoincrement=False), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, autoincrement=False), + Column('data', String(50)) + ) def _assert_round_trip(self, table, conn): row = conn.execute(table.select()).first() @@ -59,8 +59,9 @@ class LastrowidTest(fixtures.TablesTest): ) # failed on pypy1.9 but seems to be OK on pypy 2.1 - #@exclusions.fails_if(lambda: util.pypy, "lastrowid not maintained after " - # "connection close") + # @exclusions.fails_if(lambda: util.pypy, + # "lastrowid not maintained after " + # "connection close") @requirements.dbapi_lastrowid def test_native_lastrowid_autoinc(self): r = config.db.execute( @@ -81,19 +82,19 @@ class InsertBehaviorTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('autoinc_pk', metadata, - Column('id', Integer, primary_key=True, \ - test_needs_autoincrement=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('data', String(50)) + ) Table('manual_pk', metadata, - Column('id', Integer, primary_key=True, autoincrement=False), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, autoincrement=False), + Column('data', String(50)) + ) def test_autoclose_on_insert(self): if requirements.returning.enabled: engine = engines.testing_engine( - options={'implicit_returning': False}) + options={'implicit_returning': False}) else: engine = config.db @@ -119,12 +120,12 @@ class InsertBehaviorTest(fixtures.TablesTest): def test_empty_insert(self): r = config.db.execute( self.tables.autoinc_pk.insert(), - ) + ) assert r.closed r = config.db.execute( - self.tables.autoinc_pk.select().\ - where(self.tables.autoinc_pk.c.id != None) + self.tables.autoinc_pk.select(). + where(self.tables.autoinc_pk.c.id != None) ) assert len(r.fetchall()) @@ -133,21 +134,20 @@ class InsertBehaviorTest(fixtures.TablesTest): def test_insert_from_select(self): table = self.tables.manual_pk config.db.execute( - table.insert(), - [ - dict(id=1, data="data1"), - dict(id=2, data="data2"), - dict(id=3, data="data3"), - ] + table.insert(), + [ + dict(id=1, data="data1"), + dict(id=2, data="data2"), + dict(id=3, data="data3"), + ] ) - config.db.execute( - table.insert(inline=True). - from_select( - ("id", "data",), select([table.c.id + 5, table.c.data]).where( - table.c.data.in_(["data2", "data3"])) - ), + table.insert(inline=True). + from_select(("id", "data",), + select([table.c.id + 5, table.c.data]). + where(table.c.data.in_(["data2", "data3"])) + ), ) eq_( @@ -158,6 +158,7 @@ class InsertBehaviorTest(fixtures.TablesTest): ("data3", ), ("data3", )] ) + class ReturningTest(fixtures.TablesTest): run_create_tables = 'each' __requires__ = 'returning', 'autoincrement_insert' @@ -175,10 +176,10 @@ class ReturningTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('autoinc_pk', metadata, - Column('id', Integer, primary_key=True, \ - test_needs_autoincrement=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('data', String(50)) + ) @requirements.fetch_rows_post_commit def test_explicit_returning_pk_autocommit(self): @@ -186,7 +187,7 @@ class ReturningTest(fixtures.TablesTest): table = self.tables.autoinc_pk r = engine.execute( table.insert().returning( - table.c.id), + table.c.id), data="some data" ) pk = r.first()[0] @@ -199,7 +200,7 @@ class ReturningTest(fixtures.TablesTest): with engine.begin() as conn: r = conn.execute( table.insert().returning( - table.c.id), + table.c.id), data="some data" ) pk = r.first()[0] diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 762c9955c..7cc5fd160 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -24,9 +24,9 @@ class HasTableTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('test_table', metadata, - Column('id', Integer, primary_key=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True), + Column('data', String(50)) + ) def test_has_table(self): with config.db.begin() as conn: @@ -34,8 +34,6 @@ class HasTableTest(fixtures.TablesTest): assert not config.db.dialect.has_table(conn, "nonexistent_table") - - class ComponentReflectionTest(fixtures.TablesTest): run_inserts = run_deletes = None @@ -56,41 +54,42 @@ class ComponentReflectionTest(fixtures.TablesTest): if testing.requires.self_referential_foreign_keys.enabled: users = Table('users', metadata, - Column('user_id', sa.INT, primary_key=True), - Column('test1', sa.CHAR(5), nullable=False), - Column('test2', sa.Float(5), nullable=False), - Column('parent_user_id', sa.Integer, - sa.ForeignKey('%susers.user_id' % schema_prefix)), - schema=schema, - test_needs_fk=True, - ) + Column('user_id', sa.INT, primary_key=True), + Column('test1', sa.CHAR(5), nullable=False), + Column('test2', sa.Float(5), nullable=False), + Column('parent_user_id', sa.Integer, + sa.ForeignKey('%susers.user_id' % + schema_prefix)), + schema=schema, + test_needs_fk=True, + ) else: users = Table('users', metadata, - Column('user_id', sa.INT, primary_key=True), - Column('test1', sa.CHAR(5), nullable=False), - Column('test2', sa.Float(5), nullable=False), - schema=schema, - test_needs_fk=True, - ) + Column('user_id', sa.INT, primary_key=True), + Column('test1', sa.CHAR(5), nullable=False), + Column('test2', sa.Float(5), nullable=False), + schema=schema, + test_needs_fk=True, + ) Table("dingalings", metadata, - Column('dingaling_id', sa.Integer, primary_key=True), - Column('address_id', sa.Integer, - sa.ForeignKey('%semail_addresses.address_id' % - schema_prefix)), - Column('data', sa.String(30)), - schema=schema, - test_needs_fk=True, - ) + Column('dingaling_id', sa.Integer, primary_key=True), + Column('address_id', sa.Integer, + sa.ForeignKey('%semail_addresses.address_id' % + schema_prefix)), + Column('data', sa.String(30)), + schema=schema, + test_needs_fk=True, + ) Table('email_addresses', metadata, - Column('address_id', sa.Integer), - Column('remote_user_id', sa.Integer, - sa.ForeignKey(users.c.user_id)), - Column('email_address', sa.String(20)), - sa.PrimaryKeyConstraint('address_id', name='email_ad_pk'), - schema=schema, - test_needs_fk=True, - ) + Column('address_id', sa.Integer), + Column('remote_user_id', sa.Integer, + sa.ForeignKey(users.c.user_id)), + Column('email_address', sa.String(20)), + sa.PrimaryKeyConstraint('address_id', name='email_ad_pk'), + schema=schema, + test_needs_fk=True, + ) if testing.requires.index_reflection.enabled: cls.define_index(metadata, users) @@ -110,7 +109,7 @@ class ComponentReflectionTest(fixtures.TablesTest): fullname = "%s.%s" % (schema, table_name) view_name = fullname + '_v' query = "CREATE VIEW %s AS SELECT * FROM %s" % ( - view_name, fullname) + view_name, fullname) event.listen( metadata, @@ -146,7 +145,7 @@ class ComponentReflectionTest(fixtures.TablesTest): order_by=None): meta = self.metadata users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings insp = inspect(meta.bind) if table_type == 'view': table_names = insp.get_view_names(schema) @@ -195,13 +194,13 @@ class ComponentReflectionTest(fixtures.TablesTest): def _test_get_columns(self, schema=None, table_type='table'): meta = MetaData(testing.db) users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings table_names = ['users', 'email_addresses'] if table_type == 'view': table_names = ['users_v', 'email_addresses_v'] insp = inspect(meta.bind) for table_name, table in zip(table_names, (users, - addresses)): + addresses)): schema_name = schema cols = insp.get_columns(table_name, schema=schema_name) self.assert_(len(cols) > 0, len(cols)) @@ -218,23 +217,24 @@ class ComponentReflectionTest(fixtures.TablesTest): # Oracle returns Date for DateTime. if testing.against('oracle') and ctype_def \ - in (sql_types.Date, sql_types.DateTime): + in (sql_types.Date, sql_types.DateTime): ctype_def = sql_types.Date # assert that the desired type and return type share # a base within one of the generic types. self.assert_(len(set(ctype.__mro__). - intersection(ctype_def.__mro__).intersection([ - sql_types.Integer, - sql_types.Numeric, - sql_types.DateTime, - sql_types.Date, - sql_types.Time, - sql_types.String, - sql_types._Binary, - ])) > 0, '%s(%s), %s(%s)' % (col.name, - col.type, cols[i]['name'], ctype)) + intersection(ctype_def.__mro__). + intersection([ + sql_types.Integer, + sql_types.Numeric, + sql_types.DateTime, + sql_types.Date, + sql_types.Time, + sql_types.String, + sql_types._Binary, + ])) > 0, '%s(%s), %s(%s)' % + (col.name, col.type, cols[i]['name'], ctype)) if not col.primary_key: assert cols[i]['default'] is None @@ -246,11 +246,11 @@ class ComponentReflectionTest(fixtures.TablesTest): @testing.provide_metadata def _type_round_trip(self, *types): t = Table('t', self.metadata, - *[ - Column('t%d' % i, type_) - for i, type_ in enumerate(types) - ] - ) + *[ + Column('t%d' % i, type_) + for i, type_ in enumerate(types) + ] + ) t.create() return [ @@ -261,8 +261,8 @@ class ComponentReflectionTest(fixtures.TablesTest): @testing.requires.table_reflection def test_numeric_reflection(self): for typ in self._type_round_trip( - sql_types.Numeric(18, 5), - ): + sql_types.Numeric(18, 5), + ): assert isinstance(typ, sql_types.Numeric) eq_(typ.precision, 18) eq_(typ.scale, 5) @@ -277,8 +277,8 @@ class ComponentReflectionTest(fixtures.TablesTest): @testing.provide_metadata def test_nullable_reflection(self): t = Table('t', self.metadata, - Column('a', Integer, nullable=True), - Column('b', Integer, nullable=False)) + Column('a', Integer, nullable=True), + Column('b', Integer, nullable=False)) t.create() eq_( dict( @@ -288,7 +288,6 @@ class ComponentReflectionTest(fixtures.TablesTest): {"a": True, "b": False} ) - @testing.requires.table_reflection @testing.requires.schemas def test_get_columns_with_schema(self): @@ -311,11 +310,11 @@ class ComponentReflectionTest(fixtures.TablesTest): users_cons = insp.get_pk_constraint(users.name, schema=schema) users_pkeys = users_cons['constrained_columns'] - eq_(users_pkeys, ['user_id']) + eq_(users_pkeys, ['user_id']) addr_cons = insp.get_pk_constraint(addresses.name, schema=schema) addr_pkeys = addr_cons['constrained_columns'] - eq_(addr_pkeys, ['address_id']) + eq_(addr_pkeys, ['address_id']) with testing.requires.reflects_pk_names.fail_if(): eq_(addr_cons['name'], 'email_ad_pk') @@ -347,7 +346,7 @@ class ComponentReflectionTest(fixtures.TablesTest): def _test_get_foreign_keys(self, schema=None): meta = self.metadata users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings insp = inspect(meta.bind) expected_schema = schema # users @@ -366,7 +365,7 @@ class ComponentReflectionTest(fixtures.TablesTest): if testing.requires.self_referential_foreign_keys.enabled: eq_(fkey1['constrained_columns'], ['parent_user_id']) - #addresses + # addresses addr_fkeys = insp.get_foreign_keys(addresses.name, schema=schema) fkey1 = addr_fkeys[0] @@ -392,7 +391,7 @@ class ComponentReflectionTest(fixtures.TablesTest): def _test_get_indexes(self, schema=None): meta = self.metadata users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings # The database may decide to create indexes for foreign keys, etc. # so there may be more indexes than expected. insp = inspect(meta.bind) @@ -421,7 +420,6 @@ class ComponentReflectionTest(fixtures.TablesTest): def test_get_indexes_with_schema(self): self._test_get_indexes(schema='test_schema') - @testing.requires.unique_constraint_reflection def test_get_unique_constraints(self): self._test_get_unique_constraints() @@ -468,12 +466,11 @@ class ComponentReflectionTest(fixtures.TablesTest): for orig, refl in zip(uniques, reflected): eq_(orig, refl) - @testing.provide_metadata def _test_get_view_definition(self, schema=None): meta = self.metadata users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings view_name1 = 'users_v' view_name2 = 'email_addresses_v' insp = inspect(meta.bind) @@ -496,7 +493,7 @@ class ComponentReflectionTest(fixtures.TablesTest): def _test_get_table_oid(self, table_name, schema=None): meta = self.metadata users, addresses, dingalings = self.tables.users, \ - self.tables.email_addresses, self.tables.dingalings + self.tables.email_addresses, self.tables.dingalings insp = inspect(meta.bind) oid = insp.get_table_oid(table_name, schema) self.assert_(isinstance(oid, int)) @@ -527,14 +524,13 @@ class ComponentReflectionTest(fixtures.TablesTest): insp = inspect(meta.bind) for tname, cname in [ - ('users', 'user_id'), - ('email_addresses', 'address_id'), - ('dingalings', 'dingaling_id'), - ]: + ('users', 'user_id'), + ('email_addresses', 'address_id'), + ('dingalings', 'dingaling_id'), + ]: cols = insp.get_columns(tname) id_ = dict((c['name'], c) for c in cols)[cname] assert id_.get('autoincrement', True) - __all__ = ('ComponentReflectionTest', 'HasTableTest') diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py index 2fdab4d17..9ffaa6e04 100644 --- a/lib/sqlalchemy/testing/suite/test_results.py +++ b/lib/sqlalchemy/testing/suite/test_results.py @@ -15,13 +15,13 @@ class RowFetchTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('plain_pk', metadata, - Column('id', Integer, primary_key=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True), + Column('data', String(50)) + ) Table('has_dates', metadata, - Column('id', Integer, primary_key=True), - Column('today', DateTime) - ) + Column('id', Integer, primary_key=True), + Column('today', DateTime) + ) @classmethod def insert_data(cls): @@ -43,9 +43,9 @@ class RowFetchTest(fixtures.TablesTest): def test_via_string(self): row = config.db.execute( - self.tables.plain_pk.select().\ - order_by(self.tables.plain_pk.c.id) - ).first() + self.tables.plain_pk.select(). + order_by(self.tables.plain_pk.c.id) + ).first() eq_( row['id'], 1 @@ -56,9 +56,9 @@ class RowFetchTest(fixtures.TablesTest): def test_via_int(self): row = config.db.execute( - self.tables.plain_pk.select().\ - order_by(self.tables.plain_pk.c.id) - ).first() + self.tables.plain_pk.select(). + order_by(self.tables.plain_pk.c.id) + ).first() eq_( row[0], 1 @@ -69,9 +69,9 @@ class RowFetchTest(fixtures.TablesTest): def test_via_col_object(self): row = config.db.execute( - self.tables.plain_pk.select().\ - order_by(self.tables.plain_pk.c.id) - ).first() + self.tables.plain_pk.select(). + order_by(self.tables.plain_pk.c.id) + ).first() eq_( row[self.tables.plain_pk.c.id], 1 @@ -83,15 +83,14 @@ class RowFetchTest(fixtures.TablesTest): @requirements.duplicate_names_in_cursor_description def test_row_with_dupe_names(self): result = config.db.execute( - select([self.tables.plain_pk.c.data, - self.tables.plain_pk.c.data.label('data')]).\ - order_by(self.tables.plain_pk.c.id) - ) + select([self.tables.plain_pk.c.data, + self.tables.plain_pk.c.data.label('data')]). + order_by(self.tables.plain_pk.c.id) + ) row = result.first() eq_(result.keys(), ['data', 'data']) eq_(row, ('d1', 'd1')) - def test_row_w_scalar_select(self): """test that a scalar select as a column is returned as such and that type conversion works OK. @@ -124,12 +123,13 @@ class PercentSchemaNamesTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): cls.tables.percent_table = Table('percent%table', metadata, - Column("percent%", Integer), - Column("spaces % more spaces", Integer), - ) - cls.tables.lightweight_percent_table = sql.table('percent%table', - sql.column("percent%"), - sql.column("spaces % more spaces"), + Column("percent%", Integer), + Column( + "spaces % more spaces", Integer), + ) + cls.tables.lightweight_percent_table = sql.table( + 'percent%table', sql.column("percent%"), + sql.column("spaces % more spaces") ) def test_single_roundtrip(self): @@ -152,8 +152,8 @@ class PercentSchemaNamesTest(fixtures.TablesTest): config.db.execute( percent_table.insert(), [{'percent%': 7, 'spaces % more spaces': 11}, - {'percent%': 9, 'spaces % more spaces': 10}, - {'percent%': 11, 'spaces % more spaces': 9}] + {'percent%': 9, 'spaces % more spaces': 10}, + {'percent%': 11, 'spaces % more spaces': 9}] ) self._assert_table() @@ -162,10 +162,10 @@ class PercentSchemaNamesTest(fixtures.TablesTest): lightweight_percent_table = self.tables.lightweight_percent_table for table in ( - percent_table, - percent_table.alias(), - lightweight_percent_table, - lightweight_percent_table.alias()): + percent_table, + percent_table.alias(), + lightweight_percent_table, + lightweight_percent_table.alias()): eq_( list( config.db.execute( @@ -184,18 +184,18 @@ class PercentSchemaNamesTest(fixtures.TablesTest): list( config.db.execute( table.select(). - where(table.c['spaces % more spaces'].in_([9, 10])). - order_by(table.c['percent%']), + where(table.c['spaces % more spaces'].in_([9, 10])). + order_by(table.c['percent%']), ) ), - [ - (9, 10), - (11, 9) - ] + [ + (9, 10), + (11, 9) + ] ) - row = config.db.execute(table.select().\ - order_by(table.c['percent%'])).first() + row = config.db.execute(table.select(). + order_by(table.c['percent%'])).first() eq_(row['percent%'], 5) eq_(row['spaces % more spaces'], 12) @@ -211,9 +211,9 @@ class PercentSchemaNamesTest(fixtures.TablesTest): eq_( list( config.db.execute( - percent_table.\ - select().\ - order_by(percent_table.c['percent%']) + percent_table. + select(). + order_by(percent_table.c['percent%']) ) ), [(5, 15), (7, 15), (9, 15), (11, 15)] diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py index 3461b1e94..3f14ada05 100644 --- a/lib/sqlalchemy/testing/suite/test_select.py +++ b/lib/sqlalchemy/testing/suite/test_select.py @@ -21,12 +21,12 @@ class OrderByLabelTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table("some_table", metadata, - Column('id', Integer, primary_key=True), - Column('x', Integer), - Column('y', Integer), - Column('q', String(50)), - Column('p', String(50)) - ) + Column('id', Integer, primary_key=True), + Column('x', Integer), + Column('y', Integer), + Column('q', String(50)), + Column('p', String(50)) + ) @classmethod def insert_data(cls): @@ -86,15 +86,16 @@ class OrderByLabelTest(fixtures.TablesTest): [(7, ), (5, ), (3, )] ) + class LimitOffsetTest(fixtures.TablesTest): __backend__ = True @classmethod def define_tables(cls, metadata): Table("some_table", metadata, - Column('id', Integer, primary_key=True), - Column('x', Integer), - Column('y', Integer)) + Column('id', Integer, primary_key=True), + Column('x', Integer), + Column('y', Integer)) @classmethod def insert_data(cls): @@ -157,8 +158,8 @@ class LimitOffsetTest(fixtures.TablesTest): def test_bound_limit_offset(self): table = self.tables.some_table self._assert_result( - select([table]).order_by(table.c.id).\ - limit(bindparam("l")).offset(bindparam("o")), + select([table]).order_by(table.c.id). + limit(bindparam("l")).offset(bindparam("o")), [(2, 2, 3), (3, 3, 4)], params={"l": 2, "o": 1} ) diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py index 6bc2822fc..bbb4ba65c 100644 --- a/lib/sqlalchemy/testing/suite/test_sequence.py +++ b/lib/sqlalchemy/testing/suite/test_sequence.py @@ -7,6 +7,7 @@ from ... import Integer, String, Sequence, schema from ..schema import Table, Column + class SequenceTest(fixtures.TablesTest): __requires__ = ('sequences',) __backend__ = True @@ -16,15 +17,15 @@ class SequenceTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('seq_pk', metadata, - Column('id', Integer, Sequence('tab_id_seq'), primary_key=True), - Column('data', String(50)) - ) + Column('id', Integer, Sequence('tab_id_seq'), primary_key=True), + Column('data', String(50)) + ) Table('seq_opt_pk', metadata, - Column('id', Integer, Sequence('tab_id_seq', optional=True), - primary_key=True), - Column('data', String(50)) - ) + Column('id', Integer, Sequence('tab_id_seq', optional=True), + primary_key=True), + Column('data', String(50)) + ) def test_insert_roundtrip(self): config.db.execute( @@ -62,7 +63,6 @@ class SequenceTest(fixtures.TablesTest): [1] ) - def _assert_round_trip(self, table, conn): row = conn.execute(table.select()).first() eq_( @@ -80,7 +80,7 @@ class HasSequenceTest(fixtures.TestBase): testing.db.execute(schema.CreateSequence(s1)) try: eq_(testing.db.dialect.has_sequence(testing.db, - 'user_id_seq'), True) + 'user_id_seq'), True) finally: testing.db.execute(schema.DropSequence(s1)) @@ -89,8 +89,8 @@ class HasSequenceTest(fixtures.TestBase): s1 = Sequence('user_id_seq', schema="test_schema") testing.db.execute(schema.CreateSequence(s1)) try: - eq_(testing.db.dialect.has_sequence(testing.db, - 'user_id_seq', schema="test_schema"), True) + eq_(testing.db.dialect.has_sequence( + testing.db, 'user_id_seq', schema="test_schema"), True) finally: testing.db.execute(schema.DropSequence(s1)) @@ -101,7 +101,7 @@ class HasSequenceTest(fixtures.TestBase): @testing.requires.schemas def test_has_sequence_schemas_neg(self): eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', - schema="test_schema"), + schema="test_schema"), False) @testing.requires.schemas @@ -110,7 +110,7 @@ class HasSequenceTest(fixtures.TestBase): testing.db.execute(schema.CreateSequence(s1)) try: eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', - schema="test_schema"), + schema="test_schema"), False) finally: testing.db.execute(schema.DropSequence(s1)) @@ -124,5 +124,3 @@ class HasSequenceTest(fixtures.TestBase): False) finally: testing.db.execute(schema.DropSequence(s1)) - - diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 3a5134c96..230aeb1e9 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -5,7 +5,7 @@ from ..assertions import eq_ from ..config import requirements from sqlalchemy import Integer, Unicode, UnicodeText, select from sqlalchemy import Date, DateTime, Time, MetaData, String, \ - Text, Numeric, Float, literal, Boolean + Text, Numeric, Float, literal, Boolean from ..schema import Table, Column from ... import testing import decimal @@ -28,9 +28,9 @@ class _LiteralRoundTripFixture(object): for value in input_: ins = t.insert().values(x=literal(value)).compile( - dialect=testing.db.dialect, - compile_kwargs=dict(literal_binds=True) - ) + dialect=testing.db.dialect, + compile_kwargs=dict(literal_binds=True) + ) testing.db.execute(ins) for row in t.select().execute(): @@ -43,17 +43,17 @@ class _LiteralRoundTripFixture(object): class _UnicodeFixture(_LiteralRoundTripFixture): __requires__ = 'unicode_data', - data = u("Alors vous imaginez ma surprise, au lever du jour, "\ - "quand une drôle de petite voix m’a réveillé. Elle "\ - "disait: « S’il vous plaît… dessine-moi un mouton! »") + data = u("Alors vous imaginez ma surprise, au lever du jour, " + "quand une drôle de petite voix m’a réveillé. Elle " + "disait: « S’il vous plaît… dessine-moi un mouton! »") @classmethod def define_tables(cls, metadata): Table('unicode_table', metadata, - Column('id', Integer, primary_key=True, - test_needs_autoincrement=True), - Column('unicode_data', cls.datatype), - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('unicode_data', cls.datatype), + ) def test_round_trip(self): unicode_table = self.tables.unicode_table @@ -66,10 +66,10 @@ class _UnicodeFixture(_LiteralRoundTripFixture): ) row = config.db.execute( - select([ - unicode_table.c.unicode_data, - ]) - ).first() + select([ + unicode_table.c.unicode_data, + ]) + ).first() eq_( row, @@ -91,10 +91,10 @@ class _UnicodeFixture(_LiteralRoundTripFixture): ) rows = config.db.execute( - select([ - unicode_table.c.unicode_data, - ]) - ).fetchall() + select([ + unicode_table.c.unicode_data, + ]) + ).fetchall() eq_( rows, [(self.data, ) for i in range(3)] @@ -110,8 +110,8 @@ class _UnicodeFixture(_LiteralRoundTripFixture): {"unicode_data": u('')} ) row = config.db.execute( - select([unicode_table.c.unicode_data]) - ).first() + select([unicode_table.c.unicode_data]) + ).first() eq_(row, (u(''),)) def test_literal(self): @@ -139,6 +139,7 @@ class UnicodeTextTest(_UnicodeFixture, fixtures.TablesTest): def test_empty_strings_text(self): self._test_empty_strings() + class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): __requires__ = 'text_type', __backend__ = True @@ -146,10 +147,10 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('text_table', metadata, - Column('id', Integer, primary_key=True, - test_needs_autoincrement=True), - Column('text_data', Text), - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('text_data', Text), + ) def test_text_roundtrip(self): text_table = self.tables.text_table @@ -159,8 +160,8 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): {"text_data": 'some text'} ) row = config.db.execute( - select([text_table.c.text_data]) - ).first() + select([text_table.c.text_data]) + ).first() eq_(row, ('some text',)) def test_text_empty_strings(self): @@ -171,8 +172,8 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): {"text_data": ''} ) row = config.db.execute( - select([text_table.c.text_data]) - ).first() + select([text_table.c.text_data]) + ).first() eq_(row, ('',)) def test_literal(self): @@ -186,6 +187,7 @@ class TextTest(_LiteralRoundTripFixture, fixtures.TablesTest): data = r'backslash one \ backslash two \\ end' self._literal_round_trip(Text, [data], [data]) + class StringTest(_LiteralRoundTripFixture, fixtures.TestBase): __backend__ = True @@ -194,7 +196,7 @@ class StringTest(_LiteralRoundTripFixture, fixtures.TestBase): metadata = MetaData() foo = Table('foo', metadata, Column('one', String) - ) + ) foo.create(config.db) foo.drop(config.db) @@ -217,10 +219,10 @@ class _DateFixture(_LiteralRoundTripFixture): @classmethod def define_tables(cls, metadata): Table('date_table', metadata, - Column('id', Integer, primary_key=True, - test_needs_autoincrement=True), - Column('date_data', cls.datatype), - ) + Column('id', Integer, primary_key=True, + test_needs_autoincrement=True), + Column('date_data', cls.datatype), + ) def test_round_trip(self): date_table = self.tables.date_table @@ -231,10 +233,10 @@ class _DateFixture(_LiteralRoundTripFixture): ) row = config.db.execute( - select([ - date_table.c.date_data, - ]) - ).first() + select([ + date_table.c.date_data, + ]) + ).first() compare = self.compare or self.data eq_(row, @@ -250,10 +252,10 @@ class _DateFixture(_LiteralRoundTripFixture): ) row = config.db.execute( - select([ - date_table.c.date_data, - ]) - ).first() + select([ + date_table.c.date_data, + ]) + ).first() eq_(row, (None,)) @testing.requires.datetime_literals @@ -262,7 +264,6 @@ class _DateFixture(_LiteralRoundTripFixture): self._literal_round_trip(self.datatype, [self.data], [compare]) - class DateTimeTest(_DateFixture, fixtures.TablesTest): __requires__ = 'datetime', __backend__ = True @@ -322,19 +323,22 @@ class DateHistoricTest(_DateFixture, fixtures.TablesTest): class IntegerTest(_LiteralRoundTripFixture, fixtures.TestBase): __backend__ = True + def test_literal(self): self._literal_round_trip(Integer, [5], [5]) + class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): __backend__ = True @testing.emits_warning(r".*does \*not\* support Decimal objects natively") @testing.provide_metadata - def _do_test(self, type_, input_, output, filter_=None, check_scale=False): + def _do_test(self, type_, input_, output, + filter_=None, check_scale=False): metadata = self.metadata t = Table('t', metadata, Column('x', type_)) t.create() - t.insert().execute([{'x':x} for x in input_]) + t.insert().execute([{'x': x} for x in input_]) result = set([row[0] for row in t.select().execute()]) output = set(output) @@ -348,7 +352,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): [str(x) for x in output], ) - @testing.emits_warning(r".*does \*not\* support Decimal objects natively") def test_render_literal_numeric(self): self._literal_round_trip( @@ -369,17 +372,16 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): self._literal_round_trip( Float(4), [15.7563, decimal.Decimal("15.7563")], - [15.7563,], + [15.7563, ], filter_=lambda n: n is not None and round(n, 5) or None ) - @testing.requires.precision_generic_float_type def test_float_custom_scale(self): self._do_test( Float(None, decimal_return_scale=7, asdecimal=True), [15.7563827, decimal.Decimal("15.7563827")], - [decimal.Decimal("15.7563827"),], + [decimal.Decimal("15.7563827"), ], check_scale=True ) @@ -421,7 +423,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): [decimal.Decimal("15.7563"), None], ) - def test_float_as_float(self): self._do_test( Float(precision=8), @@ -430,7 +431,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): filter_=lambda n: n is not None and round(n, 5) or None ) - @testing.requires.precision_numerics_general def test_precision_decimal(self): numbers = set([ @@ -445,7 +445,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): numbers, ) - @testing.requires.precision_numerics_enotation_large def test_enotation_decimal(self): """test exceedingly small decimals. @@ -475,7 +474,6 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): numbers ) - @testing.requires.precision_numerics_enotation_large def test_enotation_decimal_large(self): """test exceedingly large decimals. @@ -526,10 +524,10 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('boolean_table', metadata, - Column('id', Integer, primary_key=True, autoincrement=False), - Column('value', Boolean), - Column('unconstrained_value', Boolean(create_constraint=False)), - ) + Column('id', Integer, primary_key=True, autoincrement=False), + Column('value', Boolean), + Column('unconstrained_value', Boolean(create_constraint=False)), + ) def test_render_literal_bool(self): self._literal_round_trip( @@ -551,11 +549,11 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest): ) row = config.db.execute( - select([ - boolean_table.c.value, - boolean_table.c.unconstrained_value - ]) - ).first() + select([ + boolean_table.c.value, + boolean_table.c.unconstrained_value + ]) + ).first() eq_( row, @@ -576,11 +574,11 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest): ) row = config.db.execute( - select([ - boolean_table.c.value, - boolean_table.c.unconstrained_value - ]) - ).first() + select([ + boolean_table.c.value, + boolean_table.c.unconstrained_value + ]) + ).first() eq_( row, @@ -588,11 +586,9 @@ class BooleanTest(_LiteralRoundTripFixture, fixtures.TablesTest): ) - - __all__ = ('UnicodeVarcharTest', 'UnicodeTextTest', - 'DateTest', 'DateTimeTest', 'TextTest', - 'NumericTest', 'IntegerTest', - 'DateTimeHistoricTest', 'DateTimeCoercedToDateTimeTest', - 'TimeMicrosecondsTest', 'TimeTest', 'DateTimeMicrosecondsTest', - 'DateHistoricTest', 'StringTest', 'BooleanTest') + 'DateTest', 'DateTimeTest', 'TextTest', + 'NumericTest', 'IntegerTest', + 'DateTimeHistoricTest', 'DateTimeCoercedToDateTimeTest', + 'TimeMicrosecondsTest', 'TimeTest', 'DateTimeMicrosecondsTest', + 'DateHistoricTest', 'StringTest', 'BooleanTest') diff --git a/lib/sqlalchemy/testing/suite/test_update_delete.py b/lib/sqlalchemy/testing/suite/test_update_delete.py index 88dc95355..e4c61e74a 100644 --- a/lib/sqlalchemy/testing/suite/test_update_delete.py +++ b/lib/sqlalchemy/testing/suite/test_update_delete.py @@ -12,18 +12,18 @@ class SimpleUpdateDeleteTest(fixtures.TablesTest): @classmethod def define_tables(cls, metadata): Table('plain_pk', metadata, - Column('id', Integer, primary_key=True), - Column('data', String(50)) - ) + Column('id', Integer, primary_key=True), + Column('data', String(50)) + ) @classmethod def insert_data(cls): config.db.execute( cls.tables.plain_pk.insert(), [ - {"id":1, "data":"d1"}, - {"id":2, "data":"d2"}, - {"id":3, "data":"d3"}, + {"id": 1, "data": "d1"}, + {"id": 2, "data": "d2"}, + {"id": 3, "data": "d3"}, ] ) |