当前位置: 首页>>代码示例>>Python>>正文


Python testing.against方法代码示例

本文整理汇总了Python中sqlalchemy.testing.against方法的典型用法代码示例。如果您正苦于以下问题:Python testing.against方法的具体用法?Python testing.against怎么用?Python testing.against使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.testing的用法示例。


在下文中一共展示了testing.against方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_reflect_unicode_no_nvarchar

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_reflect_unicode_no_nvarchar(self):
        metadata = self.metadata
        Table("tnv", metadata, Column("data", sqltypes.Unicode(255)))
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.data.type, sqltypes.VARCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleString,
            )

        data = u("m’a réveillé.")
        t2.insert().execute(data=data)
        res = t2.select().execute().first()["data"]
        eq_(res, data)
        assert isinstance(res, util.text_type) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_types.py

示例2: define_tables

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def define_tables(cls, metadata):
        # the actual function isn't reflected yet
        dv = Table(
            "data_values",
            metadata,
            Column("modulus", Integer, nullable=False),
            Column("data", String(30)),
            Column("q", Integer),
            postgresql_partition_by="range(modulus)",
        )

        # looks like this is reflected prior to #4237
        sa.event.listen(
            dv,
            "after_create",
            sa.DDL(
                "CREATE TABLE data_values_4_10 PARTITION OF data_values "
                "FOR VALUES FROM (4) TO (10)"
            ),
        )

        if testing.against("postgresql >= 11"):
            Index("my_index", dv.c.q) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_reflection.py

