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

Python testing.assert_raises函数代码示例

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

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



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

示例1: test_notcallable

    def test_notcallable(self):
        class Point(object):
            pass
        table = self.point_map(Point)
        alias = aliased(Point)

        assert_raises(TypeError, alias)
开发者ID:AndryulE,项目名称:kitsune,代码行数:7,代码来源:test_utils.py


示例2: test_basic

    def test_basic(self):
        carrier = util.ExtensionCarrier()

        assert 'translate_row' not in carrier
        assert carrier.translate_row() is interfaces.EXT_CONTINUE
        assert 'translate_row' not in carrier

        assert_raises(AttributeError, lambda: carrier.snickysnack)

        class Partial(object):
            def __init__(self, marker):
                self.marker = marker
            def translate_row(self, row):
                return self.marker

        carrier.append(Partial('end'))
        assert 'translate_row' in carrier
        assert carrier.translate_row(None) == 'end'

        carrier.push(Partial('front'))
        assert carrier.translate_row(None) == 'front'

        assert 'populate_instance' not in carrier
        carrier.append(interfaces.MapperExtension)
        
        # Py3K
        #assert 'populate_instance' not in carrier
        # Py2K
        assert 'populate_instance' in carrier
        # end Py2K
        
        assert carrier.interface
        for m in carrier.interface:
            assert getattr(interfaces.MapperExtension, m)
开发者ID:AndryulE,项目名称:kitsune,代码行数:34,代码来源:test_utils.py


示例3: test_deleted_flag

 def test_deleted_flag(self):
     mapper(User, users)
     
     sess = sessionmaker()()
     
     u1 = User(name='u1')
     sess.add(u1)
     sess.commit()
     
     sess.delete(u1)
     sess.flush()
     assert u1 not in sess
     assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
     sess.rollback()
     assert u1 in sess
     
     sess.delete(u1)
     sess.commit()
     assert u1 not in sess
     assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
     
     make_transient(u1)
     sess.add(u1)
     sess.commit()
     
     eq_(sess.query(User).count(), 1)
开发者ID:AndryulE,项目名称:kitsune,代码行数:26,代码来源:test_session.py


示例4: test_basic

    def test_basic(self):
        carrier = util.ExtensionCarrier()

        assert "translate_row" not in carrier
        assert carrier.translate_row() is interfaces.EXT_CONTINUE
        assert "translate_row" not in carrier

        assert_raises(AttributeError, lambda: carrier.snickysnack)

        class Partial(object):
            def __init__(self, marker):
                self.marker = marker

            def translate_row(self, row):
                return self.marker

        carrier.append(Partial("end"))
        assert "translate_row" in carrier
        assert carrier.translate_row(None) == "end"

        carrier.push(Partial("front"))
        assert carrier.translate_row(None) == "front"

        assert "populate_instance" not in carrier
        carrier.append(interfaces.MapperExtension)
        assert "populate_instance" in carrier

        assert carrier.interface
        for m in carrier.interface:
            assert getattr(interfaces.MapperExtension, m)
开发者ID:hughperkins,项目名称:ailadder,代码行数:30,代码来源:test_utils.py


示例5: test_nonreflected_fk_raises

 def test_nonreflected_fk_raises(self):
     """test that a NoReferencedColumnError is raised when reflecting
     a table with an FK to another table which has not included the target
     column in its reflection.
     
     """
     meta = MetaData(testing.db)
     a1 = Table('a', meta,
         Column('x', sa.Integer, primary_key=True),
         Column('z', sa.Integer),
         test_needs_fk=True
     )
     b1 = Table('b', meta,
         Column('y', sa.Integer, sa.ForeignKey('a.x')),
         test_needs_fk=True
     )
     meta.create_all()
     try:
         m2 = MetaData(testing.db)
         a2 = Table('a', m2, include_columns=['z'], autoload=True)
         b2 = Table('b', m2, autoload=True)
         
         assert_raises(tsa.exc.NoReferencedColumnError, a2.join, b2)
     finally:
         meta.drop_all()
开发者ID:gajop,项目名称:springgrid,代码行数:25,代码来源:test_reflection.py


