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


Python utest.raises函数代码示例

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


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


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