def test_discard():
	"""Test discard."""
	sl = setlist(range(10))
	sl.discard(9)
	assert sl == setlist(range(9))
	sl.discard(100)
	assert sl == setlist(range(9))
def test_add():
	"""Test add."""
	sl = setlist(range(10))
	sl.add(10)
	assert sl == setlist(range(11))
	sl.add(10)
	assert sl == setlist(range(11))
def test_remove():
	"""Test remove."""
	sl = setlist(range(10))
	sl.remove(9)
	assert sl == setlist(range(9))
	with pytest.raises(ValueError):
		sl.remove(100)
def test_remove():
	"""Test remove."""
	sl = setlist(range(10))
	sl.remove(9)
	assert sl == setlist(range(9))
	with pytest.raises(ValueError):
		sl.remove(100)
示例#5
0
def test_tuple_keys():
	# https://github.com/mlenzen/collections-extended/issues/83
	sl = setlist()
	sl.add((1, 2, 3))
	with pytest.raises(ValueError):
		sl.append((1, 2, 3))
	assert sl == setlist([(1, 2, 3)])
def test_tuple_keys():
	# https://github.com/mlenzen/collections-extended/issues/83
	sl = setlist()
	sl.add((1, 2, 3))
	with pytest.raises(ValueError):
		sl.append((1, 2, 3))
	assert sl == setlist([(1, 2, 3)])
def test_discard():
	"""Test discard."""
	sl = setlist(range(10))
	sl.discard(9)
	assert sl == setlist(range(9))
	sl.discard(100)
	assert sl == setlist(range(9))
def test_add():
	"""Test add."""
	sl = setlist(range(10))
	sl.add(10)
	assert sl == setlist(range(11))
	sl.add(10)
	assert sl == setlist(range(11))
def test_swap():
	sl = setlist('abcdef')
	sl.swap(1, 2)
	assert_internal_structure(sl)
	assert sl == setlist('acbdef')
	sl.swap(-1, 1)
	assert_internal_structure(sl)
	assert sl == setlist('afbdec')
def test_extend_works():
	"""Test simple extend works."""
	sl = setlist(range(1))
	sl.extend([1, 2])
	assert sl == setlist(range(3))
	assert sl.index(0) == 0
	assert sl.index(1) == 1
	assert sl.index(2) == 2
示例#11
0
def test_swap():
	sl = setlist('abcdef')
	sl.swap(1, 2)
	assert_internal_structure(sl)
	assert sl == setlist('acbdef')
	sl.swap(-1, 1)
	assert_internal_structure(sl)
	assert sl == setlist('afbdec')
示例#12
0
def test_extend_works():
	"""Test simple extend works."""
	sl = setlist(range(1))
	sl.extend([1, 2])
	assert sl == setlist(range(3))
	assert sl.index(0) == 0
	assert sl.index(1) == 1
	assert sl.index(2) == 2
def test_add_operator():
	assert frozensetlist(range(2)) + frozensetlist([2]) == frozensetlist(range(3))
	assert setlist(range(2)) + frozensetlist([2]) == setlist(range(3))
	assert frozensetlist(range(2)) + setlist([2]) == frozensetlist(range(3))
	assert setlist(range(2)) + setlist([2]) == setlist(range(3))
	with pytest.raises(TypeError):
		setlist() + set()
	with pytest.raises(TypeError):
		setlist() + list()
示例#14
0
def test_extend():
    sl = setlist(range(10))
    sl.extend([10, 11])
    assert sl == setlist(range(12))
    with pytest.raises(ValueError):
        sl.extend([1, 2])
    assert sl == setlist(range(12))
    with pytest.raises(ValueError):
        sl.extend([13, 2])
    assert sl == setlist(range(12))
示例#15
0
def test_copy():
    sl = setlist(range(10))
    copy = sl.copy()
    assert sl == copy
    assert not sl is copy
    sl = setlist(('1', (0, 1)))
    copy = sl.copy()
    assert sl == copy
    assert not sl is copy
    assert sl[1] is copy[1]
def test_copy():
	"""Test copy."""
	sl = setlist(range(10))
	copy = sl.copy()
	assert sl == copy
	assert sl is not copy
	sl = setlist(('1', (0, 1)))
	copy = sl.copy()
	assert sl == copy
	assert sl is not copy
	assert sl[1] is copy[1]
