• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python testing.is_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy.testing.is_函数的典型用法代码示例。如果您正苦于以下问题:Python is_函数的具体用法?Python is_怎么用?Python is_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_no_instance_level_collections

    def test_no_instance_level_collections(self):
        @event.listens_for(self.Target, "event_one")
        def listen_one(x, y):
            pass

        t1 = self.Target()
        t2 = self.Target()
        t1.dispatch.event_one(5, 6)
        t2.dispatch.event_one(5, 6)
        is_(
            self.Target.dispatch._empty_listener_reg[self.Target]["event_one"],
            t1.dispatch.event_one,
        )

        @event.listens_for(t1, "event_one")
        def listen_two(x, y):
            pass

        is_not_(
            self.Target.dispatch._empty_listener_reg[self.Target]["event_one"],
            t1.dispatch.event_one,
        )
        is_(
            self.Target.dispatch._empty_listener_reg[self.Target]["event_one"],
            t2.dispatch.event_one,
        )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:26,代码来源:test_events.py


示例2: test_backref_events

    def test_backref_events(self):
        User, Address = self._user_address_fixture(addresses_args={"backref": "user"})

        u1 = User()
        a1 = Address()
        u1.addresses.append(a1)
        is_(a1.user, u1)
开发者ID:hunterfu,项目名称:LuoYunCloud,代码行数:7,代码来源:test_dynamic.py


示例3: test_select

    def test_select(self):
        t = Table("t", MetaData(), Column("x", Integer))
        s = t.select()

        is_(inspect(s), s)
        assert s.is_selectable
        is_(s.selectable, s)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:7,代码来源:test_inspect.py


示例4: test_inplace_add

    def test_inplace_add(self):
        User = self.classes.User
        session = Session()

        def l1():
            return session.query(User)

        def l2(q):
            return q.filter(User.name == bindparam('name'))

        q1 = self.bakery(l1)
        self._assert_cache_key(
            q1._cache_key,
            [l1]
        )
        eq_(q1.steps, [l1])

        q2 = q1.add_criteria(l2)
        is_(q2, q1)

        self._assert_cache_key(
            q1._cache_key,
            [l1, l2]
        )
        eq_(q1.steps, [l1, l2])
开发者ID:eoghanmurray,项目名称:sqlalchemy,代码行数:25,代码来源:test_baked.py


示例5: _run_test

    def _run_test(self, specs, attributes):
        columns = [Column("c%i" % (i + 1), t[0]) for i, t in enumerate(specs)]

        # Early 5.0 releases seem to report more "general" for columns
        # in a view, e.g. char -> varchar, tinyblob -> mediumblob
        use_views = testing.db.dialect.server_version_info > (5, 0, 10)

        m = self.metadata
        Table("mysql_types", m, *columns)

        if use_views:
            event.listen(m, "after_create", DDL("CREATE OR REPLACE VIEW mysql_types_v " "AS SELECT * from mysql_types"))
            event.listen(m, "before_drop", DDL("DROP VIEW IF EXISTS mysql_types_v"))
        m.create_all()

        m2 = MetaData(testing.db)
        tables = [Table("mysql_types", m2, autoload=True)]
        if use_views:
            tables.append(Table("mysql_types_v", m2, autoload=True))

        for table in tables:
            for i, (reflected_col, spec) in enumerate(zip(table.c, specs)):
                expected_spec = spec[1]
                reflected_type = reflected_col.type
                is_(type(reflected_type), type(expected_spec))

                for attr in attributes:
                    eq_(
                        getattr(reflected_type, attr),
                        getattr(expected_spec, attr),
                        "Column %s: Attribute %s value of %s does not "
                        "match %s for type %s"
                        % ("c%i" % (i + 1), attr, getattr(reflected_type, attr), getattr(expected_spec, attr), spec[0]),
                    )
开发者ID:pugong,项目名称:sqlalchemy,代码行数:34,代码来源:test_reflection.py


示例6: _test_round_trip

    def _test_round_trip(self, fixture, warnings=False):
        from sqlalchemy import inspect
        conn = testing.db.connect()
        for from_, to_ in self._fixture_as_string(fixture):
            inspector = inspect(conn)
            conn.execute("CREATE TABLE foo (data %s)" % from_)
            try:
                if warnings:
                    def go():
                        return inspector.get_columns("foo")[0]
                    col_info = testing.assert_warnings(go,
                                    ["Could not instantiate"], regex=True)
                else:
                    col_info = inspector.get_columns("foo")[0]
                expected_type = type(to_)
                is_(type(col_info['type']), expected_type)

                # test args
                for attr in ("scale", "precision", "length"):
                    if getattr(to_, attr, None) is not None:
                        eq_(
                            getattr(col_info['type'], attr),
                            getattr(to_, attr, None)
                        )
            finally:
                conn.execute("DROP TABLE foo")
开发者ID:Callek,项目名称:sqlalchemy,代码行数:26,代码来源:test_sqlite.py


示例7: test_sets

    def test_sets(self):