示例6: test_single_parent_raise

    def test_single_parent_raise(self):

        sess = create_session()
        
        y = T2(data='T2a')
        x = T1(data='T1a', t2=y)
        assert_raises(sa_exc.InvalidRequestError, T1, data='T1b', t2=y)
开发者ID:gajop,项目名称:springgrid,代码行数:7,代码来源:test_cascade.py


示例7: test_empty_insert_pk2

 def test_empty_insert_pk2(self):
     assert_raises(
         exc.DBAPIError,
         self._test_empty_insert,
         Table('b', MetaData(testing.db),
               Column('x', Integer, primary_key=True),
               Column('y', Integer, primary_key=True)))
开发者ID:clones,项目名称:sqlalchemy,代码行数:7,代码来源:test_sqlite.py


示例8: test_inheriting

 def test_inheriting(self):
     mapper(A, a_table, properties={
             'some_dest': relationship(Dest,back_populates='many_a')
         })
     mapper(B, b_table, inherits=A, concrete=True,
            properties={
                 'some_dest': relationship(Dest, back_populates='many_b')
             })
                 
     mapper(Dest, dest_table, properties={
                 'many_a': relationship(A,back_populates='some_dest'), 
                 'many_b': relationship(B,back_populates='some_dest')
             })
     sess = sessionmaker()()
     dest1 = Dest(name='c1')
     dest2 = Dest(name='c2')
     a1 = A(some_dest=dest1, aname='a1')
     a2 = A(some_dest=dest2, aname='a2')
     b1 = B(some_dest=dest1, bname='b1')
     b2 = B(some_dest=dest1, bname='b2')
     assert_raises(AttributeError, setattr, b1, 'aname', 'foo')
     assert_raises(AttributeError, getattr, A, 'bname')
     assert dest2.many_a == [a2]
     assert dest1.many_a == [a1]
     assert dest1.many_b == [b1, b2]
     sess.add_all([dest1, dest2])
     sess.commit()
     assert sess.query(Dest).filter(Dest.many_a.contains(a2)).one() is dest2
     assert dest2.many_a == [a2]
     assert dest1.many_a == [a1]
     assert dest1.many_b == [b1, b2]
     assert sess.query(B).filter(B.bname == 'b1').one() is b1
开发者ID:AndryulE,项目名称:kitsune,代码行数:32,代码来源:test_concrete.py


示例9: test_noninherited_warning

    def test_noninherited_warning(self):
        mapper(A, a_table, properties={
            'some_c':relation(C)
        })
        mapper(B, b_table,inherits=A, concrete=True)
        mapper(C, c_table)

        b = B()
        c = C()
        assert_raises(AttributeError, setattr, b, 'some_c', c)

        clear_mappers()
        mapper(A, a_table, properties={
            'a_id':a_table.c.id
        })
        mapper(B, b_table,inherits=A, concrete=True)
        mapper(C, c_table)
        b = B()
        assert_raises(AttributeError, setattr, b, 'a_id', 3)

        clear_mappers()
        mapper(A, a_table, properties={
            'a_id':a_table.c.id
        })
        mapper(B, b_table,inherits=A, concrete=True)
        mapper(C, c_table)
开发者ID:clones,项目名称:sqlalchemy,代码行数:26,代码来源:test_concrete.py


示例10: test_explode_in_initializer

    def test_explode_in_initializer(self):
        engine = engines.testing_engine()
        def broken_initialize(connection):
            connection.execute("select fake_stuff from _fake_table")
            
        engine.dialect.initialize = broken_initialize
        
        # raises a DBAPIError, not an AttributeError
        assert_raises(exc.DBAPIError, engine.connect)

        # dispose connections so we get a new one on
        # next go
        engine.dispose()

        p1 = engine.pool
        
        def is_disconnect(e):
            return True
            
        engine.dialect.is_disconnect = is_disconnect

        # invalidate() also doesn't screw up
        assert_raises(exc.DBAPIError, engine.connect)
        
        # pool was recreated
        assert engine.pool is not p1
开发者ID:AndryulE,项目名称:kitsune,代码行数:26,代码来源:test_reconnect.py


