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)
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_modifications_during_reversed(self): chars = ItemList(str, items='yxdba') for c in reversed(chars): if c == 'a': chars.remove('x') if c == 'b': chars.insert(-2, 'c') if c == 'c': chars.pop(0) if c == 'd': chars.insert(0, 'e') assert_true(c in 'abcde', '%s was unexpected here!' % c) assert_equal(list(chars), list('edcba'))