示例3: test_col_w_optional_sequence_non_autoinc_no_firing

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_col_w_optional_sequence_non_autoinc_no_firing(
        self, dataset_no_autoinc, connection
    ):
        """this is testing that a Table which includes a Sequence, when
        run against a DB that does not support sequences, the Sequence
        does not get in the way.

        """
        dataset_no_autoinc.c.set_id.default.optional = True

        connection.execute(dataset_no_autoinc.insert())
        eq_(
            connection.scalar(
                select([func.count("*")]).select_from(dataset_no_autoinc)
            ),
            1,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_defaults.py

示例4: test_int_default_none_on_insert

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_int_default_none_on_insert(self, connection):
        metadata = self.metadata
        t = Table(
            "x",
            metadata,
            Column("y", Integer, server_default="5", primary_key=True),
            Column("data", String(10)),
            implicit_returning=False,
        )
        assert t._autoincrement_column is None
        metadata.create_all(connection)
        r = connection.execute(t.insert(), dict(data="data"))
        eq_(r.inserted_primary_key, (None,))
        if testing.against("sqlite"):
            eq_(list(connection.execute(t.select())), [(1, "data")])
        else:
            eq_(list(connection.execute(t.select())), [(5, "data")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_defaults.py

示例5: test_int_default_none_on_insert_reflected

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_int_default_none_on_insert_reflected(self, connection):
        metadata = self.metadata
        Table(
            "x",
            metadata,
            Column("y", Integer, server_default="5", primary_key=True),
            Column("data", String(10)),
            implicit_returning=False,
        )
        metadata.create_all(connection)

        m2 = MetaData()
        t2 = Table("x", m2, autoload_with=connection, implicit_returning=False)

        r = connection.execute(t2.insert(), dict(data="data"))
        eq_(r.inserted_primary_key, (None,))
        if testing.against("sqlite"):
            eq_(list(connection.execute(t2.select())), [(1, "data")])
        else:
            eq_(list(connection.execute(t2.select())), [(5, "data")]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_defaults.py

示例6: test_bind_in

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_bind_in(self, connection):
        """test calling IN against a bind parameter.

        this isn't allowed on several platforms since we
        generate ? = ?.

        """

        connection.execute(users.insert(), user_id=7, user_name="jack")
        connection.execute(users.insert(), user_id=8, user_name="fred")
        connection.execute(users.insert(), user_id=9, user_name=None)

        u = bindparam("search_key", type_=String)

        s = users.select(not_(u.in_([])))
        r = connection.execute(s, search_key="john").fetchall()
        assert len(r) == 3
        r = connection.execute(s, search_key=None).fetchall()
        assert len(r) == 3 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_query.py

示例7: test_empty_in_filtering_static

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_empty_in_filtering_static(self, connection):
        """test the behavior of the in_() function when
        comparing against an empty collection, specifically
        that a proper boolean value is generated.

        """

        connection.execute(
            users.insert(),
            [
                {"user_id": 7, "user_name": "jack"},
                {"user_id": 8, "user_name": "ed"},
                {"user_id": 9, "user_name": None},
            ],
        )

        s = users.select(users.c.user_name.in_([]) == True)  # noqa
        r = connection.execute(s).fetchall()
        assert len(r) == 0
        s = users.select(users.c.user_name.in_([]) == False)  # noqa
        r = connection.execute(s).fetchall()
        assert len(r) == 3
        s = users.select(users.c.user_name.in_([]) == None)  # noqa
        r = connection.execute(s).fetchall()
        assert len(r) == 0 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_query.py

示例8: test_close_transaction_on_commit_fail

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_close_transaction_on_commit_fail(self):
        T2, t1 = self.classes.T2, self.tables.t1

        session = create_session(autocommit=True)

        # with a deferred constraint, this fails at COMMIT time instead
        # of at INSERT time.
        session.add(T2(t1_id=123))

        try:
            session.flush()
            assert False
        except Exception:
            # Flush needs to rollback also when commit fails
            assert session.transaction is None

        # todo: on 8.3 at least, the failed commit seems to close the cursor?
        # needs investigation.  leaving in the DDL above now to help verify
        # that the new deferrable support on FK isn't involved in this issue.
        if testing.against("postgresql"):
            t1.bind.engine.dispose() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_unitofwork.py

示例9: define_tables

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def define_tables(cls, metadata):
        if testing.against("oracle"):
            fk_args = dict(deferrable=True, initially="deferred")
        elif testing.against("mysql"):
            fk_args = {}
        else:
            fk_args = dict(onupdate="cascade")

        Table(
            "users",
            metadata,
            Column(
                "id", Integer, primary_key=True, test_needs_autoincrement=True
            ),
        )
        Table(
            "addresses",
            metadata,
            Column(
                "id", Integer, primary_key=True, test_needs_autoincrement=True
            ),
            Column("user_id", Integer, ForeignKey("users.id", **fk_args)),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_hasparent.py

示例10: define_temp_tables

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def define_temp_tables(cls, metadata):
        # cheat a bit, we should fix this with some dialect-level
        # temp table fixture
        if testing.against("oracle"):
            kw = {
                'prefixes': ["GLOBAL TEMPORARY"],
                'oracle_on_commit': 'PRESERVE ROWS'
            }
        else:
            kw = {
                'prefixes': ["TEMPORARY"],
            }

        user_tmp = Table(
            "user_tmp", metadata,
            Column("id", sa.INT, primary_key=True),
            Column('name', sa.VARCHAR(50)),
            Column('foo', sa.INT),
            sa.UniqueConstraint('name', name='user_tmp_uq'),
            sa.Index("user_tmp_ix", "foo"),
            **kw
        )
        if testing.requires.view_reflection.enabled and \
                testing.requires.temporary_views.enabled:
            event.listen(
                user_tmp, "after_create",
                DDL("create temporary view user_tmp_v as "
                    "select * from user_tmp")
            )
            event.listen(
                user_tmp, "before_drop",
                DDL("drop view user_tmp_v")
            ) 
开发者ID:jpush,项目名称:jbox,代码行数:35,代码来源:test_reflection.py

示例11: define_temp_tables

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def define_temp_tables(cls, metadata):
        # the definition of temporary tables in the temporary table tests needs to be overwritten,
        # because similar to oracle, in HANA one needs to mention GLOBAL or LOCAL in the temporary table definition

        if testing.against("hana"):
            kw = {
                'prefixes': ["GLOBAL TEMPORARY"],
            }
        else:
            kw = {
                'prefixes': ["TEMPORARY"],
            }

        user_tmp = Table(
            "user_tmp", metadata,
            Column("id", sa.INT, primary_key=True),
            Column('name', sa.VARCHAR(50)),
            Column('foo', sa.INT),
            sa.UniqueConstraint('name', name='user_tmp_uq'),
            sa.Index("user_tmp_ix", "foo"),
            **kw
        )
        if testing.requires.view_reflection.enabled and \
                testing.requires.temporary_views.enabled:
            event.listen(
                user_tmp, "after_create",
                DDL("create temporary view user_tmp_v as "
                    "select * from user_tmp")
            )
            event.listen(
                user_tmp, "before_drop",
                DDL("drop view user_tmp_v")
            ) 
开发者ID:SAP,项目名称:sqlalchemy-hana,代码行数:35,代码来源:test_suite.py

示例12: test_include_columns

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_include_columns(self):
        meta = self.metadata
        foo = Table(
            "foo",
            meta,
            *[Column(n, sa.String(30)) for n in ["a", "b", "c", "d", "e", "f"]]
        )
        meta.create_all()
        meta2 = MetaData(testing.db)
        foo = Table(
            "foo", meta2, autoload=True, include_columns=["b", "f", "e"]
        )
        # test that cols come back in original order
        eq_([c.name for c in foo.c], ["b", "e", "f"])
        for c in ("b", "f", "e"):
            assert c in foo.c
        for c in ("a", "c", "d"):
            assert c not in foo.c

        # test against a table which is already reflected
        meta3 = MetaData(testing.db)
        foo = Table("foo", meta3, autoload=True)

        foo = Table(
            "foo", meta3, include_columns=["b", "f", "e"], extend_existing=True
        )
        eq_([c.name for c in foo.c], ["b", "e", "f"])
        for c in ("b", "f", "e"):
            assert c in foo.c
        for c in ("a", "c", "d"):
            assert c not in foo.c 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:33,代码来源:test_reflection.py

示例13: test_explicit_default_schema_metadata

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_explicit_default_schema_metadata(self):
        engine = testing.db

        if testing.against("sqlite"):
            # Works for CREATE TABLE main.foo, SELECT FROM main.foo, etc.,
            # but fails on:
            #   FOREIGN KEY(col2) REFERENCES main.table1 (col1)
            schema = "main"
        else:
            schema = engine.dialect.default_schema_name

        assert bool(schema)

        metadata = MetaData(engine, schema=schema)
        Table(
            "table1",
            metadata,
            Column("col1", sa.Integer, primary_key=True),
            test_needs_fk=True,
        )
        Table(
            "table2",
            metadata,
            Column("col1", sa.Integer, primary_key=True),
            Column("col2", sa.Integer, sa.ForeignKey("table1.col1")),
            test_needs_fk=True,
        )
        try:
            metadata.create_all()
            metadata.create_all(checkfirst=True)
            assert len(metadata.tables) == 2
            metadata.clear()

            Table("table1", metadata, autoload=True)
            Table("table2", metadata, autoload=True)
            assert len(metadata.tables) == 2
        finally:
            metadata.drop_all() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:40,代码来源:test_reflection.py

示例14: test_many_discarded_relationships

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_many_discarded_relationships(self):
        """a use case that really isn't supported, nonetheless we can
        guard against memleaks here so why not"""

        m1 = MetaData()
        t1 = Table("t1", m1, Column("id", Integer, primary_key=True))
        t2 = Table(
            "t2",
            m1,
            Column("id", Integer, primary_key=True),
            Column("t1id", ForeignKey("t1.id")),
        )

        class T1(object):
            pass

        t1_mapper = mapper(T1, t1)

        @testing.emits_warning()
        @profile_memory()
        def go():
            class T2(object):
                pass

            t2_mapper = mapper(T2, t2)
            t1_mapper.add_property("bar", relationship(t2_mapper))
            s1 = Session()
            # this causes the path_registry to be invoked
            s1.query(t1_mapper)._compile_context()

        go()

    # fails on newer versions of pysqlite due to unusual memory behavior
    # in pysqlite itself. background at:
    # http://thread.gmane.org/gmane.comp.python.db.pysqlite.user/2290 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:37,代码来源:test_memusage.py

示例15: test_literal_round_trip

# 需要导入模块: from sqlalchemy import testing [as 别名]
# 或者: from sqlalchemy.testing import against [as 别名]
def test_literal_round_trip(self, connection):
        # in particular, this tests that the array index
        # operator against the function is handled by PG; with some
        # array functions it requires outer parenthezisation on the left and
        # we may not be doing that here
        expr = hstore(
            postgresql.array(["1", "2"]), postgresql.array(["3", None])
        )["1"]
        eq_(connection.scalar(select([expr])), "3") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:11,代码来源:test_types.py


注:本文中的sqlalchemy.testing.against方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。