示例11: test_child_row_switch_two

    def test_child_row_switch_two(self):
        Session = sessionmaker()
        
        sess1 = Session()
        sess1.add(P(id=1, data='P version 1'))
        sess1.commit()
        sess1.close()
        
        p1 = sess1.query(P).first()

        sess2 = Session()
        p2 = sess2.query(P).first()
        
        sess1.delete(p1)
        sess1.commit()
        
        sess1.add(P(id='P1', data='P version 2'))
        sess1.commit()
        
        p2.data = 'P overwritten by concurrent tx'
        assert_raises(
            orm.exc.ConcurrentModificationError,
            sess2.commit
        )
        
        
        
        
        
开发者ID:gaguilarmi,项目名称:sqlalchemy,代码行数:24,代码来源:test_versioning.py


示例12: test_too_long_idx_name

    def test_too_long_idx_name(self):
        dialect = testing.db.dialect.__class__()

        for max_ident, max_index in [(22, None), (256, 22)]:
            dialect.max_identifier_length = max_ident
            dialect.max_index_name_length = max_index

            for tname, cname, exp in [
                ('sometable', 'this_name_is_too_long', 'ix_sometable_t_09aa'),
                ('sometable', 'this_name_alsois_long', 'ix_sometable_t_3cf1'),
            ]:
        
                t1 = Table(tname, MetaData(), 
                            Column(cname, Integer, index=True),
                        )
                ix1 = list(t1.indexes)[0]
        
                self.assert_compile(
                    schema.CreateIndex(ix1),
                    "CREATE INDEX %s "
                    "ON %s (%s)" % (exp, tname, cname),
                    dialect=dialect
                )
        
        dialect.max_identifier_length = 22
        dialect.max_index_name_length = None
        
        t1 = Table('t', MetaData(), Column('c', Integer))
        assert_raises(
            exc.IdentifierError,
            schema.CreateIndex(Index(
                        "this_other_name_is_too_long_for_what_were_doing", 
                        t1.c.c)).compile,
            dialect=dialect
        )
开发者ID:AndryulE,项目名称:kitsune,代码行数:35,代码来源:test_constraints.py


示例13: test_versioncheck

    def test_versioncheck(self):
        """query.with_lockmode performs a 'version check' on an already loaded instance"""

        s1 = create_session(autocommit=False)

        mapper(Foo, version_table, version_id_col=version_table.c.version_id)
        f1s1 = Foo(value='f1 value')
        s1.add(f1s1)
        s1.commit()

        s2 = create_session(autocommit=False)
        f1s2 = s2.query(Foo).get(f1s1.id)
        f1s2.value='f1 new value'
        s2.commit()

        # load, version is wrong
        assert_raises(
                sa.orm.exc.ConcurrentModificationError, 
                s1.query(Foo).with_lockmode('read').get, f1s1.id
            )

        # reload it - this expires the old version first
        s1.refresh(f1s1, lockmode='read')
        
        # now assert version OK
        s1.query(Foo).with_lockmode('read').get(f1s1.id)

        # assert brand new load is OK too
        s1.close()
        s1.query(Foo).with_lockmode('read').get(f1s1.id)
开发者ID:gaguilarmi,项目名称:sqlalchemy,代码行数:30,代码来源:test_versioning.py


示例14: test_default_constructor_state_not_shared

    def test_default_constructor_state_not_shared(self):
        scope = scoped_session(sa.orm.sessionmaker())

        class A(object):
            pass
        class B(object):
            def __init__(self):
                pass

        scope.mapper(A, table1)
        scope.mapper(B, table2)

        A(foo='bar')
        assert_raises(TypeError, B, foo='bar')

        scope = scoped_session(sa.orm.sessionmaker())

        class C(object):
            def __init__(self):
                pass
        class D(object):
            pass

        scope.mapper(C, table1)
        scope.mapper(D, table2)

        assert_raises(TypeError, C, foo='bar')
        D(foo='bar')
开发者ID:gajop,项目名称:springgrid,代码行数:28,代码来源:test_scoping.py