def test_copy():
	"""Test copy."""
	sl = setlist(range(10))
	copy = sl.copy()
	assert sl == copy
	assert sl is not copy
	sl = setlist(('1', (0, 1)))
	copy = sl.copy()
	assert sl == copy
	assert sl is not copy
	assert sl[1] is copy[1]
def test_delitem():
	"""Test __delitem__."""
	sl = setlist(range(10))
	del sl[9]
	assert sl == setlist(range(9))
	del sl[-1]
	assert sl == setlist(range(8))
	del sl[0]
	assert sl == setlist(range(1, 8))
	with pytest.raises(IndexError):
		del sl[10]
def test_delitem():
	"""Test __delitem__."""
	sl = setlist(range(10))
	del sl[9]
	assert sl == setlist(range(9))
	del sl[-1]
	assert sl == setlist(range(8))
	del sl[0]
	assert sl == setlist(range(1, 8))
	with pytest.raises(IndexError):
		del sl[10]
示例#20
0
def test_del():
    sl = setlist('abcde')
    del sl[1]
    assert sl == setlist('acde')
    del sl[0]
    assert sl == setlist('cde')
    del sl[2]
    assert sl == setlist('cd')
    with pytest.raises(IndexError):
        del sl[2]
    with pytest.raises(IndexError):
        del sl[-3]
示例#21
0
def test_getitem():
    sl = setlist(range(10))
    assert sl[0] == 0
    assert sl[5] == 5
    assert sl[9] == 9
    with pytest.raises(IndexError):
        sl[10]
    assert sl[-1] == 9
    with pytest.raises(IndexError):
        sl[-11]
    assert sl[1:3] == setlist([1, 2])
    assert sl[1:6:2] == setlist([1, 3, 5])
    assert sl[6:1:-2] == setlist([6, 4, 2])
def test_del():
	"""Test __delitem__."""
	sl = setlist('abcde')
	del sl[1]
	assert sl == setlist('acde')
	del sl[0]
	assert sl == setlist('cde')
	del sl[2]
	assert sl == setlist('cd')
	with pytest.raises(IndexError):
		del sl[2]
	with pytest.raises(IndexError):
		del sl[-3]
def test_getitem():
	"""Test __getitem__."""
	sl = setlist(range(10))
	assert sl[0] == 0
	assert sl[5] == 5
	assert sl[9] == 9
	with pytest.raises(IndexError):
		sl[10]
	assert sl[-1] == 9
	with pytest.raises(IndexError):
		sl[-11]
	assert sl[1:3] == setlist([1, 2])
	assert sl[1:6:2] == setlist([1, 3, 5])
	assert sl[6:1:-2] == setlist([6, 4, 2])
示例#24
0
def test_delitem():
    sl = setlist(range(10))
    del sl[9]
    assert sl == setlist(range(9))
    del sl[-1]
    assert sl == setlist(range(8))
    del sl[0]
    assert sl == setlist(range(1, 8))
    with pytest.raises(IndexError):
        del sl[10]
    compare_del_slice_to_list(slice(0, 2))
    compare_del_slice_to_list(slice(6, 9))
    compare_del_slice_to_list(slice(3, 7))
    compare_del_slice_to_list(slice(7, 3, -1))
    compare_del_slice_to_list(slice(0, 7, 2))
def test_difference_update():
	sl = setlist('abd')
	sl.difference_update(setlist('bcd'))
	assert sl == setlist('a')
	sl = setlist('abd')
	sl.difference_update('bcd')
	assert sl == setlist('a')
	sl = setlist('abd')
	sl -= setlist('bcd')
	assert sl == setlist('a')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl -= 'bcd'
def test_symmetric_difference_update():
	sl = setlist('abd')
	sl.symmetric_difference_update(setlist('bcd'))
	assert sl == setlist('ac')
	sl = setlist('abd')
	sl.symmetric_difference_update('bcd')
	assert sl == setlist('ac')
	sl = setlist('abd')
	sl ^= setlist('bcd')
	assert sl == setlist('ac')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl ^= 'bcd'
