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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 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
0
 def test_clear(self):
     items = ItemList(int, range(10))
     items.clear()
     assert_equal(len(items), 0)
Пример #10
0
 def test_len(self):
     items = ItemList(object)
     assert_equal(len(items), 0)
     items.create()
     assert_equal(len(items), 1)
Пример #11
0
 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')
 def test_index(self):
     items = ItemList(str, items=("first", "second"))
     assert_equal(items.index("first"), 0)
     assert_equal(items.index("second"), 1)
Пример #13
0
 def test_index(self):
     items = ItemList(str, items=('first', 'second'))
     assert_equal(items.index('first'), 0)
     assert_equal(items.index('second'), 1)