# start Py2K
#        import sets
# end Py2K

        class SetLike(object):
            def add(self):
                pass

        class ForcedSet(list):
            __emulates__ = set

        for type_ in (set,
# start Py2K
#                      sets.Set,
# end Py2K
                      SetLike,
                      ForcedSet):
            eq_(util.duck_type_collection(type_), set)
            instance = type_()
            eq_(util.duck_type_collection(instance), set)

        for type_ in (frozenset,
# start Py2K
#                      sets.ImmutableSet
# end Py2K
                      ):
            is_(util.duck_type_collection(type_), None)
            instance = type_()
            is_(util.duck_type_collection(instance), None)
开发者ID:e0ne,项目名称:sqlalchemy,代码行数:30,代码来源:test_utils.py


示例8: test_synonym_filter

    def test_synonym_filter(self):
        User = self.classes.User
        syn = inspect(User).synonyms

        eq_(list(syn.keys()), ["name_syn"])
        is_(syn.name_syn, User.name_syn.original_property)
        eq_(dict(syn), {"name_syn": User.name_syn.original_property})
开发者ID:monetate,项目名称:sqlalchemy,代码行数:7,代码来源:test_inspect.py


示例9: test_insp_column_prop

    def test_insp_column_prop(self):
        User = self.classes.User
        prop = inspect(User.name)
        is_(prop, User.name)

        is_(prop.parent, class_mapper(User))
        assert not hasattr(prop, "mapper")
开发者ID:afeide,项目名称:LuoYunCloud,代码行数:7,代码来源:test_inspect.py


示例10: test_password_custom_obj

    def test_password_custom_obj(self):
        class SecurePassword(str):
            def __init__(self, value):
                self.value = value

            def __str__(self):
                return self.value

        sp = SecurePassword("secured_password")
        u = url.URL("dbtype", username="x", password=sp, host="localhost")

        eq_(u.password, "secured_password")
        eq_(str(u), "dbtype://x:[email protected]")

        # test in-place modification
        sp.value = "new_secured_password"
        eq_(u.password, "new_secured_password")
        eq_(str(u), "dbtype://x:[email protected]")

        u.password = "hi"

        eq_(u.password, "hi")
        eq_(str(u), "dbtype://x:[email protected]")

        u.password = None

        is_(u.password, None)
        eq_(str(u), "dbtype://[email protected]")
开发者ID:vrajmohan,项目名称:sqlalchemy,代码行数:28,代码来源:test_parseconnect.py


示例11: test_invocation_systemwide_loaders

    def test_invocation_systemwide_loaders(self):
        baked.bake_lazy_loaders()
        try:
            User, Address = self._o2m_fixture()

            sess = Session()
            q = sess.query(User).options(lazyload(User.addresses))
            with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
                u1 = q.first()
                u1.addresses
                # invoked
                is_(
                    el.mock_calls[0][1][1],
                    u1._sa_instance_state
                )
        finally:
            baked.unbake_lazy_loaders()

        clear_mappers()
        User, Address = self._o2m_fixture()
        sess = Session()
        q = sess.query(User).options(lazyload(User.addresses))

        with mock.patch.object(BakedLazyLoader, "_emit_lazyload") as el:
            u1 = q.first()
            u1.addresses
            # not invoked
            eq_(el.mock_calls, [])
开发者ID:CyberCollins,项目名称:sqlalchemy,代码行数:28,代码来源:test_baked.py


示例12: test_any_literal

    def test_any_literal(self):
        stuff = self.tables.stuff
        stmt = select([4 == any_(select([stuff.c.value]))])

        is_(
            testing.db.execute(stmt).scalar(), True
        )
开发者ID:laserson,项目名称:sqlalchemy,代码行数:7,代码来源:test_query.py


示例13: test_post_update_m2o_detect_none

    def test_post_update_m2o_detect_none(self):
        person, ball, Ball, Person = (
            self.tables.person,
            self.tables.ball,
            self.classes.Ball,
            self.classes.Person)

        mapper(Ball, ball, properties={
            'person': relationship(
                Person, post_update=True,
                primaryjoin=person.c.id == ball.c.person_id)
        })
        mapper(Person, person)

        sess = create_session(autocommit=False, expire_on_commit=True)
        sess.add(Ball(person=Person()))
        sess.commit()
        b1 = sess.query(Ball).first()

        # needs to be unloaded
        assert 'person' not in b1.__dict__
        b1.person = None

        self.assert_sql_execution(
            testing.db,
            sess.flush,
            CompiledSQL(
                "UPDATE ball SET person_id=:person_id "
                "WHERE ball.id = :ball_id",
                lambda ctx: {'person_id': None, 'ball_id': b1.id})
        )

        is_(b1.person, None)
开发者ID:anti-social,项目名称:sqlalchemy,代码行数:33,代码来源:test_cycles.py


示例14: test_savepoint_lost_still_runs

    def test_savepoint_lost_still_runs(self):
        User = self.classes.User
        s = self.session(bind=self.bind)
        trans = s.begin_nested()
        s.connection()
        u1 = User(name='ed')
        s.add(u1)

        # kill off the transaction
        nested_trans = trans._connections[self.bind][1]
        nested_trans._do_commit()

        is_(s.transaction, trans)
        assert_raises(
            sa_exc.DBAPIError,
            s.rollback
        )

        assert u1 not in s.new

        is_(trans._state, _session.CLOSED)
        is_not_(s.transaction, trans)
        is_(s.transaction._state, _session.ACTIVE)

        is_(s.transaction.nested, False)

        is_(s.transaction._parent, None)