示例15: test_literal_interpretation

 def test_literal_interpretation(self):
     t = table('test', column('col1'))
     
     assert_raises(exc.ArgumentError, case, [("x", "y")])
     
     self.assert_compile(case([("x", "y")], value=t.c.col1), "CASE test.col1 WHEN :param_1 THEN :param_2 END")
     self.assert_compile(case([(t.c.col1==7, "y")], else_="z"), "CASE WHEN (test.col1 = :col1_1) THEN :param_1 ELSE :param_2 END")
开发者ID:AndryulE,项目名称:kitsune,代码行数:7,代码来源:test_case_statement.py


示例16: test_string_dates_raise

 def test_string_dates_raise(self):
     assert_raises(
         TypeError,
         testing.db.execute,
         select([1]).where(bindparam("date", type_=Date)),
         date=str(datetime.date(2007, 10, 30)),
     )
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:7,代码来源:test_sqlite.py


示例17: test_double_fk_usage_raises

 def test_double_fk_usage_raises(self):
     f = ForeignKey('b.id')
     
     assert_raises(exc.InvalidRequestError, Table, "a", metadata,
         Column('x', Integer, f),
         Column('y', Integer, f)
     )
开发者ID:gajop,项目名称:springgrid,代码行数:7,代码来源:test_constraints.py


示例18: test_length_deprecation

 def test_length_deprecation(self):
     assert_raises(exc.SADeprecationWarning, Numeric, length=8)
     
     @testing.uses_deprecated(".*is deprecated for Numeric")
     def go():
         n = Numeric(length=12)
         assert n.scale == 12
     go()
     
     n = Numeric(scale=12)
     for dialect in engines.all_dialects():
         n2 = dialect.type_descriptor(n)
         eq_(n2.scale, 12, dialect.name)
         
         # test colspec generates successfully using 'scale'
         assert n2.get_col_spec()
         
         # test constructor of the dialect-specific type
         n3 = n2.__class__(scale=5)
         eq_(n3.scale, 5, dialect.name)
         
         @testing.uses_deprecated(".*is deprecated for Numeric")
         def go():
             n3 = n2.__class__(length=6)
             eq_(n3.scale, 6, dialect.name)
         go()
开发者ID:gajop,项目名称:springgrid,代码行数:26,代码来源:test_types.py


示例19: test_unknown_types

    def test_unknown_types(self):
        meta = MetaData(testing.db)
        t = Table("test", meta,
            Column('foo', sa.DateTime))

        import sys
        dialect_module = sys.modules[testing.db.dialect.__module__]

        # we're relying on the presence of "ischema_names" in the
        # dialect module, else we can't test this.  we need to be able
        # to get the dialect to not be aware of some type so we temporarily
        # monkeypatch.  not sure what a better way for this could be,
        # except for an established dialect hook or dialect-specific tests
        if not hasattr(dialect_module, 'ischema_names'):
            return

        ischema_names = dialect_module.ischema_names
        t.create()
        dialect_module.ischema_names = {}
        try:
            m2 = MetaData(testing.db)
            assert_raises(tsa.exc.SAWarning, Table, "test", m2, autoload=True)

            @testing.emits_warning('Did not recognize type')
            def warns():
                m3 = MetaData(testing.db)
                t3 = Table("test", m3, autoload=True)
                assert t3.c.foo.type.__class__ == sa.types.NullType

        finally:
            dialect_module.ischema_names = ischema_names
            t.drop()
开发者ID:gajop,项目名称:springgrid,代码行数:32,代码来源:test_reflection.py


示例20: test_rollback_recover

    def test_rollback_recover(self):
        mapper(User, users)

        session = sessionmaker()()

        u1, u2, u3= \
            User(name='u1'),\
            User(name='u2'),\
            User(name='u3')

        session.add_all([u1, u2, u3])

        session.commit()

        session.delete(u2)
        u4 = User(name='u2')
        session.add(u4)
        session.flush()

        u5 = User(name='u3')
        session.add(u5)
        assert_raises(orm_exc.FlushError, session.flush)

        assert u5 not in session
        assert u2 not in session.deleted

        session.rollback()
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:27,代码来源:test_transaction.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python testing.assert_raises_message函数代码示例发布时间:2022-05-27
下一篇:
Python schema.Table类代码示例发布时间: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