Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_more_on_lists(self):
a = RedisList((66.25, 333, 333, 1, 1234.5))
assert (a.count(333), a.count(66.25), a.count('x')) == (2, 1, 0)
a.insert(2, -1)
a.append(333)
assert a == [66.25, 333, -1, 333, 1, 1234.5, 333]
assert a.index(333) == 1
a.remove(333)
assert a == [66.25, -1, 333, 1, 1234.5, 333]
a.reverse()
assert a == [333, 1234.5, 1, 333, -1, 66.25]
a.sort()
assert a == [-1, 1, 66.25, 333, 333, 1234.5]
assert a.pop() == 1234.5
assert a == [-1, 1, 66.25, 333, 333]
def test_nesting(self):
a = ['a', 'b', 'c']
n = [1, 2, 3]
x = RedisList((a, n))
assert x == [['a', 'b', 'c'], [1, 2, 3]]
assert x[0] == ['a', 'b', 'c']
assert x[0][1] == 'b'
def test_remove_nonexistent(self):
metasyntactic = RedisList((
'foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply',
'waldo', 'fred', 'plugh', 'xyzzy', 'thud',
))
with self.assertRaises(ValueError):
metasyntactic.remove('raj')
def test_extend(self):
squares = RedisList((1, 4, 9))
squares.extend((16, 25))
assert squares == [1, 4, 9, 16, 25]
def test_eq_typeerror(self):
squares = RedisList((1, 4, 9, 16, 25))
assert not squares == None
assert squares != None
def test_indexerror(self):
list_ = RedisList()
with self.assertRaises(IndexError):
list_[0] = 'raj'
def test_slices(self):
letters = RedisList(('a', 'b', 'c', 'd', 'e', 'f', 'g'))
assert letters == ['a', 'b', 'c', 'd', 'e', 'f', 'g']
assert letters[2:5] == ['c', 'd', 'e']
assert letters[2:5:2] == ['c', 'e']
assert letters[2:5:3] == ['c']
assert letters[2:5:4] == ['c']
letters[2:5] = ['C', 'D', 'E']
assert letters == ['a', 'b', 'C', 'D', 'E', 'f', 'g']
letters[2:5:2] = [None, None]
assert letters == ['a', 'b', None, 'D', None, 'f', 'g']
letters[2:5] = []
assert letters == ['a', 'b', 'f', 'g']
letters[:] = []
assert letters == []
def test_pop_out_of_range(self):
squares = RedisList((1, 4, 9, 16, 25))
with self.assertRaises(IndexError):
squares.pop(len(squares))
def test_sort(self):
squares = RedisList({1, 4, 9, 16, 25})
squares.sort()
assert squares == [1, 4, 9, 16, 25]
squares.sort(reverse=True)
assert squares == [25, 16, 9, 4, 1]
with self.assertRaises(NotImplementedError):
squares.sort(key=str)
def test_using_list_as_stack(self):
stack = RedisList((3, 4, 5))
stack.append(6)
stack.append(7)
assert stack == [3, 4, 5, 6, 7]
assert stack.pop() == 7
assert stack == [3, 4, 5, 6]
assert stack.pop() == 6
assert stack.pop() == 5
assert stack == [3, 4]