开发者ID:FluxIX,项目名称:sqlalchemy,代码行数:27,代码来源:test_transaction.py


示例15: insert_values

        def insert_values(engine, table_, values):
            """
            Inserts a row into a table, returns the full list of values
            INSERTed including defaults that fired off on the DB side and
            detects rows that had defaults and post-fetches.
            """

            # verify implicit_returning is working
            if engine.dialect.implicit_returning:
                ins = table_.insert()
                comp = ins.compile(engine, column_keys=list(values))
                if not set(values).issuperset(
                        c.key for c in table_.primary_key):
                    is_(bool(comp.returning), True)

            result = engine.execute(table_.insert(), **values)
            ret = values.copy()

            for col, id in zip(
                    table_.primary_key, result.inserted_primary_key):
                ret[col.key] = id

            if result.lastrow_has_defaults():
                criterion = and_(
                    *[
                        col == id for col, id in
                        zip(table_.primary_key, result.inserted_primary_key)])
                row = engine.execute(table_.select(criterion)).first()
                for c in table_.c:
                    ret[c.key] = row[c]
            return ret
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:31,代码来源:test_insert_exec.py


示例16: test_column_in_mapper_args_used_multiple_times

    def test_column_in_mapper_args_used_multiple_times(self):

        class MyMixin(object):

            version_id = Column(Integer)
            __mapper_args__ = {'version_id_col': version_id}

        class ModelOne(Base, MyMixin):

            __tablename__ = 'm1'
            id = Column(Integer, primary_key=True)

        class ModelTwo(Base, MyMixin):

            __tablename__ = 'm2'
            id = Column(Integer, primary_key=True)

        is_(
            ModelOne.__mapper__.version_id_col,
            ModelOne.__table__.c.version_id
        )
        is_(
            ModelTwo.__mapper__.version_id_col,
            ModelTwo.__table__.c.version_id
        )
开发者ID:Julian,项目名称:sqlalchemy,代码行数:25,代码来源:test_mixin.py


示例17: _run_test

 def _run_test(self, specs, attributes):
     columns = [Column("c%i" % (i + 1), t[0]) for i, t in enumerate(specs)]
     m = self.metadata
     Table("oracle_types", m, *columns)
     m.create_all()
     m2 = MetaData(testing.db)
     table = Table("oracle_types", m2, autoload=True)
     for i, (reflected_col, spec) in enumerate(zip(table.c, specs)):
         expected_spec = spec[1]
         reflected_type = reflected_col.type
         is_(type(reflected_type), type(expected_spec))
         for attr in attributes:
             eq_(
                 getattr(reflected_type, attr),
                 getattr(expected_spec, attr),
                 "Column %s: Attribute %s value of %s does not "
                 "match %s for type %s"
                 % (
                     "c%i" % (i + 1),
                     attr,
                     getattr(reflected_type, attr),
                     getattr(expected_spec, attr),
                     spec[0],
                 ),
             )
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:25,代码来源:test_reflection.py


示例18: test_column_error_printing

    def test_column_error_printing(self):
        result = testing.db.execute(select([1]))
        row = result.first()

        class unprintable(object):

            def __str__(self):
                raise ValueError("nope")

        msg = r"Could not locate column in row for column '%s'"

        for accessor, repl in [
            ("x", "x"),
            (Column("q", Integer), "q"),
            (Column("q", Integer) + 12, r"q \+ :q_1"),
            (unprintable(), "unprintable element.*"),
        ]:
            assert_raises_message(
                exc.NoSuchColumnError,
                msg % repl,
                result._getter, accessor
            )

            is_(result._getter(accessor, False), None)

            assert_raises_message(
                exc.NoSuchColumnError,
                msg % repl,
                lambda: row[accessor]
            )
开发者ID:CyberCollins,项目名称:sqlalchemy,代码行数:30,代码来源:test_resultset.py


示例19: test_mapper_selectable

 def test_mapper_selectable(self):
     User = self.classes.User
     user_table = self.tables.users
     insp = inspect(User)
     is_(insp.selectable, user_table)
     assert not insp.is_selectable
     assert not insp.is_aliased_class
开发者ID:afeide,项目名称:LuoYunCloud,代码行数:7,代码来源:test_inspect.py


示例20: test_info_from_hybrid

    def test_info_from_hybrid(self):
        A = self._fixture()
        A._value.info['foo'] = 'bar'
        A.value.info['bar'] = 'hoho'

        insp = inspect(A)
        is_(insp.all_orm_descriptors['value'].info, A.value.info)
开发者ID:Dorthu,项目名称:sqlalchemy,代码行数:7,代码来源:test_hybrid.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testing.is_not_函数代码示例发布时间:2022-05-27
下一篇:
Python testing.in_函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap