Esempio n. 1
0
 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')
Esempio n. 2
0
 def test_eq_same_redis_instance_different_keys(self):
     key1 = f'{TestCase._TEST_KEY_PREFIX}squares1'
     key2 = f'{TestCase._TEST_KEY_PREFIX}squares2'
     squares1 = RedisList((1, 4, 9, 16, 25), key=key1)
     squares2 = RedisList((1, 4, 9, 16, 25), key=key2)
     assert squares1 == squares2
     assert not squares1 != squares2
Esempio n. 3
0
 def test_mutability_and_append(self):
     cubes = RedisList((1, 8, 27, 65, 125))
     cubes[3] = 64
     assert cubes == [1, 8, 27, 64, 125]
     cubes.append(216)
     cubes.append(7**3)
     assert cubes == [1, 8, 27, 64, 125, 216, 343]
Esempio n. 4
0
 def test_eq_same_redis_instance_different_keys(self):
     key1 = 'squares1'
     key2 = 'squares2'
     squares1 = RedisList((1, 4, 9, 16, 25), redis=self.redis, key=key1)
     squares2 = RedisList((1, 4, 9, 16, 25), redis=self.redis, key=key2)
     assert squares1 == squares2
     assert not squares1 != squares2
Esempio n. 5
0
 def test_eq_same_redis_instance_and_key(self):
     squares1 = RedisList((1, 4, 9, 16, 25),
                          redis=self.redis,
                          key=self._KEY)
     squares2 = RedisList(redis=self.redis, key=self._KEY)
     assert squares1 == squares2
     assert not squares1 != squares2
Esempio n. 6
0
 def test_pop_index(self):
     metasyntactic = RedisList(
         ('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply',
          'waldo', 'fred', 'plugh', 'xyzzy', 'thud'),
         redis=self.redis,
     )
     assert metasyntactic.pop(1) == 'bar'
Esempio n. 7
0
 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')
Esempio n. 8
0
 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]
Esempio n. 9
0
 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'
Esempio n. 10
0
 def test_del(self):
     a = RedisList((-1, 1, 66.25, 333, 333, 1234.5))
     del a[0]
     assert a == [1, 66.25, 333, 333, 1234.5]
     del a[2:4]
     assert a == [1, 66.25, 1234.5]
     del a[:]
     assert a == []
Esempio n. 11
0
    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)
Esempio n. 12
0
 def test_basic_usage(self):
     squares = RedisList((1, 4, 9, 16, 25), redis=self.redis)
     assert squares == [1, 4, 9, 16, 25]
     assert squares[0] == 1
     assert squares[-1] == 25
     assert squares[-3:] == [9, 16, 25]
     assert squares[:] == [1, 4, 9, 16, 25]
     assert squares + [36, 49, 64, 81, 100] == \
         [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
Esempio n. 13
0
 def test_json_dumps(self):
     metasyntactic = RedisList(
         ('foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply',
          'waldo', 'fred', 'plugh', 'xyzzy', 'thud'),
         redis=self.redis,
     )
     assert json.dumps(metasyntactic) == (
         '["foo", "bar", "baz", "qux", "quux", "corge", "grault", "garply", '
         '"waldo", "fred", "plugh", "xyzzy", "thud"]')
Esempio n. 14
0
    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)
Esempio n. 15
0
 def test_mutability_and_append(self):
     cubes = RedisList((1, 8, 27, 65, 125))
     cubes[3] = 64
     assert cubes == [1, 8, 27, 64, 125]
     cubes.append(216)
     cubes.append(7**3)
     assert cubes == [1, 8, 27, 64, 125, 216, 343]
Esempio n. 16
0
 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 == []
Esempio n. 17
0
 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]
Esempio n. 18
0
 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]
Esempio n. 19
0
 def test_insert_left(self):
     squares = RedisList((9, 16, 25))
     squares.insert(-1, 4)
     assert squares == [4, 9, 16, 25]
     squares.insert(0, 1)
     assert squares == [1, 4, 9, 16, 25]
Esempio n. 20
0
 def test_len(self):
     letters = RedisList(('a', 'b', 'c', 'd'))
     assert len(letters) == 4
