本文整理匯總了Python中robot.model.itemlist.ItemList類的典型用法代碼示例。如果您正苦於以下問題:Python ItemList類的具體用法?Python ItemList怎麽用?Python ItemList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ItemList類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_insert
def test_insert(self):
items = ItemList(str)
items.insert(0, 'a')
items.insert(0, 'b')
items.insert(3, 'c')
items.insert(1, 'd')
assert_equal(list(items), ['b', 'd', 'a', 'c'])
示例2: test_pop
def test_pop(self):
items = ItemList(str, items='abcde')
assert_equal(items.pop(), 'e')
assert_equal(items.pop(0), 'a')
assert_equal(items.pop(-2), 'c')
assert_equal(list(items), ['b', 'd'])
assert_raises(IndexError, items.pop, 7)
assert_equal(list(items), ['b', 'd'])
assert_raises(IndexError, ItemList(int).pop)
示例3: test_create_with_args_and_kwargs
def test_create_with_args_and_kwargs(self):
class Item(object):
def __init__(self, arg1, arg2):
self.arg1 = arg1
self.arg2 = arg2
items = ItemList(Item)
item = items.create('value 1', arg2='value 2')
assert_equal(item.arg1, 'value 1')
assert_equal(item.arg2, 'value 2')
assert_equal(list(items), [item])
示例4: test_common_attrs
def test_common_attrs(self):
item1 = Object()
item2 = Object()
parent = object()
items = ItemList(Object, {'attr': 2, 'parent': parent}, [item1])
items.append(item2)
assert_true(item1.parent is parent)
assert_equal(item1.attr, 2)
assert_true(item2.parent is parent)
assert_equal(item2.attr, 2)
assert_equal(list(items), [item1, item2])
示例5: test_index_with_start_and_stop
def test_index_with_start_and_stop(self):
numbers = [0, 1, 2, 3, 2, 1, 0]
items = ItemList(int, items=numbers)
for num in sorted(set(numbers)):
for start in range(len(numbers)):
if num in numbers[start:]:
assert_equal(items.index(num, start),
numbers.index(num, start))
for end in range(start, len(numbers)):
if num in numbers[start:end]:
assert_equal(items.index(num, start, end),
numbers.index(num, start, end))
示例6: test_extend_with_generator
def test_extend_with_generator(self):
items = ItemList(str)
items.extend((c for c in 'Hello, world!'))
assert_equal(list(items), list('Hello, world!'))
示例7: test_append_and_extend
def test_append_and_extend(self):
items = ItemList(int)
items.append(1)
items.append(2)
items.extend((3, 4))
assert_equal(list(items), [1, 2, 3, 4])
示例8: test_create_items
def test_create_items(self):
items = ItemList(str)
item = items.create(object=1)
assert_true(isinstance(item, str))
assert_equal(item, '1')
assert_equal(list(items), [item])
示例9: test_clear
def test_clear(self):
items = ItemList(int, range(10))
items.clear()
assert_equal(len(items), 0)
示例10: test_len
def test_len(self):
items = ItemList(object)
assert_equal(len(items), 0)
items.create()
assert_equal(len(items), 1)
示例11: test_index
def test_index(self):
items = ItemList(str, items=('first', 'second'))
assert_equal(items.index('first'), 0)
assert_equal(items.index('second'), 1)
assert_raises(ValueError, items.index, 'nonex')
示例12: test_index
def test_index(self):
items = ItemList(str, items=("first", "second"))
assert_equal(items.index("first"), 0)
assert_equal(items.index("second"), 1)