Esempio n. 1
0
 def test_discard(self):
     basket = RedisSet(
         {'apple', 'orange', 'apple', 'pear', 'orange', 'banana', 'tomato'})
     basket.discard('tomato')
     assert basket == {
         'apple', 'orange', 'apple', 'pear', 'orange', 'banana'
     }
Esempio n. 2
0
 def test_discard(self):
     basket = RedisSet({
         'apple', 'orange', 'apple', 'pear', 'orange', 'banana', 'tomato',
     })
     basket.discard('tomato')
     assert basket == {
         'apple', 'orange', 'apple', 'pear', 'orange', 'banana',
     }
Esempio n. 3
0
 def test_add(self):
     basket = RedisSet({
         'apple', 'orange', 'apple', 'pear', 'orange', 'banana',
     })
     basket.add('tomato')
     assert basket == {
         'apple', 'orange', 'apple', 'pear', 'orange', 'banana', 'tomato',
     }
Esempio n. 4
0
    def test_repr(self):
        basket = RedisSet({'apple'})
        assert repr(basket) == "RedisSet{'apple'}"

        basket = RedisSet({'apple', 'orange'})
        assert repr(basket) in {
            "RedisSet{'apple', 'orange'}",
            "RedisSet{'orange', 'apple'}",
        }
Esempio n. 5
0
    def test_isdisjoint(self):
        a = RedisSet('abc')
        b = RedisSet('cde')
        assert not a.isdisjoint(b)
        c = RedisSet('def')
        assert a.isdisjoint(c)

        d = {'c', 'd', 'e'}
        assert not a.isdisjoint(d)
        e = {'d', 'e', 'f'}
        assert a.isdisjoint(e)
Esempio n. 6
0
    def test_pop(self):
        fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
        basket = RedisSet(fruits)
        for _ in range(len(fruits)):
            fruit = basket.pop()
            assert fruit in fruits
            fruits.discard(fruit)

        assert not fruits
        assert not basket
        with self.assertRaises(KeyError):
            basket.pop()
Esempio n. 7
0
 def test_set_operations(self):
     a = RedisSet('abracadabra')
     b = RedisSet('alacazam')
     assert a == {'a', 'r', 'b', 'c', 'd'}
     assert a - b == {'r', 'd', 'b'}
     assert isinstance(a - b, RedisSet)
     assert a | b == {'a', 'c', 'r', 'd', 'b', 'm', 'z', 'l'}
     assert isinstance(a | b, RedisSet)
     assert a & b == {'a', 'c'}
     assert isinstance(a & b, RedisSet)
     assert a ^ b == {'r', 'd', 'b', 'm', 'z', 'l'}
     assert isinstance(a ^ b, RedisSet)
Esempio n. 8
0
    def test_pop(self):
        fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
        basket = RedisSet(fruits)
        for _ in range(len(fruits)):
            fruit = basket.pop()
            assert fruit in fruits
            fruits.discard(fruit)

        assert not fruits
        assert not basket
        with self.assertRaises(KeyError):
            basket.pop()
Esempio n. 9
0
 def test_add(self):
     fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
     basket = RedisSet(fruits, redis=self.redis)
     basket.add('tomato')
     assert basket == {
         'apple',
         'orange',
         'apple',
         'pear',
         'orange',
         'banana',
         'tomato',
     }