def test_intersection_update():
	sl = setlist('abd')
	sl.intersection_update(setlist('bcd'))
	assert sl == setlist('bd')
	sl = setlist('abd')
	sl.intersection_update('bcd')
	assert sl == setlist('bd')
	sl = setlist('abd')
	sl &= setlist('bcd')
	assert sl == setlist('bd')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl &= 'bcd'
def test_symmetric_difference_update():
	sl = setlist('abd')
	sl.symmetric_difference_update(setlist('bcd'))
	assert sl == setlist('ac')
	sl = setlist('abd')
	sl.symmetric_difference_update('bcd')
	assert sl == setlist('ac')
	sl = setlist('abd')
	sl ^= setlist('bcd')
	assert sl == setlist('ac')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl ^= 'bcd'
def test_intersection_update():
	sl = setlist('abd')
	sl.intersection_update(setlist('bcd'))
	assert sl == setlist('bd')
	sl = setlist('abd')
	sl.intersection_update('bcd')
	assert sl == setlist('bd')
	sl = setlist('abd')
	sl &= setlist('bcd')
	assert sl == setlist('bd')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl &= 'bcd'
def test_difference_update():
	sl = setlist('abd')
	sl.difference_update(setlist('bcd'))
	assert sl == setlist('a')
	sl = setlist('abd')
	sl.difference_update('bcd')
	assert sl == setlist('a')
	sl = setlist('abd')
	sl -= setlist('bcd')
	assert sl == setlist('a')
	sl = setlist('abd')
	with pytest.raises(TypeError):
		sl -= 'bcd'
示例#31
0
def test_index():
    sl = setlist('abcdef')
    assert sl.index('a') == 0
    assert sl.index('f') == 5
    with pytest.raises(ValueError):
        sl.index('g')
    with pytest.raises(ValueError):
        sl.index('a', start=1)
    with pytest.raises(ValueError):
        sl.index('f', end=5)
    with pytest.raises(ValueError):
        sl.index('f', end=-1)
示例#32
0
def test_sub_index():
    sl = setlist('abcdef')
    assert sl.sub_index('ef') == 4
    with pytest.raises(ValueError):
        sl.sub_index('cb')
    with pytest.raises(ValueError):
        sl.sub_index('efg')
    with pytest.raises(TypeError):
        sl.sub_index(1)
    with pytest.raises(ValueError):
        sl.sub_index('ef', end=5)
    with pytest.raises(ValueError):
        sl.sub_index('ab', start=1)
def test_sub_index():
	"""Test sub_index."""
	sl = setlist('abcdef')
	assert sl.sub_index('ef') == 4
	with pytest.raises(ValueError):
		sl.sub_index('cb')
	with pytest.raises(ValueError):
		sl.sub_index('efg')
	with pytest.raises(TypeError):
		sl.sub_index(1)
	with pytest.raises(ValueError):
		sl.sub_index('ef', end=5)
	with pytest.raises(ValueError):
		sl.sub_index('ab', start=1)
def test_index():
	"""Test index."""
	sl = setlist('abcdef')
	assert sl.index('a') == 0
	assert sl.index('f') == 5
	with pytest.raises(ValueError):
		sl.index('g')
	with pytest.raises(ValueError):
		sl.index('a', start=1)
	with pytest.raises(ValueError):
		sl.index('f', end=5)
	with pytest.raises(ValueError):
		sl.index('f', end=-1)
	with pytest.raises(IndexError):
		sl.index('a', end=-10)
def test_sort():
	sl = setlist([4, 7, 1, 0])
	sl.sort()
	assert sl == setlist([0, 1, 4, 7])
	sl = setlist([])
	sl.sort()
	assert sl == setlist()
	sl = setlist(['a9', 'b7', 'c5'])
	sl.sort(key=lambda i: i[1])
	assert sl == setlist(['c5', 'b7', 'a9'])
def test_extend_update():
	sl = setlist('abd')
	sl += setlist('e')
	assert sl == setlist('abde')
	with pytest.raises(TypeError):
		sl += 'f'
	assert sl == setlist('abde')
	with pytest.raises(ValueError):
		sl += setlist('fe')
	assert sl == setlist('abde')
