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])
def test_modifications_during_iter(self): chars = ItemList(str, items='abdx') for c in chars: if c == 'a': chars.pop() if c == 'b': chars.insert(2, 'c') if c == 'c': chars.append('e') assert_true(c in 'abcde', '%s was unexpected here!' % c) assert_equal(list(chars), list('abcde'))
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])