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

Python utest.raises函数代码示例

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

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



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

示例1: a

 def a(self):
     s = BytesIO()
     for sample in ([], [0], [2, 1], range(7)):
         int_array = IntArray(file=s, number_of_ints=10, maximum_int=10)
         for j, x in enumerate(sample):
             int_array[j] = x
         non_blanks = set(int_array)
         non_blanks.discard(int_array.get_blank_value())
         assert set(sample) == non_blanks, (list(int_array), sample)
     assert raises(IndexError, int_array.__getitem__, 10)
     int_array2 = IntArray(file=BytesIO(s.getvalue()))
     int_array3 = IntArray(number_of_ints=10, maximum_int=300)
     for x in range(10):
         assert int_array3.get(x) == None
     assert int_array3[1] == int_array3.get_blank_value()
     int_array3[1] = 42
     assert int_array3.get(1)== 42
     assert len(int_array3) == 10
     raises(ValueError, int_array3.__setitem__, 2, 100000)
     int_array4 = IntArray(number_of_ints=10)
     assert int_array4.get(1, default=42) == 42
     assert int_array4.get(100, default=42) == 42
     assert list(iteritems(int_array4)) == []
     int_array4[3] = 4
     int_array4[8] = 9
     assert list(iteritems(int_array4)) == [(3, 4), (8, 9)]
开发者ID:cfobel,项目名称:durus,代码行数:26,代码来源:utest_utils.py


示例2: end_protocol_error

 def end_protocol_error(self):
     s1 = ClientStorage(address=self.address)
     c1 = Connection(s1)
     r1 = c1.get_root()
     s1.s = FakeSocket('\0\0\0\0?')
     r1._p_note_change()
     raises(ProtocolError, c1.commit)
开发者ID:cfobel,项目名称:durus,代码行数:7,代码来源:utest_client_storage.py


示例3: check_object_writer

 def check_object_writer(self):
     class FakeConnection(ConnectionBase):
         def new_oid(self):
             return ROOT_OID
         def note_access(self, obj):
             pass
     connection = FakeConnection()
     self.s=s=ObjectWriter(connection)
     x = Persistent()
     assert x._p_connection == None
     x._p_oid = ROOT_OID
     x._p_connection = connection
     assert s._persistent_id(x) == (ROOT_OID, Persistent)
     x._p_connection = FakeConnection()
     # connection of x no longer matches connection of s.
     raises(ValueError, s._persistent_id, x)
     x.a = Persistent()
     assert s.get_state(x), (
         '\x80\x02cdurus.persistent\nPersistent\nq\x01.\x80\x02}q\x02U'
         '\x01aU\x08\x00\x00\x00\x00\x00\x00\x00\x00q\x03h\x01\x86Qs.',
         '\x00\x00\x00\x00\x00\x00\x00\x00')
     assert list(s.gen_new_objects(x)) == [x, x.a]
     # gen_new_objects() can only be called once.
     raises(RuntimeError, s.gen_new_objects, 3)
     s.close()
开发者ID:cfobel,项目名称:durus,代码行数:25,代码来源:utest_serialize.py


示例4: update

 def update(self):
     pd = PersistentDict()
     pd.update()
     raises(TypeError, pd.update, {}, {})
     assert not list(pd.items())
     pd.update(a=1)
     assert list(pd.items()) == [('a', 1)]
     pd = PersistentDict()
     pd.update(dict(b=2), a=1)
     assert len(list(pd.items())) == 2
     assert pd['b'] == 2
     assert pd['a'] == 1
     pd = PersistentDict()
     pd.update([('b', 2)], a=1)
     assert len(pd.items()) == 2
     assert pd['b'] == 2
     assert pd['a'] == 1
     pd2 = PersistentDict((x, True) for x in range(10))
     pd.update(pd2)
     class keyed(object):
         data = dict(a=3)
         keys = data.keys
         __setitem__ = data.__setitem__
         __getitem__ = data.__getitem__
     pd.update(keyed())
     assert pd['a'] == 3
开发者ID:cfobel,项目名称:durus,代码行数:26,代码来源:utest_persistent_dict.py


示例5: test_remove

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


示例6: check_wrong_magic

 def check_wrong_magic(self):
     name = mktemp()
     f = open(name, 'w')
     f.write('bogusbogus')
     f.close()
     raises(AssertionError, FileStorage, name)
     unlink(name)
开发者ID:nascheme,项目名称:durus,代码行数:7,代码来源:utest_file_storage.py


示例7: check_write_conflict

 def check_write_conflict(self):
     s1 = ClientStorage(address=self.address)
     c1 = Connection(s1)
     r1 = c1.get_root()
     s1.s = FakeSocket('\0\0\0\0', STATUS_INVALID)
     r1._p_note_change()
     raises(WriteConflictError, c1.commit)