Esempio n. 21
0
 def test_eq_same_redis_instance_and_key(self):
     squares1 = RedisList((1, 4, 9, 16, 25), key='pottery:squares')
     squares2 = RedisList(key='pottery:squares')
     assert squares1 == squares2
     assert not squares1 != squares2
Esempio n. 22
0
 def test_extend(self):
     squares = RedisList((1, 4, 9))
     squares.extend((16, 25))
     assert squares == [1, 4, 9, 16, 25]
Esempio n. 23
0
 def test_eq_unordered_collection(self):
     squares1 = RedisList((1, ), redis=self.redis)
     squares2 = {1}
     assert not squares1 == squares2
     assert squares1 != squares2
Esempio n. 24
0
 def test_pop_out_of_range(self):
     squares = RedisList((1, 4, 9, 16, 25))
     with self.assertRaises(IndexError):
         squares.pop(len(squares))
Esempio n. 25
0
 def test_eq_typeerror(self):
     squares = RedisList((1, 4, 9, 16, 25), redis=self.redis)
     assert not squares == None
     assert squares != None
Esempio n. 26
0
 def test_eq_unordered_collection(self):
     squares1 = RedisList((1, ), key='pottery:squares')
     squares2 = {1}
     assert not squares1 == squares2
     assert squares1 != squares2
Esempio n. 27
0
 def test_eq_different_items(self):
     squares1 = RedisList((1, 4, 9, 16, 25), key='pottery:squares')
     squares2 = (4, 9, 16, 25, 36)
     assert not squares1 == squares2
     assert squares1 != squares2
Esempio n. 28
0
 def test_eq_same_redis_instance_different_keys(self):
     squares1 = RedisList((1, 4, 9, 16, 25), key='pottery:squares1')
     squares2 = RedisList((1, 4, 9, 16, 25), key='pottery:squares2')
     assert squares1 == squares2
     assert not squares1 != squares2
Esempio n. 29
0
 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]
Esempio n. 30
0
 def test_insert_left(self):
     squares = RedisList((9, 16, 25))
     squares.insert(-1, 4)
     assert squares == [4, 9, 16, 25]
     squares.insert(0, 1)
     assert squares == [1, 4, 9, 16, 25]
Esempio n. 31
0
 def test_keyexistserror(self):
     squares = RedisList((1, 4, 9, 16, 25), redis=self.redis, key=self._KEY)
     squares  # Workaround for Pyflakes.  :-(
     with self.assertRaises(KeyExistsError):
         RedisList((1, 4, 9, 16, 25), redis=self.redis, key=self._KEY)
Esempio n. 32
0
 def test_repr(self):
     squares = RedisList((1, 4, 9, 16, 25))
     assert repr(squares) == 'RedisList[1, 4, 9, 16, 25]'
Esempio n. 33
0
 def test_extend(self):
     squares = RedisList((1, 4, 9))
     squares.extend((16, 25))
     assert squares == [1, 4, 9, 16, 25]
Esempio n. 34
0
 def test_pop_index(self):
     metasyntactic = RedisList((
         'foo', 'bar', 'baz', 'qux', 'quux', 'corge', 'grault', 'garply',
         'waldo', 'fred', 'plugh', 'xyzzy', 'thud',
     ))
     assert metasyntactic.pop(1) == 'bar'
Esempio n. 35
0
 def test_indexerror(self):
     list_ = RedisList()
     with self.assertRaises(IndexError):
         list_[0] = 'raj'
Esempio n. 36
0
 def test_eq_different_items(self):
     squares1 = RedisList((1, 4, 9, 16, 25), redis=self.redis)
     squares2 = (4, 9, 16, 25, 36)
     assert not squares1 == squares2
     assert squares1 != squares2
Esempio n. 37
0
 def test_pop_out_of_range(self):
     squares = RedisList((1, 4, 9, 16, 25))
     with self.assertRaises(IndexError):
         squares.pop(len(squares))
Esempio n. 38
0
 def test_eq_typeerror(self):
     squares = RedisList((1, 4, 9, 16, 25), key='pottery:squares')
     assert not squares == None
     assert squares != None
Esempio n. 39
0
 def test_keyexistserror(self):
     squares = RedisList((1, 4, 9, 16, 25), key='pottery:squares')
     with self.assertRaises(KeyExistsError):
         squares = RedisList((1, 4, 9, 16, 25), key='pottery:squares')