def test_extend_update():
	sl = setlist('abd')
	sl += setlist('e')
	assert sl == setlist('abde')
	with pytest.raises(TypeError):
		sl += 'f'
	assert sl == setlist('abde')
	with pytest.raises(ValueError):
		sl += setlist('fe')
	assert sl == setlist('abde')
示例#38
0
def test_sort():
	sl = setlist([4, 7, 1, 0])
	sl.sort()
	assert sl == setlist([0, 1, 4, 7])
	sl = setlist([])
	sl.sort()
	assert sl == setlist()
	sl = setlist(['a9', 'b7', 'c5'])
	sl.sort(key=lambda i: i[1])
	assert sl == setlist(['c5', 'b7', 'a9'])
def test_symmetric_difference():
	assert setlist('abd').symmetric_difference(setlist('bcd')) == setlist('ac')
	assert setlist('abd').symmetric_difference('bcd') == setlist('ac')
	assert setlist('abd') ^ setlist('bcd') == setlist('ac')
	with pytest.raises(TypeError):
		assert setlist('abd') ^ 'bcd' == setlist('ac')
def test_difference():
	assert setlist('abd').difference(setlist('bcd')) == setlist('a')
	assert setlist('abd').difference('bcd') == setlist('a')
	assert setlist('abd') - setlist('bcd') == setlist('a')
	with pytest.raises(TypeError):
		assert setlist('abd') - 'bcd' == setlist('a')
def test_intersection():
	assert setlist('abd').intersection(setlist('bcd')) == setlist('bd')
	assert setlist('abd').intersection('bcd') == setlist('bd')
	assert setlist('abd') & setlist('bcd') == setlist('bd')
	with pytest.raises(TypeError):
		assert setlist('abd') & 'bcd' == setlist('bd')
def test_union():
	assert setlist('ab').union(setlist('bc')) == setlist('abc')
	assert setlist('ab').union('bc') == setlist('abc')
	assert setlist('ab') | setlist('bc') == setlist('abc')
	with pytest.raises(TypeError):
		assert setlist('ab') | 'bc' == setlist('abc')
def test_is_superset():
	assert not setlist('ab').issuperset(setlist('abc'))
	assert setlist('abc').issuperset(setlist('abc'))
	assert setlist('abc').issuperset(setlist('ab'))
def test_symmetric_difference():
	assert setlist('abd').symmetric_difference(setlist('bcd')) == setlist('ac')
	assert setlist('abd').symmetric_difference('bcd') == setlist('ac')
	assert setlist('abd') ^ setlist('bcd') == setlist('ac')
	with pytest.raises(TypeError):
		assert setlist('abd') ^ 'bcd' == setlist('ac')
def test_remove_all_works():
	sl = setlist('abcdefgh')
	sl.remove_all('acdh')
	assert sl == setlist(('befg'))
def test_difference():
	assert setlist('abd').difference(setlist('bcd')) == setlist('a')
	assert setlist('abd').difference('bcd') == setlist('a')
	assert setlist('abd') - setlist('bcd') == setlist('a')
	with pytest.raises(TypeError):
		assert setlist('abd') - 'bcd' == setlist('a')
def test_init():
	with pytest.raises(ValueError):
		setlist('aa', raise_on_duplicate=True)
	with pytest.raises(ValueError):
		setlist('aa', True)
def test_intersection():
	assert setlist('abd').intersection(setlist('bcd')) == setlist('bd')
	assert setlist('abd').intersection('bcd') == setlist('bd')
	assert setlist('abd') & setlist('bcd') == setlist('bd')
	with pytest.raises(TypeError):
		assert setlist('abd') & 'bcd' == setlist('bd')
def test_union():
	assert setlist('ab').union(setlist('bc')) == setlist('abc')
	assert setlist('ab').union('bc') == setlist('abc')
	assert setlist('ab') | setlist('bc') == setlist('abc')
	with pytest.raises(TypeError):
		assert setlist('ab') | 'bc' == setlist('abc')