开发者ID:cfobel,项目名称:durus,代码行数:7,代码来源:utest_client_storage.py


示例8: test_pop

 def test_pop(self):
     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,项目名称:durus,代码行数:7,代码来源:utest_persistent_set.py


示例9: find_extremes

 def find_extremes(self):
     bt = BTree()
     raises(AssertionError, bt.get_min_item)
     raises(AssertionError, bt.get_max_item)
     for j in range(100):
         bt.add(j)
     assert bt.get_min_item() == (0, True)
     assert bt.get_max_item() == (99, True)
开发者ID:Schevo,项目名称:durus,代码行数:8,代码来源:utest_btree.py


示例10: check_bad_record_size

 def check_bad_record_size(self):
     name = mktemp()
     f = open(name, 'wb')
     g = FileStorage(name)
     f.seek(0, 2)
     write_int4_str(f, 'ok')
     g.close()
     f.close()
     raises(ShortRead, FileStorage, name)
     unlink(name)
开发者ID:nascheme,项目名称:durus,代码行数:10,代码来源:utest_file_storage.py


示例11: check_reopen

 def check_reopen(self):
     f = TempFileStorage()
     filename = f.get_filename()
     if os.name == 'nt':
         f.close() # don't try to re-open an open file on windows
         return
     g = FileStorage(filename, readonly=True)
     raises(IOError, FileStorage, filename)
     f.close()
     g.close()
开发者ID:nascheme,项目名称:durus,代码行数:10,代码来源:utest_file_storage.py


示例12: f

 def f(self):
     class FakeSocket(object):
         def recv(self, n):
             if n > 10:
                 return as_bytes('')
             return as_bytes('x')
         def send(self, s):
             return len(s)
     s = FakeSocket()
     write(s, 'x' * 2000000)
     read(s, 8)
     raises(ShortRead, read, s, 11)
开发者ID:cfobel,项目名称:durus,代码行数:12,代码来源:utest_utils.py


示例13: check_client_storage

 def check_client_storage(self):
     b = ClientStorage(address=self.address)
     c = ClientStorage(address=self.address)
     oid = b.new_oid()
     assert oid == int8_to_str(0), repr(oid)
     oid = b.new_oid()
     assert oid == int8_to_str(1), repr(oid)
     oid = b.new_oid()
     assert oid == int8_to_str(2), repr(oid)
     raises(KeyError, b.load, int8_to_str(0))
     record = pack_record(int8_to_str(0), as_bytes('ok'), as_bytes(''))
     b.begin()
     b.store(int8_to_str(0), record)
     assert b.end() is None
     b.load(int8_to_str(0))
     assert b.sync() == []
     b.begin()
     b.store(
         int8_to_str(1),
         pack_record(int8_to_str(1), as_bytes('no'), as_bytes('')))
     b.end()
     assert len(list(b.gen_oid_record())) == 1
     records = b.bulk_load([int8_to_str(0), int8_to_str(1)])
     assert len(list(records)) == 2
     records = b.bulk_load([int8_to_str(0), int8_to_str(1), int8_to_str(2)])
     raises(DurusKeyError, list, records)
     b.pack()
     assert len(list(b.gen_oid_record())) == 1
     raises(ReadConflictError, c.load, int8_to_str(0))
     raises(ReadConflictError, c.load, int8_to_str(0))
     assert set(c.sync()) == set([int8_to_str(0), int8_to_str(1)])
     assert record == c.load(int8_to_str(0))
     b.close()
     c.close()
开发者ID:cfobel,项目名称:durus,代码行数:34,代码来源:utest_client_storage.py


示例14: a

 def a(self):
     for sample in (["a"], ["a", "b"], ["ab", "cd", "ef"]):
         sample = [as_bytes(x) for x in sample]
         s = BytesIO()
         number_of_words = len(sample)
         bytes_per_word = 0
         if sample:
             bytes_per_word = len(sample[0])
         word_array = WordArray(file=s, bytes_per_word=bytes_per_word, number_of_words=number_of_words)
         for j, word in enumerate(sample):
             word_array[j] = word
         assert list(word_array) == sample, (list(word_array), sample)
     assert raises(ValueError, word_array.__setitem__, 1, "sdf")
     assert raises(IndexError, word_array.__setitem__, 10, "sf")
     assert raises(IndexError, word_array.__getitem__, -10)
开发者ID:pfw,项目名称:Durus,代码行数:15,代码来源:utest_utils.py


