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


Python test.raises函数代码示例

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


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

示例1: test_immutable_entity_view_field_value

 def test_immutable_entity_view_field_value(self):
     foo1 = ex(db.Foo.t.create(name='foo1'))
     foo2 = ex(db.Foo.t.create(name='foo2'))
     bar = ex(db.Bar.t.create(foo_list=[foo1]))
     assert raises(AttributeError, getattr, bar.foo_list, 'append')
     v = bar.v.default()
     assert raises(AttributeError, getattr, v.foo_list, 'append')
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_field_entitylist.py

示例2: test_find_extremes

 def test_find_extremes(self):
     bt = BTree()
     assert raises(AssertionError, bt.get_min_item)
     assert raises(AssertionError, bt.get_max_item)
     map(bt.add, range(100))
     assert bt.get_min_item() == (0, True)
     assert bt.get_max_item() == (99, True)
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_store_btree.py

示例3: test_only_one_top_level

 def test_only_one_top_level(self):
     # Cannot pass more than one top-level transaction.
     tx1 = db.User.t.create(name='1')
     tx2 = db.User.t.create(name='2')
     assert raises(RuntimeError, db.execute, tx1, tx2)
     # Must pass at least one top-level transaction.
     assert raises(RuntimeError, db.execute)
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_transaction.py

示例4: test_extra_fields

 def test_extra_fields(self):
     # A normal Gender create does not normally have fget fields in
     # the transaction, but in ProblemGender we've inserted them as
     # fields of different types.
     tx = db.ProblemGender.t.create()
     assert sorted(tx.s.field_map().keys()) == [
         'code', 'count', 'foo', 'name']
     # When executing the transaction, the superclass T.Create
     # should ignore .count since it was an fget field.
     tx.code = 'X'
     tx.name = 'xyz'
     tx.count = 'foo'
     tx.foo = 5
     pgender = db.execute(tx)
     # Accessing the count directly should result in a calculated
     # value.
     assert pgender.count == 0
     # Peek in the database to make sure that it didn't get stored
     # in the database as a string though, since in cases where the
     # type of the calculated field is an entity field
     assert db._entity_field(
         'ProblemGender', pgender.s.oid, 'count') != 'foo'
     assert raises(KeyError, db._entity_field, 'ProblemGender',
                   pgender.s.oid, 'foo')
     # Same thing for updates.
     tx = pgender.t.update()
     tx.count = 'bar'
     tx.foo = 10
     pgender = db.execute(tx)
     assert pgender.count == 0
     assert db._entity_field(
         'ProblemGender', pgender.s.oid, 'count') != 'foo'
     assert raises(KeyError, db._entity_field, 'ProblemGender',
                   pgender.s.oid, 'foo')
开发者ID:Schevo,项目名称:schevo,代码行数:34,代码来源:test_transaction.py

示例5: test_transfer_account_suspended

 def test_transfer_account_suspended(self):
     betty = db.Person.findone(name='Betty Rubble')
     family = db.Account.findone(owner=betty, name='Family')
     savings = db.Account.findone(owner=betty, name='Savings')
     # Attempt transfer from family to savings.
     tx = family.t.transfer()
     tx.to_account = savings
     tx.amount = 0.01
     assert raises(Exception, db.execute, tx)
     # Attempt transfer from savings to family.
     tx = savings.t.transfer()
     tx.to_account = family
     tx.amount = 0.01
     assert raises(Exception, db.execute, tx)
开发者ID:Schevo,项目名称:schevo,代码行数:14,代码来源:test_bank.py

示例6: test_remove_entity_field_then_readd

 def test_remove_entity_field_then_readd(self):
     schema1 = fix("""
     class Foo(E.Entity):
         bar = f.entity('Bar')
         baz = f.integer()
     class Bar(E.Entity):
         bof = f.string()
     """)
     schema2 = fix("""
     class Foo(E.Entity):
         baz = f.integer()
     class Bar(E.Entity):
         bof = f.string()
     """)
     schema3 = fix("""
     class Foo(E.Entity):
         bar = f.entity('Bar')
         baz = f.integer()
     class Bar(E.Entity):
         bof = f.string()
     """)
     self.sync(schema1)
     bar = db.execute(db.Bar.t.create(bof='fob'))
     foo = db.execute(db.Foo.t.create(bar=bar, baz=12))
     foo_oid = foo.s.oid
     bar_oid = bar.s.oid
     assert bar.s.count() == 1
     # Evolve.
     self.evolve(schema2, version=2)
     foo = db.Foo[foo_oid]
     bar = db.Bar[bar_oid]
     assert foo.baz == 12
     raises(AttributeError, getattr, foo, 'bar')
     assert bar.s.count() == 0
     # Attempt to update the entity.
     tx = foo.t.update()
     tx.baz = 5
     db.execute(tx)
     assert foo.baz == 5
     # Evolve.
     self.evolve(schema3, version=3)
     foo = db.Foo[foo_oid]
     bar = db.Bar[bar_oid]
     assert foo.bar is UNASSIGNED
     assert foo.baz == 5
     tx = foo.t.update()
     tx.bar = bar
     db.execute(tx)
     assert foo.bar == bar
     assert bar.s.count() == 1
开发者ID:gldnspud,项目名称:schevo,代码行数:50,代码来源:test_evolve.py