Esempio n. 10
0
    def test_difference_update_with_empty_set(self):
        ramanujans_friends = RedisSet(redis=self.redis)
        ramanujans_friends.difference_update(set())
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10), redis=self.redis)
        ramanujans_friends.difference_update(set())
        assert ramanujans_friends == {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Esempio n. 11
0
    def test_update_with_no_arguments(self):
        s = RedisSet()
        s.update()
        assert s == set()

        s = RedisSet('abcd')
        s.update()
        assert s == {'a', 'b', 'c', 'd'}
Esempio n. 12
0
    def test_update_with_empty_set(self):
        metasyntactic_variables = RedisSet()
        metasyntactic_variables.update(set())
        assert metasyntactic_variables == set()

        metasyntactic_variables = RedisSet({'foo', 'bar', 'baz'})
        metasyntactic_variables.update(set())
        assert metasyntactic_variables == {'foo', 'bar', 'baz'}
Esempio n. 13
0
    def test_difference_update_with_set(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update({5, 6, 7, 8, 9})
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update({5, 6, 7, 8, 9})
        assert ramanujans_friends == {0, 1, 2, 3, 4}
Esempio n. 14
0
    def test_difference_update_with_range(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update(range(5))
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update(range(5))
        assert ramanujans_friends == {5, 6, 7, 8, 9}
Esempio n. 15
0
    def test_difference_update_with_range_and_set(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update(range(4), {6, 7, 8, 9})
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update(range(4), {6, 7, 8, 9})
        assert ramanujans_friends == {4, 5}
Esempio n. 16
0
    def test_remove(self):
        basket = RedisSet({'apple', 'orange'})
        basket.remove('orange')
        assert basket == {'apple'}

        basket.remove('apple')
        assert basket == set()

        with self.assertRaises(KeyError):
            basket.remove('apple')
Esempio n. 17
0
    def test_isdisjoint(self):
        a = RedisSet('abc')
        b = RedisSet('cde')
        assert not a.isdisjoint(b)
        c = RedisSet('def')
        assert a.isdisjoint(c)

        d = {'c', 'd', 'e'}
        assert not a.isdisjoint(d)
        e = {'d', 'e', 'f'}
        assert a.isdisjoint(e)
Esempio n. 18
0
    def test_remove(self):
        basket = RedisSet({'apple', 'orange'})
        basket.remove('orange')
        assert basket == {'apple'}

        basket.remove('apple')
        assert basket == set()

        with self.assertRaises(KeyError):
            basket.remove('apple')
Esempio n. 19
0
    def test_difference_update_with_range(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update(range(5))
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update(range(5))
        assert ramanujans_friends == {5, 6, 7, 8, 9}
Esempio n. 20
0
    def test_difference_update_with_range_and_set(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update(range(4), {6, 7, 8, 9})
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update(range(4), {6, 7, 8, 9})
        assert ramanujans_friends == {4, 5}
Esempio n. 21
0
    def test_difference_update_with_set(self):
        ramanujans_friends = RedisSet()
        ramanujans_friends.difference_update({5, 6, 7, 8, 9})
        assert ramanujans_friends == set()

        ramanujans_friends = RedisSet(range(10))
        ramanujans_friends.difference_update({5, 6, 7, 8, 9})
        assert ramanujans_friends == {0, 1, 2, 3, 4}
Esempio n. 22
0
    def test_update_with_empty_set(self):
        metasyntactic_variables = RedisSet()
        metasyntactic_variables.update(set())
        assert metasyntactic_variables == set()

        metasyntactic_variables = RedisSet({'foo', 'bar', 'baz'})
        metasyntactic_variables.update(set())
        assert metasyntactic_variables == {'foo', 'bar', 'baz'}
Esempio n. 23
0
    def test_update_with_no_arguments(self):
        s = RedisSet()
        s.update()
        assert s == set()

        s = RedisSet('abcd')
        s.update()
        assert s == {'a', 'b', 'c', 'd'}
Esempio n. 24
0
 def test_issuperset(self):
     a = RedisSet('abc')
     b = RedisSet('abc')
     # assert a.issuperset(b)
     # assert b.issuperset(a)
     assert a >= b
     assert b >= a
     assert not a > b
     assert not b > a
     c = RedisSet('abcd')
     # assert not a.issuperset(c)
     # assert c.issuperset(a)
     assert not a >= c
     assert c >= a
     assert not a > c
     assert c > a
     d = RedisSet('def')
     # assert not a.issuperset(d)
     # assert not d.issuperset(a)
     assert not a >= d
     assert not d >= a
     assert not a > d
     assert not d > a
Esempio n. 25
0
 def test_issubset(self):
     a = RedisSet('abc')
     b = RedisSet('abc')
     # assert a.issubset(b)
     # assert b.issubset(a)
     assert a <= b
     assert b <= a
     assert not a < b
     assert not b < a
     c = RedisSet('abcd')
     # assert a.issubset(c)
     # assert not c.issubset(a)
     assert a <= c
     assert not c <= a
     assert a < c
     assert not c < a
     d = RedisSet('def')
     # assert not a.issubset(d)
     # assert not d.issubset(a)
     assert not a <= d
     assert not d <= a
     assert not a < d
     assert not d < a
Esempio n. 26
0
 def test_update_with_set(self):
     metasyntactic_variables = RedisSet()
     metasyntactic_variables.update({'foo', 'bar', 'baz'})
     assert metasyntactic_variables == {'foo', 'bar', 'baz'}
     metasyntactic_variables.update({'qux'})
     assert metasyntactic_variables == {'foo', 'bar', 'baz', 'qux'}
Esempio n. 27
0
 def test_update_with_range(self):
     ramanujans_friends = RedisSet()
     ramanujans_friends.update(range(10))
     assert ramanujans_friends == {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Esempio n. 28
0
 def test_update_with_set_and_range(self):
     silliness = RedisSet()
     silliness.update({'foo', 'bar', 'baz'}, range(5))
     assert silliness == {'foo', 'bar', 'baz', 0, 1, 2, 3, 4}
     silliness.update({'qux'}, range(6))
     assert silliness == {'foo', 'bar', 'baz', 'qux', 0, 1, 2, 3, 4, 5}
Esempio n. 29
0
 def test_keyexistserror(self):
     fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
     basket = RedisSet(fruits, key='pottery:basket')
     basket  # Workaround for Pyflakes.  :-(
     with self.assertRaises(KeyExistsError):
         RedisSet(fruits, key='pottery:basket')
Esempio n. 30
0
 def test_update_with_range(self):
     ramanujans_friends = RedisSet()
     ramanujans_friends.update(range(10))
     assert ramanujans_friends == {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Esempio n. 31
0
 def test_membership_for_non_jsonifyable_element(self):
     redis_set = RedisSet(redis=self.redis)
     assert not BaseException in redis_set
Esempio n. 32
0
    def test_isdisjoint(self):
        a = RedisSet('abc')
        b = RedisSet('cde')
        assert not a.isdisjoint(b)
        c = RedisSet('def')
        assert a.isdisjoint(c)

        other_url = 'redis://127.0.0.1:6379/'
        other_redis = Redis.from_url(other_url, socket_timeout=1)
        b = RedisSet('cde', redis=other_redis)
        assert not a.isdisjoint(b)
        c = RedisSet('def', redis=other_redis)
        assert a.isdisjoint(c)

        d = {'c', 'd', 'e'}
        assert not a.isdisjoint(d)
        e = {'d', 'e', 'f'}
        assert a.isdisjoint(e)
Esempio n. 33
0
 def test_basic_usage(self):
     fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
     basket = RedisSet(fruits)
     assert basket == {'orange', 'banana', 'pear', 'apple'}
     assert 'orange' in basket
     assert not 'crabgrass' in basket
Esempio n. 34
0
 def test_init(self):
     set_ = RedisSet()
     assert set_ == set()
Esempio n. 35
0
 def test_update_with_set_and_range(self):
     silliness = RedisSet()
     silliness.update({'foo', 'bar', 'baz'}, range(5))
     assert silliness == {'foo', 'bar', 'baz', 0, 1, 2, 3, 4}
     silliness.update({'qux'}, range(6))
     assert silliness == {'foo', 'bar', 'baz', 'qux', 0, 1, 2, 3, 4, 5}
Esempio n. 36
0
 def test_update_with_set(self):
     metasyntactic_variables = RedisSet()
     metasyntactic_variables.update({'foo', 'bar', 'baz'})
     assert metasyntactic_variables == {'foo', 'bar', 'baz'}
     metasyntactic_variables.update({'qux'})
     assert metasyntactic_variables == {'foo', 'bar', 'baz', 'qux'}
Esempio n. 37
0
 def test_keyexistserror(self):
     fruits = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'}
     basket = RedisSet(fruits, key='pottery:basket')
     with self.assertRaises(KeyExistsError):
         basket = RedisSet(fruits, key='pottery:basket')
Esempio n. 38
0
 def test_init(self):
     set_ = RedisSet(redis=self.redis)
     assert set_ == set()