How to use the pottery.RedisDict function in pottery

To help you get started, we’ve selected a few pottery examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github brainix / pottery / tests / test_dict.py View on Github external
def test_more_construction_options(self):
        a = RedisDict(one=1, two=2, three=3)
        b = {'one': 1, 'two': 2, 'three': 3}
        c = RedisDict(zip(['one', 'two', 'three'], [1, 2, 3]))
        d = RedisDict([('two', 2), ('one', 1), ('three', 3)])
        e = RedisDict({'three': 3, 'one': 1, 'two': 2})
        assert a == b == c == d == e
github brainix / pottery / tests / test_dict.py View on Github external
def test_keyexistserror_str(self):
        d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098)
        d   # Workaround for Pyflakes.  :-(
        try:
            RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098)
        except KeyExistsError as wtf:
            assert str(wtf) == (
                "redis=Pipeline>> "
                "key='pottery:tel'"
            )
        else:  # pragma: no cover
            self.fail(msg='KeyExistsError not raised')
github brainix / pottery / tests / test_dict.py View on Github external
def test_key_deletion(self):
        a = RedisDict(one=1, two=2, three=3)
        assert sorted(a) == ['one', 'three', 'two']
        a['four'] = 4
        assert sorted(a) == ['four', 'one', 'three', 'two']
        with self.assertRaises(KeyError):
            del a['five']
        del a['four']
        assert sorted(a) == ['one', 'three', 'two']
        del a['three']
        assert sorted(a) == ['one', 'two']
        del a['two']
        assert sorted(a) == ['one']
        del a['one']
        assert sorted(a) == []
        with self.assertRaises(KeyError):
            del a['one']
github brainix / pottery / tests / test_dict.py View on Github external
def test_len(self):
        a = RedisDict()
        assert len(a) == 0
        a = RedisDict(one=1, two=2, three=3)
        assert len(a) == 3
        a['four'] = 4
        assert len(a) == 4
        del a['four']
        assert len(a) == 3
github brainix / pottery / tests / test_dict.py View on Github external
def test_update(self):
        a = RedisDict(one=1, two=2, three=3)
        a.update()
        assert a == {'one': 1, 'two': 2, 'three': 3}

        a.update({'four': 4, 'five': 5})
        assert a == {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5}

        a.update((('six', 6), ('seven', 7)))
        assert a == {
            'one': 1,
            'two': 2,
            'three': 3,
            'four': 4,
            'five': 5,
            'six': 6,
            'seven': 7,
        }
github brainix / pottery / tests / test_dict.py View on Github external
def test_keyexistserror_raised(self):
        d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098)
        d   # Workaround for Pyflakes.  :-(
        with self.assertRaises(KeyExistsError):
            RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098)
github brainix / pottery / tests / test_dict.py View on Github external
def test_key_membership(self):
        a = RedisDict(one=1, two=2, three=3)
        assert 'one' in a
        assert 'four' not in a
        assert not 'four' in a
        a['four'] = 4
        assert 'four' in a
        del a['four']
        assert 'four' not in a
        assert not 'four' in a
github brainix / pottery / tests / test_dict.py View on Github external
def test_keyerror(self):
        a = RedisDict(one=1, two=2, three=3)
        assert a['one'] == 1
        assert a['two'] == 2
        assert a['three'] == 3
        with self.assertRaises(KeyError):
            a['four']
github brainix / pottery / tests / test_dict.py View on Github external
def test_items(self):
        a = RedisDict(one=1, two=2, three=3)
        assert isinstance(a.items(), collections.abc.ItemsView)
        assert len(a) == 3
        assert set(a.items()) == {('one', 1), ('two', 2), ('three', 3)}
        assert ('one', 1) in a.items()
        assert ('four', 4) not in a.items()
github brainix / pottery / tests / test_dict.py View on Github external
def test_basic_usage(self):
        tel = RedisDict(jack=4098, sape=4139)
        tel['guido'] = 4127
        assert tel == {'sape': 4139, 'guido': 4127, 'jack': 4098}
        assert tel['jack'] == 4098
        del tel['sape']
        tel['irv'] = 4127
        assert tel == {'guido': 4127, 'irv': 4127, 'jack': 4098}
        assert sorted(tel) == ['guido', 'irv', 'jack']
        assert 'guido' in tel
        assert not 'jack' not in tel