示例15: lowlevelops

 def lowlevelops(self):
     from durus.persistent import _getattribute, _setattribute
     from durus.persistent import _delattribute, _hasattribute
     storage = TempFileStorage()
     connection = Connection(storage)
     root = connection.get_root()
     root._p_set_status_ghost()
     assert not _hasattribute(root, 'data')
     root._p_set_status_ghost()
     raises(AttributeError, _getattribute, root, 'data')
     assert root._p_is_ghost()
     _setattribute(root, 'data', 'bogus')
     assert root._p_is_ghost()
     _delattribute(root, 'data')
     assert root._p_is_ghost()
开发者ID:Schevo,项目名称:durus,代码行数:15,代码来源:utest_persistent.py


示例16: check_repair

 def check_repair(self):
     name = mktemp()
     g = FileStorage(name)
     g.close()
     f = open(name, 'r+b')
     f.seek(0, 2)
     p = f.tell()
     f.write(as_bytes('b'))
     f.flush()
     raises(ShortRead, FileStorage, name, readonly=True)
     h = FileStorage(name, repair=True)
     f.seek(0, 2)
     assert p == f.tell()
     f.close()
     h.close()
     unlink(name)
开发者ID:nascheme,项目名称:durus,代码行数:16,代码来源:utest_file_storage.py


示例17: check_conflict

 def check_conflict(self):
     b = Connection(self._get_storage())
     c = Connection(self._get_storage())
     rootb = b.get(int8_to_str(0))
     rootb['b'] = Persistent()
     rootc = c.get(int8_to_str(0))
     rootc['c'] = Persistent()
     c.commit()
     raises(ConflictError, b.commit)
     raises(KeyError, rootb.__getitem__, 'c')
     transaction_serial = b.transaction_serial
     b.abort()
     assert b.get_transaction_serial() > transaction_serial
     assert rootb._p_is_ghost()
     rootc['d'] = Persistent()
     c.commit()
     rootb['d']
开发者ID:Schevo,项目名称:durus,代码行数:17,代码来源:utest_connection.py


示例18: check_more

 def check_more(self):
     storage = TempFileStorage()
     connection = Connection(storage)
     root=connection.get_root()
     assert not root._p_is_ghost()
     root['a'] = 1
     assert root._p_is_unsaved()
     del root['a']
     connection.abort()
     assert root._p_is_ghost()
     raises(AttributeError, getattr, root, 'a')
     root._p_set_status_saved()
     assert root._p_is_saved()
     root._p_set_status_unsaved()
     assert root._p_is_unsaved()
     root._p_set_status_ghost()
     assert root._p_is_ghost()
     root._p_set_status_unsaved()
开发者ID:Schevo,项目名称:durus,代码行数:18,代码来源:utest_persistent.py


示例19: update

 def update(self):
     bt = BTree()
     bt.update()
     assert not list(bt.items())
     bt.update(a=1)
     assert list(bt.items()) == [('a', 1)]
     bt = BTree()
     bt.update(dict(b=2), a=1)
     assert len(list(bt.items())) == 2
     assert bt['b'] == 2
     assert bt['a'] == 1
     bt = BTree()
     bt.update([('b', 2)], a=1)
     assert len(list(bt.items())) == 2
     assert bt['b'] == 2
     assert bt['a'] == 1
     class Fake(object):
         def items(self):
             return [('1',2)]
     bt.update(Fake())
     raises(TypeError, bt.update, 1, 2)
开发者ID:Schevo,项目名称:durus,代码行数:21,代码来源:utest_btree.py


示例20: check_file_storage

 def check_file_storage(self):
     name = mktemp()
     b = FileStorage(name)
     assert b.new_oid() == int8_to_str(0)
     assert b.new_oid() == int8_to_str(1)
     assert b.new_oid() == int8_to_str(2)
     raises(KeyError, b.load, int8_to_str(0))
     record = pack_record(int8_to_str(0), as_bytes('ok'), as_bytes(''))
     b.begin()
     b.store(int8_to_str(0), record)
     b.end()
     b.sync()
     b.begin()
     b.store(int8_to_str(1), pack_record(
         int8_to_str(1), as_bytes('no'), as_bytes('')))
     b.end()
     assert len(list(b.gen_oid_record(start_oid=int8_to_str(0)))) == 1
     assert len(list(b.gen_oid_record())) == 2
     b.pack()
     b.close()
     unlink(name + '.prepack')
     raises(ValueError, b.pack) # storage closed
     unlink(name + '.pack')
     raises(ValueError, b.load, int8_to_str(0)) # storage closed
     unlink(name)
开发者ID:nascheme,项目名称:durus,代码行数:25,代码来源:utest_file_storage.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python client.Client类代码示例发布时间:2022-05-27
下一篇:
Python processor.Processor类代码示例发布时间: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