def test_setlist():
	"""General setlist tests."""
	sl = setlist('abcde')
	sl[0] = 5
	assert sl == setlist((5, 'b', 'c', 'd', 'e'))
	sl[-1] = 0
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	with pytest.raises(ValueError):
		sl[1] = 'c'
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	with pytest.raises(ValueError):
		sl.append('c')
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	sl[2] == 'c'
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	del sl[0]
	assert sl == setlist(('b', 'c', 'd', 0))
	del sl[-1]
	assert sl == setlist(('b', 'c', 'd'))
	assert sl.pop() == 'd'
	assert sl.pop(0) == 'b'
	assert sl == setlist(('c',))
	sl.insert(0, 'a')
	assert sl == setlist(('a', 'c'))
	sl.insert(len(sl), 'e')
	assert sl == setlist(('a', 'c', 'e'))
	with pytest.raises(ValueError):
		sl.insert(1, 'e')
	sl.append('f')
	assert sl == setlist(('a', 'c', 'e', 'f'))
def test_union_update():
	sl = setlist('abd')
	sl |= setlist('bcd')
	assert sl == setlist('abdc')
def test_is_superset():
	assert not setlist('ab').issuperset(setlist('abc'))
	assert setlist('abc').issuperset(setlist('abc'))
	assert setlist('abc').issuperset(setlist('ab'))
def test_setlist():
	"""General setlist tests."""
	sl = setlist('abcde')
	sl[0] = 5
	assert sl == setlist((5, 'b', 'c', 'd', 'e'))
	sl[-1] = 0
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	with pytest.raises(ValueError):
		sl[1] = 'c'
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	with pytest.raises(ValueError):
		sl.append('c')
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	sl[2] == 'c'
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	assert sl == setlist((5, 'b', 'c', 'd', 0))
	del sl[0]
	assert sl == setlist(('b', 'c', 'd', 0))
	del sl[-1]
	assert sl == setlist(('b', 'c', 'd'))
	assert sl.pop() == 'd'
	assert sl.pop(0) == 'b'
	assert sl == setlist(('c',))
	sl.insert(0, 'a')
	assert sl == setlist(('a', 'c'))
	sl.insert(len(sl), 'e')
	assert sl == setlist(('a', 'c', 'e'))
	with pytest.raises(ValueError):
		sl.insert(1, 'e')
	sl.append('f')
	assert sl == setlist(('a', 'c', 'e', 'f'))
def test_operator_iadd():
	sl = setlist('abc')
	sl += setlist('de')
	assert sl == setlist('abcde')
def test_eq():
	"""Test __eq__."""
	assert not setlist(range(10)) == list(range(10))
	assert not setlist(range(10)) == setlist(range(9))
def test_union_update():
	sl = setlist('abd')
	sl |= setlist('bcd')
	assert sl == setlist('abdc')
def test_init():
	"""Test __init__."""
	with pytest.raises(ValueError):
		setlist('aa', raise_on_duplicate=True)
	with pytest.raises(ValueError):
		setlist('aa', True)
def test_str():
	"""Test __str__."""
	assert str(setlist()) == '{[}]'
	assert str(setlist('abc')) == "{['a', 'b', 'c'}]"
	assert str(frozensetlist()) == 'frozensetlist()'
	assert str(frozensetlist('abc')) == "frozensetlist(('a', 'b', 'c'))"
def test_operator_add():
	assert setlist('abc') + setlist('def') == setlist('abcdef')
	with pytest.raises(TypeError):
		assert setlist('abc') + 'def' == setlist('abcdef')
	assert frozensetlist(range(2)) + frozensetlist([2]) == frozensetlist(range(3))
	assert setlist(range(2)) + frozensetlist([2]) == setlist(range(3))
	assert frozensetlist(range(2)) + setlist([2]) == frozensetlist(range(3))
	assert setlist(range(2)) + setlist([2]) == setlist(range(3))
	with pytest.raises(TypeError):
		setlist() + set()
	with pytest.raises(TypeError):
		setlist() + list()
def test_repr():
	"""Test __repr."""
	assert repr(setlist()) == 'setlist()'
	assert repr(setlist(range(4))) == 'setlist((0, 1, 2, 3))'
	assert repr(frozensetlist()) == 'frozensetlist()'
	assert repr(frozensetlist('abc')) == "frozensetlist(('a', 'b', 'c'))"