def test_table_useexisting(self): meta = self.metadata Table("t", meta, Column("x", Integer)) meta.create_all() with testing.expect_deprecated( "The Table.useexisting parameter is deprecated and " "will be removed in a future release." ): Table("t", meta, useexisting=True, autoload_with=testing.db) with testing.expect_deprecated( "The Table.useexisting parameter is deprecated and " "will be removed in a future release." ): assert_raises_message( exc.ArgumentError, "useexisting is synonymous with extend_existing.", Table, "t", meta, useexisting=True, extend_existing=True, autoload_with=testing.db, )
def test_deprecated_append_ddl_listener_table(self): metadata, users, engine = self.metadata, self.users, self.engine canary = [] with testing.expect_deprecated(".* is deprecated .*"): users.append_ddl_listener( "before-create", lambda e, t, b: canary.append("mxyzptlk") ) with testing.expect_deprecated(".* is deprecated .*"): users.append_ddl_listener( "after-create", lambda e, t, b: canary.append("klptzyxm") ) with testing.expect_deprecated(".* is deprecated .*"): users.append_ddl_listener( "before-drop", lambda e, t, b: canary.append("xyzzy") ) with testing.expect_deprecated(".* is deprecated .*"): users.append_ddl_listener( "after-drop", lambda e, t, b: canary.append("fnord") ) metadata.create_all() assert "mxyzptlk" in canary assert "klptzyxm" in canary assert "xyzzy" not in canary assert "fnord" not in canary del engine.mock[:] canary[:] = [] metadata.drop_all() assert "mxyzptlk" not in canary assert "klptzyxm" not in canary assert "xyzzy" in canary assert "fnord" in canary
def test_scalar_select(self): with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): self.assert_compile( func.coalesce(select([table1.c.myid])), "coalesce((SELECT mytable.myid FROM mytable))", ) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): s = select([table1.c.myid]).alias() self.assert_compile( select([table1.c.myid]).where(table1.c.myid == s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid = (SELECT mytable.myid FROM " "mytable)", ) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): self.assert_compile( select([table1.c.myid]).where(s > table1.c.myid), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid < (SELECT mytable.myid FROM " "mytable)", ) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): s = select([table1.c.myid]).alias() self.assert_compile( select([table1.c.myid]).where(table1.c.myid == s), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid = (SELECT mytable.myid FROM " "mytable)", ) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): self.assert_compile( select([table1.c.myid]).where(s > table1.c.myid), "SELECT mytable.myid FROM mytable WHERE " "mytable.myid < (SELECT mytable.myid FROM " "mytable)", )
def test_legacy_typemap(self): table1 = table( "mytable", column("myid", Integer), column("name", String), column("description", String), ) with testing.expect_deprecated( "The text.typemap parameter is deprecated" ): t = text( "select id, name from user", typemap=dict(id=Integer, name=String), ) stmt = select([table1.c.myid]).select_from( table1.join(t, table1.c.myid == t.c.id) ) compiled = stmt.compile() eq_( compiled._create_result_map(), { "myid": ( "myid", (table1.c.myid, "myid", "myid"), table1.c.myid.type, ) }, )
def test_set_parse(self): with testing.expect_deprecated("Manually quoting SET value literals"): set_table = Table( "mysql_set", self.metadata, Column("e1", mysql.SET("'a'")), Column("e2", mysql.SET("''")), Column("e3", mysql.SET("a")), Column("e4", mysql.SET("")), Column("e5", mysql.SET("'a'", "''")), Column("e6", mysql.SET("''", "'a'")), Column("e7", mysql.SET("''", "'''a'''", "'b''b'", "''''")), ) for col in set_table.c: self.assert_(repr(col)) set_table.create() # don't want any warnings on reflection reflected = Table("mysql_set", MetaData(testing.db), autoload=True) for t in set_table, reflected: eq_(t.c.e1.type.values, ("a",)) eq_(t.c.e2.type.values, ("",)) eq_(t.c.e3.type.values, ("a",)) eq_(t.c.e4.type.values, ("",)) eq_(t.c.e5.type.values, ("a", "")) eq_(t.c.e6.type.values, ("", "a")) eq_(t.c.e7.type.values, ("", "'a'", "b'b", "'"))
def test_enum_parse(self): with testing.expect_deprecated("Manually quoting ENUM value literals"): enum_table = Table( "mysql_enum", self.metadata, Column("e1", mysql.ENUM("'a'")), Column("e2", mysql.ENUM("''")), Column("e3", mysql.ENUM("a")), Column("e4", mysql.ENUM("")), Column("e5", mysql.ENUM("'a'", "''")), Column("e6", mysql.ENUM("''", "'a'")), Column("e7", mysql.ENUM("''", "'''a'''", "'b''b'", "''''")), ) for col in enum_table.c: self.assert_(repr(col)) enum_table.create() reflected = Table("mysql_enum", MetaData(testing.db), autoload=True) for t in enum_table, reflected: eq_(t.c.e1.type.enums, ("a",)) eq_(t.c.e2.type.enums, ("",)) eq_(t.c.e3.type.enums, ("a",)) eq_(t.c.e4.type.enums, ("",)) eq_(t.c.e5.type.enums, ("a", "")) eq_(t.c.e6.type.enums, ("", "a")) eq_(t.c.e7.type.enums, ("", "'a'", "b'b", "'"))
def test_set_parse(self): with testing.expect_deprecated('Manually quoting SET value literals'): set_table = Table( 'mysql_set', self.metadata, Column('e1', mysql.SET("'a'")), Column('e2', mysql.SET("''", retrieve_as_bitwise=True)), Column('e3', mysql.SET('a')), Column('e4', mysql.SET('', retrieve_as_bitwise=True)), Column('e5', mysql.SET("'a'", "''", retrieve_as_bitwise=True)), Column('e6', mysql.SET("''", "'a'", retrieve_as_bitwise=True)), Column('e7', mysql.SET( "''", "'''a'''", "'b''b'", "''''", retrieve_as_bitwise=True))) for col in set_table.c: self.assert_(repr(col)) set_table.create() # don't want any warnings on reflection reflected = Table('mysql_set', MetaData(testing.db), autoload=True) for t in set_table, reflected: eq_(t.c.e1.type.values, ("a",)) eq_(t.c.e2.type.values, ("",)) eq_(t.c.e3.type.values, ("a",)) eq_(t.c.e4.type.values, ("",)) eq_(t.c.e5.type.values, ("a", "")) eq_(t.c.e6.type.values, ("", "a")) eq_(t.c.e7.type.values, ("", "'a'", "b'b", "'"))
def test_deprecated_dialect_name_still_loads(self): dialects.registry.clear() with expect_deprecated( "The 'postgres' dialect name " "has been renamed to 'postgresql'" ): dialect = url.URL("postgres").get_dialect() is_(dialect, postgresql.dialect)
def test_enum_parse(self): with testing.expect_deprecated('Manually quoting ENUM value literals'): enum_table = Table( 'mysql_enum', self.metadata, Column('e1', mysql.ENUM("'a'")), Column('e2', mysql.ENUM("''")), Column('e3', mysql.ENUM('a')), Column('e4', mysql.ENUM('')), Column('e5', mysql.ENUM("'a'", "''")), Column('e6', mysql.ENUM("''", "'a'")), Column('e7', mysql.ENUM("''", "'''a'''", "'b''b'", "''''"))) for col in enum_table.c: self.assert_(repr(col)) enum_table.create() reflected = Table('mysql_enum', MetaData(testing.db), autoload=True) for t in enum_table, reflected: eq_(t.c.e1.type.enums, ["a"]) eq_(t.c.e2.type.enums, [""]) eq_(t.c.e3.type.enums, ["a"]) eq_(t.c.e4.type.enums, [""]) eq_(t.c.e5.type.enums, ["a", ""]) eq_(t.c.e6.type.enums, ["", "a"]) eq_(t.c.e7.type.enums, ["", "'a'", "b'b", "'"])
def test_as_scalar(self): with testing.expect_deprecated( r"The SelectBase.as_scalar\(\) method is deprecated and " "will be removed in a future release." ): stmt = select([table1.c.myid]).as_scalar() is_true(stmt.compare(select([table1.c.myid]).scalar_subquery()))
def test_enum(self): """Exercise the ENUM type.""" with testing.expect_deprecated('Manually quoting ENUM value literals'): e1, e2 = mysql.ENUM("'a'", "'b'"), mysql.ENUM("'a'", "'b'") e3 = mysql.ENUM("'a'", "'b'", strict=True) e4 = mysql.ENUM("'a'", "'b'", strict=True) enum_table = Table('mysql_enum', self.metadata, Column('e1', e1), Column('e2', e2, nullable=False), Column('e2generic', Enum("a", "b"), nullable=False), Column('e3', e3), Column('e4', e4, nullable=False), Column('e5', mysql.ENUM("a", "b")), Column('e5generic', Enum("a", "b")), Column('e6', mysql.ENUM("'a'", "b")), ) eq_(colspec(enum_table.c.e1), "e1 ENUM('a','b')") eq_(colspec(enum_table.c.e2), "e2 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e2generic), "e2generic ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e3), "e3 ENUM('a','b')") eq_(colspec(enum_table.c.e4), "e4 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e5), "e5 ENUM('a','b')") eq_(colspec(enum_table.c.e5generic), "e5generic ENUM('a','b')") eq_(colspec(enum_table.c.e6), "e6 ENUM('''a''','b')") enum_table.create() assert_raises(exc.DBAPIError, enum_table.insert().execute, e1=None, e2=None, e3=None, e4=None) assert_raises(exc.StatementError, enum_table.insert().execute, e1='c', e2='c', e2generic='c', e3='c', e4='c', e5='c', e5generic='c', e6='c') enum_table.insert().execute() enum_table.insert().execute(e1='a', e2='a', e2generic='a', e3='a', e4='a', e5='a', e5generic='a', e6="'a'") enum_table.insert().execute(e1='b', e2='b', e2generic='b', e3='b', e4='b', e5='b', e5generic='b', e6='b') res = enum_table.select().execute().fetchall() expected = [(None, 'a', 'a', None, 'a', None, None, None), ('a', 'a', 'a', 'a', 'a', 'a', 'a', "'a'"), ('b', 'b', 'b', 'b', 'b', 'b', 'b', 'b')] eq_(res, expected)
def test_labeled_role(self): stmt = select([table1.c.myid]) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): coerced = coercions.expect(roles.LabeledColumnExprRole, stmt) is_true(coerced.compare(stmt.scalar_subquery().label(None))) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): coerced = coercions.expect( roles.LabeledColumnExprRole, stmt.alias() ) is_true(coerced.compare(stmt.scalar_subquery().label(None)))
def test_enum(self): """Exercise the ENUM type.""" with testing.expect_deprecated("Manually quoting ENUM value literals"): e1, e2 = mysql.ENUM("'a'", "'b'"), mysql.ENUM("'a'", "'b'") enum_table = Table( "mysql_enum", self.metadata, Column("e1", e1), Column("e2", e2, nullable=False), Column("e2generic", Enum("a", "b"), nullable=False), Column("e3", mysql.ENUM("'a'", "'b'", strict=True)), Column("e4", mysql.ENUM("'a'", "'b'", strict=True), nullable=False), Column("e5", mysql.ENUM("a", "b")), Column("e5generic", Enum("a", "b")), Column("e6", mysql.ENUM("'a'", "b")), ) eq_(colspec(enum_table.c.e1), "e1 ENUM('a','b')") eq_(colspec(enum_table.c.e2), "e2 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e2generic), "e2generic ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e3), "e3 ENUM('a','b')") eq_(colspec(enum_table.c.e4), "e4 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e5), "e5 ENUM('a','b')") eq_(colspec(enum_table.c.e5generic), "e5generic ENUM('a','b')") eq_(colspec(enum_table.c.e6), "e6 ENUM('''a''','b')") enum_table.create() assert_raises(exc.DBAPIError, enum_table.insert().execute, e1=None, e2=None, e3=None, e4=None) assert_raises( exc.StatementError, enum_table.insert().execute, e1="c", e2="c", e2generic="c", e3="c", e4="c", e5="c", e5generic="c", e6="c", ) enum_table.insert().execute() enum_table.insert().execute(e1="a", e2="a", e2generic="a", e3="a", e4="a", e5="a", e5generic="a", e6="'a'") enum_table.insert().execute(e1="b", e2="b", e2generic="b", e3="b", e4="b", e5="b", e5generic="b", e6="b") res = enum_table.select().execute().fetchall() expected = [ (None, "a", "a", None, "a", None, None, None), ("a", "a", "a", "a", "a", "a", "a", "'a'"), ("b", "b", "b", "b", "b", "b", "b", "b"), ] eq_(res, expected)
def test_threaded_deprecated_at_dialect_level(self): with testing.expect_deprecated( "The 'threaded' parameter to the cx_oracle dialect" ): dialect = cx_oracle.dialect(threaded=False) arg, kw = dialect.create_connect_args( url.make_url("oracle+cx_oracle://scott:tiger@dsn") ) eq_(kw["threaded"], False)
def setup_mappers(cls): foo = cls.tables.foo mapper(Foo, foo) with testing.expect_deprecated( "The mapper.non_primary parameter is deprecated" ): mapper( Foo, foo, non_primary=True, properties={"foo_bar": foo.c.data} )
def test_fromclause_subquery(self): stmt = select([table1.c.myid]) with testing.expect_deprecated( "Implicit coercion of SELECT and textual SELECT constructs " "into FROM clauses is deprecated" ): coerced = coercions.expect( roles.StrictFromClauseRole, stmt, allow_select=True ) is_true(coerced.compare(stmt.subquery()))
def test_filter_deprecated(self): cx = self.engine tbl = Table("t", MetaData(), Column("id", Integer)) target = cx.name assert DDL("")._should_execute_deprecated("x", tbl, cx) with testing.expect_deprecated(".* is deprecated .*"): assert DDL("", on=target)._should_execute_deprecated("x", tbl, cx) with testing.expect_deprecated(".* is deprecated .*"): assert not DDL("", on="bogus")._should_execute_deprecated( "x", tbl, cx ) with testing.expect_deprecated(".* is deprecated .*"): assert DDL( "", on=lambda d, x, y, z: True )._should_execute_deprecated("x", tbl, cx) with testing.expect_deprecated(".* is deprecated .*"): assert DDL( "", on=lambda d, x, y, z: z.engine.name != "bogus" )._should_execute_deprecated("x", tbl, cx)
def test_set(self): with testing.expect_deprecated('Manually quoting SET value literals'): e1, e2 = mysql.SET("'a'", "'b'"), mysql.SET("'a'", "'b'") e4 = mysql.SET("'a'", "b") e5 = mysql.SET("'a'", "'b'", quoting="quoted") set_table = Table('mysql_set', self.metadata, Column('e1', e1), Column('e2', e2, nullable=False), Column('e3', mysql.SET("a", "b")), Column('e4', e4), Column('e5', e5) ) eq_(colspec(set_table.c.e1), "e1 SET('a','b')") eq_(colspec(set_table.c.e2), "e2 SET('a','b') NOT NULL") eq_(colspec(set_table.c.e3), "e3 SET('a','b')") eq_(colspec(set_table.c.e4), "e4 SET('''a''','b')") eq_(colspec(set_table.c.e5), "e5 SET('a','b')") set_table.create() assert_raises(exc.DBAPIError, set_table.insert().execute, e1=None, e2=None, e3=None, e4=None) if testing.against("+oursql"): assert_raises(exc.StatementError, set_table.insert().execute, e1='c', e2='c', e3='c', e4='c') set_table.insert().execute(e1='a', e2='a', e3='a', e4="'a'", e5="a,b") set_table.insert().execute(e1='b', e2='b', e3='b', e4='b', e5="a,b") res = set_table.select().execute().fetchall() if not testing.against("+oursql"): # oursql receives this for first row: # (set(['']), set(['']), set(['']), set(['']), None), # but based on ...OS? MySQL version? not clear. # not worth testing. expected = [] expected.extend([ (set(['a']), set(['a']), set(['a']), set(["'a'"]), set(['a', 'b'])), (set(['b']), set(['b']), set(['b']), set(['b']), set(['a', 'b'])) ]) eq_(res, expected)
def test_append_listener(self): metadata, table, bind = self.metadata, self.table, self.bind def fn(*a): return None with testing.expect_deprecated(".* is deprecated .*"): table.append_ddl_listener("before-create", fn) with testing.expect_deprecated(".* is deprecated .*"): assert_raises( exc.InvalidRequestError, table.append_ddl_listener, "blah", fn ) with testing.expect_deprecated(".* is deprecated .*"): metadata.append_ddl_listener("before-create", fn) with testing.expect_deprecated(".* is deprecated .*"): assert_raises( exc.InvalidRequestError, metadata.append_ddl_listener, "blah", fn, )
def test_unknown_mode(self): t = table("t", column("c")) with testing.expect_deprecated( "The select.for_update parameter is deprecated and " "will be removed in a future release." ): assert_raises_message( exc.ArgumentError, "Unknown for_update argument: 'unknown_mode'", t.select, t.c.c == 7, for_update="unknown_mode", )
def test_column_roles(self): stmt = select([table1.c.myid]) for role in [ roles.WhereHavingRole, roles.ExpressionElementRole, roles.ByOfRole, roles.OrderByRole, # roles.LabeledColumnExprRole ]: with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): coerced = coercions.expect(role, stmt) is_true(coerced.compare(stmt.scalar_subquery())) with testing.expect_deprecated( "coercing SELECT object to scalar " "subquery in a column-expression context is deprecated" ): coerced = coercions.expect(role, stmt.alias()) is_true(coerced.compare(stmt.scalar_subquery()))
def _test_dialect_param_from_url(self, url_string, key, value): import cx_Oracle url_obj = url.make_url(url_string) dialect = cx_oracle.dialect(dbapi=cx_Oracle) with testing.expect_deprecated( "cx_oracle dialect option %r should" % key ): arg, kw = dialect.create_connect_args(url_obj) eq_(getattr(dialect, key), value) # test setting it on the dialect normally dialect = cx_oracle.dialect(dbapi=cx_Oracle, **{key: value}) eq_(getattr(dialect, key), value)
def test_sequence_ignore_nullability(self): metadata = MetaData() tbl = Table( "test", metadata, Column("id", Integer, Sequence("", start=5), nullable=True), ) with testing.expect_deprecated( "Use of Sequence with SQL Server in order to affect " ): self.assert_compile( schema.CreateTable(tbl), "CREATE TABLE test (id INTEGER NOT NULL IDENTITY(5,1))", )
def test_legacy_bindparam(self): with testing.expect_deprecated( "The text.bindparams parameter is deprecated" ): t = text( "select * from foo where lala=:bar and hoho=:whee", bindparams=[bindparam("bar", 4), bindparam("whee", 7)], ) self.assert_compile( t, "select * from foo where lala=:bar and hoho=:whee", checkparams={"bar": 4, "whee": 7}, )
def test_ident_preparer_force(self): preparer = testing.db.dialect.identifier_preparer preparer.quote("hi") with testing.expect_deprecated( "The IdentifierPreparer.quote.force parameter is deprecated" ): preparer.quote("hi", True) with testing.expect_deprecated( "The IdentifierPreparer.quote.force parameter is deprecated" ): preparer.quote("hi", False) preparer.quote_schema("hi") with testing.expect_deprecated( "The IdentifierPreparer.quote_schema.force parameter is deprecated" ): preparer.quote_schema("hi", True) with testing.expect_deprecated( "The IdentifierPreparer.quote_schema.force parameter is deprecated" ): preparer.quote_schema("hi", True)
def _set_fixture_one(self): with testing.expect_deprecated('Manually quoting SET value literals'): e1, e2 = mysql.SET("'a'", "'b'"), mysql.SET("'a'", "'b'") e4 = mysql.SET("'a'", "b") e5 = mysql.SET("'a'", "'b'", quoting="quoted") set_table = Table( 'mysql_set', self.metadata, Column('e1', e1), Column('e2', e2, nullable=False), Column('e3', mysql.SET("a", "b")), Column('e4', e4), Column('e5', e5) ) return set_table
def test_sequence_start_0(self): metadata = MetaData() tbl = Table( "test", metadata, Column("id", Integer, Sequence("", 0), primary_key=True), ) with testing.expect_deprecated( "Use of Sequence with SQL Server in order to affect " ): self.assert_compile( schema.CreateTable(tbl), "CREATE TABLE test (id INTEGER NOT NULL IDENTITY(0,1), " "PRIMARY KEY (id))", )
def test_set(self): with testing.expect_deprecated("Manually quoting SET value literals"): e1, e2 = mysql.SET("'a'", "'b'"), mysql.SET("'a'", "'b'") set_table = Table( "mysql_set", self.metadata, Column("e1", e1), Column("e2", e2, nullable=False), Column("e3", mysql.SET("a", "b")), Column("e4", mysql.SET("'a'", "b")), Column("e5", mysql.SET("'a'", "'b'", quoting="quoted")), ) eq_(colspec(set_table.c.e1), "e1 SET('a','b')") eq_(colspec(set_table.c.e2), "e2 SET('a','b') NOT NULL") eq_(colspec(set_table.c.e3), "e3 SET('a','b')") eq_(colspec(set_table.c.e4), "e4 SET('''a''','b')") eq_(colspec(set_table.c.e5), "e5 SET('a','b')") set_table.create() assert_raises(exc.DBAPIError, set_table.insert().execute, e1=None, e2=None, e3=None, e4=None) if testing.against("+oursql"): assert_raises(exc.StatementError, set_table.insert().execute, e1="c", e2="c", e3="c", e4="c") set_table.insert().execute(e1="a", e2="a", e3="a", e4="'a'", e5="a,b") set_table.insert().execute(e1="b", e2="b", e3="b", e4="b", e5="a,b") res = set_table.select().execute().fetchall() if testing.against("+oursql"): expected = [ # 1st row with all c's, data truncated (set([""]), set([""]), set([""]), set([""]), None) ] else: expected = [] expected.extend( [ (set(["a"]), set(["a"]), set(["a"]), set(["'a'"]), set(["a", "b"])), (set(["b"]), set(["b"]), set(["b"]), set(["b"]), set(["a", "b"])), ] ) eq_(res, expected)
def _assert_legacy(self, leg, read=False, nowait=False): t = table("t", column("c")) with testing.expect_deprecated( "The select.for_update parameter is deprecated and " "will be removed in a future release." ): s1 = select([t], for_update=leg) if leg is False: assert s1._for_update_arg is None assert s1.for_update is None else: eq_(s1._for_update_arg.read, read) eq_(s1._for_update_arg.nowait, nowait) eq_(s1.for_update, leg)
def _set_fixture_one(self): with testing.expect_deprecated("Manually quoting SET value literals"): e1, e2 = mysql.SET("'a'", "'b'"), mysql.SET("'a'", "'b'") e4 = mysql.SET("'a'", "b") e5 = mysql.SET("'a'", "'b'", quoting="quoted") set_table = Table( "mysql_set", self.metadata, Column("e1", e1), Column("e2", e2, nullable=False), Column("e3", mysql.SET("a", "b")), Column("e4", e4), Column("e5", e5), ) return set_table
def test_select_for_update(self): with testing.expect_deprecated( "The select.for_update parameter is deprecated and " "will be removed in a future release."): select([column("x")], for_update=True)
def _c_deprecated(self): return testing.expect_deprecated( "The SelectBase.c and SelectBase.columns attributes are " "deprecated")
def test_engine_convert_unicode(self): with testing.expect_deprecated( "The create_engine.convert_unicode parameter and " "corresponding dialect-level"): create_engine("mysql://", convert_unicode=True, module=mock.Mock())
def test_column_collection_ordered(self): t = text("select a, b, c from foo").columns(column("a"), column("b"), column("c")) with testing.expect_deprecated( "The SelectBase.c and SelectBase.columns"): eq_(t.c.keys(), ["a", "b", "c"])
def expect_deprecated_opts(self): return expect_deprecated( "The psycopg2 use_batch_mode flag is superseded by " "executemany_mode='batch'" )
def test_string_convert_unicode(self): with testing.expect_deprecated( "The String.convert_unicode parameter is deprecated and " "will be removed in a future release."): String(convert_unicode=True)
def test_autocommit(self): with testing.expect_deprecated( "The text.autocommit parameter is deprecated"): t = text("select id, name from user", autocommit=True)
def test_transaction_engine_fn_commit(self): fn = self._trans_fn() with testing.expect_deprecated(r"The Engine.transaction\(\) method"): testing.db.transaction(fn, 5, value=8) self._assert_fn(5, value=8)
def test_enum(self): """Exercise the ENUM type.""" with testing.expect_deprecated('Manually quoting ENUM value literals'): e1, e2 = mysql.ENUM("'a'", "'b'"), mysql.ENUM("'a'", "'b'") e3 = mysql.ENUM("'a'", "'b'", strict=True) e4 = mysql.ENUM("'a'", "'b'", strict=True) enum_table = Table( 'mysql_enum', self.metadata, Column('e1', e1), Column('e2', e2, nullable=False), Column('e2generic', Enum("a", "b"), nullable=False), Column('e3', e3), Column('e4', e4, nullable=False), Column('e5', mysql.ENUM("a", "b")), Column('e5generic', Enum("a", "b")), Column('e6', mysql.ENUM("'a'", "b")), ) eq_(colspec(enum_table.c.e1), "e1 ENUM('a','b')") eq_(colspec(enum_table.c.e2), "e2 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e2generic), "e2generic ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e3), "e3 ENUM('a','b')") eq_(colspec(enum_table.c.e4), "e4 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e5), "e5 ENUM('a','b')") eq_(colspec(enum_table.c.e5generic), "e5generic ENUM('a','b')") eq_(colspec(enum_table.c.e6), "e6 ENUM('''a''','b')") enum_table.create() assert_raises(exc.DBAPIError, enum_table.insert().execute, e1=None, e2=None, e3=None, e4=None) assert_raises(exc.StatementError, enum_table.insert().execute, e1='c', e2='c', e2generic='c', e3='c', e4='c', e5='c', e5generic='c', e6='c') enum_table.insert().execute() enum_table.insert().execute(e1='a', e2='a', e2generic='a', e3='a', e4='a', e5='a', e5generic='a', e6="'a'") enum_table.insert().execute(e1='b', e2='b', e2generic='b', e3='b', e4='b', e5='b', e5generic='b', e6='b') res = enum_table.select().execute().fetchall() expected = [(None, 'a', 'a', None, 'a', None, None, None), ('a', 'a', 'a', 'a', 'a', 'a', 'a', "'a'"), ('b', 'b', 'b', 'b', 'b', 'b', 'b', 'b')] eq_(res, expected)
def test_warn_deprecated_limited_text(self): with expect_deprecated("foo has been deprecated"): warn_deprecated_limited("%s has been deprecated [%d]", ("foo", 1), "1.3")
def test_deprecated_dialect_name_still_loads(self): with expect_deprecated("The 'postgres' dialect name " "has been renamed to 'postgresql'"): dialect = url.URL("postgres").get_dialect() is_(dialect, postgresql.dialect)
def test_select_autocommit(self): with testing.expect_deprecated( "The select.autocommit parameter is deprecated and " "will be removed in a future release."): select([column("x")], autocommit=True)
def test_enum(self): """Exercise the ENUM type.""" with testing.expect_deprecated("Manually quoting ENUM value literals"): e1, e2 = mysql.ENUM("'a'", "'b'"), mysql.ENUM("'a'", "'b'") e3 = mysql.ENUM("'a'", "'b'", strict=True) e4 = mysql.ENUM("'a'", "'b'", strict=True) enum_table = Table( "mysql_enum", self.metadata, Column("e1", e1), Column("e2", e2, nullable=False), Column( "e2generic", Enum("a", "b", validate_strings=True), nullable=False, ), Column("e3", e3), Column("e4", e4, nullable=False), Column("e5", mysql.ENUM("a", "b")), Column("e5generic", Enum("a", "b")), Column("e6", mysql.ENUM("'a'", "b")), Column( "e7", mysql.ENUM( EnumSetTest.SomeEnum, values_callable=EnumSetTest.get_enum_string_values, ), ), Column("e8", mysql.ENUM(EnumSetTest.SomeEnum)), ) eq_(colspec(enum_table.c.e1), "e1 ENUM('a','b')") eq_(colspec(enum_table.c.e2), "e2 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e2generic), "e2generic ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e3), "e3 ENUM('a','b')") eq_(colspec(enum_table.c.e4), "e4 ENUM('a','b') NOT NULL") eq_(colspec(enum_table.c.e5), "e5 ENUM('a','b')") eq_(colspec(enum_table.c.e5generic), "e5generic ENUM('a','b')") eq_(colspec(enum_table.c.e6), "e6 ENUM('''a''','b')") eq_(colspec(enum_table.c.e7), "e7 ENUM('1','2','3','a','b')") eq_( colspec(enum_table.c.e8), "e8 ENUM('one','two','three','AMember','BMember')", ) enum_table.create() assert_raises( exc.DBAPIError, enum_table.insert().execute, e1=None, e2=None, e3=None, e4=None, ) assert enum_table.c.e2generic.type.validate_strings assert_raises( exc.StatementError, enum_table.insert().execute, e1="c", e2="c", e2generic="c", e3="c", e4="c", e5="c", e5generic="c", e6="c", e7="c", e8="c", ) enum_table.insert().execute() enum_table.insert().execute( e1="a", e2="a", e2generic="a", e3="a", e4="a", e5="a", e5generic="a", e6="'a'", e7="a", e8="AMember", ) enum_table.insert().execute( e1="b", e2="b", e2generic="b", e3="b", e4="b", e5="b", e5generic="b", e6="b", e7="b", e8="BMember", ) res = enum_table.select().execute().fetchall() expected = [ (None, "a", "a", None, "a", None, None, None, None, None), ( "a", "a", "a", "a", "a", "a", "a", "'a'", EnumSetTest.SomeEnum.AMember, EnumSetTest.SomeEnum.AMember, ), ( "b", "b", "b", "b", "b", "b", "b", "b", EnumSetTest.SomeEnum.BMember, EnumSetTest.SomeEnum.BMember, ), ] eq_(res, expected)
def test_transaction_connection_fn_rollback(self): fn = self._trans_rollback_fn() with testing.db.connect() as conn: with testing.expect_deprecated(r""): assert_raises(Exception, conn.transaction, fn, 5, value=8) self._assert_no_data()
def test_legacy_schema_flag(self, cfg, expected): with testing.expect_deprecated("The legacy_schema_aliasing parameter"): e = engine_from_config( cfg, module=Mock(version="MS SQL Server 11.0.92")) is_(e.dialect.legacy_schema_aliasing, expected)
def test_without_default_polymorphic(self): Employee, Engineer, Manager = self.classes( "Employee", "Engineer", "Manager" ) (Hacker,) = self.classes("Hacker") (employees_table,) = self.tables("employees") engineers_table, managers_table = self.tables("engineers", "managers") (hackers_table,) = self.tables("hackers") pjoin = polymorphic_union( { "employee": employees_table, "manager": managers_table, "engineer": engineers_table, "hacker": hackers_table, }, "type", "pjoin", ) pjoin2 = polymorphic_union( {"engineer": engineers_table, "hacker": hackers_table}, "type", "pjoin2", ) employee_mapper = self.mapper_registry.map_imperatively( Employee, employees_table, polymorphic_identity="employee" ) self.mapper_registry.map_imperatively( Manager, managers_table, inherits=employee_mapper, concrete=True, polymorphic_identity="manager", ) engineer_mapper = self.mapper_registry.map_imperatively( Engineer, engineers_table, inherits=employee_mapper, concrete=True, polymorphic_identity="engineer", ) self.mapper_registry.map_imperatively( Hacker, hackers_table, inherits=engineer_mapper, concrete=True, polymorphic_identity="hacker", ) session = fixture_session() jdoe = Employee("Jdoe") tom = Manager("Tom", "knows how to manage things") jerry = Engineer("Jerry", "knows how to program") hacker = Hacker("Kurt", "Badass", "knows how to hack") session.add_all((jdoe, tom, jerry, hacker)) session.flush() with expect_deprecated_20(with_polymorphic_dep): eq_( len( session.connection() .execute( session.query(Employee) .with_polymorphic("*", pjoin, pjoin.c.type) .statement ) .fetchall() ), 4, ) eq_(session.get(Employee, jdoe.employee_id), jdoe) eq_(session.get(Engineer, jerry.employee_id), jerry) with expect_deprecated_20(with_polymorphic_dep): eq_( set( [ repr(x) for x in session.query(Employee).with_polymorphic( "*", pjoin, pjoin.c.type ) ] ), set( [ "Employee Jdoe", "Engineer Jerry knows how to program", "Manager Tom knows how to manage things", "Hacker Kurt 'Badass' knows how to hack", ] ), ) eq_( set([repr(x) for x in session.query(Manager)]), set(["Manager Tom knows how to manage things"]), ) with expect_deprecated_20(with_polymorphic_dep): eq_( set( [ repr(x) for x in session.query(Engineer).with_polymorphic( "*", pjoin2, pjoin2.c.type ) ] ), set( [ "Engineer Jerry knows how to program", "Hacker Kurt 'Badass' knows how to hack", ] ), ) eq_( set([repr(x) for x in session.query(Hacker)]), set(["Hacker Kurt 'Badass' knows how to hack"]), ) # test adaption of the column by wrapping the query in a # subquery with testing.expect_deprecated( r"The Query.from_self\(\) method", with_polymorphic_dep ): eq_( len( session.connection() .execute( session.query(Engineer) .with_polymorphic("*", pjoin2, pjoin2.c.type) .from_self() .statement ) .fetchall() ), 2, ) with testing.expect_deprecated( r"The Query.from_self\(\) method", with_polymorphic_dep ): eq_( set( [ repr(x) for x in session.query(Engineer) .with_polymorphic("*", pjoin2, pjoin2.c.type) .from_self() ] ), set( [ "Engineer Jerry knows how to program", "Hacker Kurt 'Badass' knows how to hack", ] ), )
def _expect_deprecated(self, clsname, methname, newmeth): return testing.expect_deprecated( r"The %s.append_%s\(\) method is deprecated " r"and will be removed in a future release. Use the generative " r"method %s.%s\(\)." % (clsname, methname, clsname, newmeth))