示例7: test_database_decoration

 def test_database_decoration(self):
     # This label is assigned automatically.
     assert label.label(db) == u'Schevo Database'
     # It can be easily overridden.
     label.relabel(db, 'Custom Label')
     assert label.label(db) == u'Custom Label'
     # When reopening the database, the label persists.
     self.reopen()
     assert label.label(db) == u'Custom Label'
     # Cannot change the label during a transaction.
     def fn(db):
         label.relabel(db, u'Custom Label 2')
     tx = transaction.CallableWrapper(fn)
     raises(error.DatabaseExecutingTransaction,
            db.execute, tx)
开发者ID:Schevo,项目名称:schevo,代码行数:15,代码来源:test_label.py

示例8: test_pop

 def test_pop(self):
     assert raises(KeyError, set_type().pop)
     s1 = set_type('asdf')
     x = s1.pop()
     assert x not in s1
     assert len(s1) == 3
     assert (s1 | set_type(x)) == set_type('asdf')
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_store_persistent_set.py

示例9: test_remove

 def test_remove(self):
     s1 = set_type()
     assert raises(KeyError, s1.remove, 1)
     assert s1 == set_type()
     s1 = set_type('asdf')
     s1.remove('a')
     assert s1 == set_type('sdf')
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_store_persistent_set.py

示例10: test_delete_cannot_skip_revisions

 def test_delete_cannot_skip_revisions(self):
     tx = db.User.t.create(name='foo')
     user = db.execute(tx)
     tx1 = user.t.update(name='bar')
     tx2 = user.t.delete()
     db.execute(tx1)
     assert raises(error.TransactionExpired, db.execute, tx2)
开发者ID:Schevo,项目名称:schevo,代码行数:7,代码来源:test_transaction.py

示例11: test_a

 def test_a(self):
     filename = tempfile.mktemp()
     s = FileStorage2(filename)
     connection = Connection(s)
     root = connection.get_root()
     root['a'] = Persistent()
     root['a'].b = 1
     connection.commit()
     root['a'].b = 2
     connection.commit()
     s.close()
     hc = HistoryConnection(filename)
     a = hc.get_root()['a']
     assert len(hc.get_storage().index.history) == 4
     assert a.b == 2
     hc.previous()
     assert a.b == 1
     hc.next()
     assert a.b == 2
     hc.previous()
     assert a.b == 1
     hc.previous()
     assert a._p_is_ghost()
     assert not hasattr(a, '__dict__')
     assert isinstance(a, Persistent)
     assert raises(KeyError, getattr, a, 'b')
     assert hc.get(a._p_oid) is a
     hc.next()
     assert a.b == 1
     hc.get_storage().fp.close()
     os.unlink(filename)
开发者ID:Schevo,项目名称:schevo,代码行数:31,代码来源:test_store_history.py

示例12: test_remove_extent_restricted

 def test_remove_extent_restricted(self):
     schema1 = fix("""
     class Foo(E.Entity):
         bar = f.entity(allow='Bar')
     class Bar(E.Entity):
         baz = f.integer()
     """)
     schema2 = fix("""
     class Foo(E.Entity):
         bar = f.entity(allow='Bar')
     class Bof(E.Entity):
         baz = f.integer()
     """)
     self.sync(schema1)
     raises(error.ExtentDoesNotExist, self.sync, schema2)
     assert db.schema_source == schema1
     assert db.extent_names() == ['Bar', 'Foo']
开发者ID:gldnspud,项目名称:schevo,代码行数:17,代码来源:test_evolve.py

示例13: test_transfer_insufficient_funds

 def test_transfer_insufficient_funds(self):
     fred = db.Person.findone(name='Fred Flintstone')
     business = db.Account.findone(owner=fred, name='Business')
     personal = db.Account.findone(owner=fred, name='Personal')
     # Attempt transfer from personal to business.
     tx = personal.t.transfer()
     tx.to_account = business
     tx.amount = 205.00
     assert raises(Exception, db.execute, tx)
开发者ID:Schevo,项目名称:schevo,代码行数:9,代码来源:test_bank.py

示例14: test_field_requirements

 def test_field_requirements(self):
     tx = db.User.t.create()
     # User was not specified, so transaction shouldn't succeed.
     assert raises(AttributeError, db.execute, tx)
     # Even if the transaction's fields are modified, the entity's
     # field spec should remain enforced.
     tx.f.name.required = False
     assert raises(AttributeError, db.execute, tx)
     # Age should not be required though.
     tx = db.User.t.create()
     tx.name = 'foo'
     result = db.execute(tx)
     assert result.age is UNASSIGNED
     # When updating, restrictions should still be enforced.
     tx = result.t.update(name=UNASSIGNED)
     assert raises(AttributeError, db.execute, tx)
     tx.f.name.required = False
     assert raises(AttributeError, db.execute, tx)
开发者ID:Schevo,项目名称:schevo,代码行数:18,代码来源:test_entity_extent.py

示例15: test_unassign_when_unassigned_disallowed

 def test_unassign_when_unassigned_disallowed(self):
     bar1, bar2, bar3, bar4, bar5 = db.Bar.by('name')
     fee = ex(db.Fee.t.create(
         name='fee',
         bar_list=[bar1, bar2, bar3, bar4, bar5, bar4, bar3],
         ))
     assert list(fee.bar_list) == [bar1, bar2, bar3, bar4, bar5, bar4, bar3]
     call = ex, bar4.t.delete()
     assert raises(ValueError, *call)
开发者ID:gldnspud,项目名称:schevo,代码行数:9,代码来源:test_on_delete.py


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