def test_keys(self): a = RedisDict(one=1, two=2, three=3) assert isinstance(a.keys(), collections.abc.KeysView) assert len(a) == 3 assert set(a.keys()) == {'one', 'two', 'three'} assert 'one' in a.keys() assert 'four' not in a.keys()
def test_values(self): a = RedisDict(one=1, two=2, three=3) assert isinstance(a.values(), collections.abc.ValuesView) assert len(a) == 3 assert set(a.values()) == {1, 2, 3} assert 1 in a.values() assert 4 not in a.values()
def test_clear(self): a = RedisDict(one=1, two=2, three=3) assert sorted(a) == ['one', 'three', 'two'] assert a.clear() is None assert sorted(a) == [] assert a.clear() is None assert sorted(a) == []
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()
def test_clear(self): a = RedisDict(one=1, two=2, three=3) assert sorted(a) == ['one', 'three', 'two'] assert a.clear() is None assert sorted(a) == [] assert a.clear() is None assert sorted(a) == []
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
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, } a.update(eight=8, nine=9) assert a == { 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9, }
def setUp(self): super().setUp() self.redis = _default_redis self.raj = RedisDict(key='pottery:raj', hobby='music', vegetarian=True) self.nilika = RedisDict(key='pottery:nilika', hobby='music', vegetarian=True) self.luvh = RedisDict(key='luvh', hobby='bullying', vegetarian=False)
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
def test_keyexistserror_str(self): d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098) try: d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098) except KeyExistsError as err: assert str(err) == ( "redis=Pipeline<ConnectionPool<Connection<host=localhost,port=6379,db=0>>> " "key='pottery:tel'") else: self.fail(msg='KeyExistsError not raised')
def test_keyexistserror_repr(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 err: assert repr(err) == ( "KeyExistsError(redis=Pipeline<ConnectionPool<Connection<host=localhost,port=6379,db=0>>>, " "key='pottery:tel')") else: self.fail(msg='KeyExistsError not raised')
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=Redis<ConnectionPool<Connection<host=localhost,port=6379,db=0>>> " "key='pottery:tel'") else: # pragma: no cover self.fail(msg='KeyExistsError not raised')
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']
def test_key_assignment(self): a = RedisDict(one=1, two=2, three=2) assert a['three'] == 2 a['three'] = 3 assert a['three'] == 3 a['four'] = 4 assert a['four'] == 4
def test_keyexistserror_raised(self): d = RedisDict( redis=self.redis, key='pottery:tel', sape=4139, guido=4127, jack=4098, ) d # Workaround for Pyflakes. :-( with self.assertRaises(KeyExistsError): RedisDict( redis=self.redis, key='pottery:tel', sape=4139, guido=4127, jack=4098, )
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
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
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()
def test_values(self): a = RedisDict(one=1, two=2, three=3) assert isinstance(a.values(), collections.abc.ValuesView) assert len(a) == 3 assert set(a.values()) == {1, 2, 3} assert 1 in a.values() assert 4 not in a.values()
def test_keys(self): a = RedisDict(one=1, two=2, three=3) assert isinstance(a.keys(), collections.abc.KeysView) assert len(a) == 3 assert set(a.keys()) == {'one', 'two', 'three'} assert 'one' in a.keys() assert 'four' not in a.keys()
def compare_to_potteryx(): client = Redis.from_url('redis://localhost:6379/') pottery_dict = RedisDict(redis=client, key='pottery') info = {"title": "REEM vs Pottery", "plots": [], "x_label": "Package", "y_label": "Latency (ms)"} data = nested_level_dictionary( levels=5, data=single_level_dictionary( copies=100, data={ "single_key": "".join(["A" for i in range(10 ** 2)]), "nested_data": { "subkey": "".join(["A" for i in range(10 ** 2)]) } } ) ) # REEM Set p = { "ticker_label": "REEM Set", "times": multitrial_time_test(set, {"keys": ["pottery_comparison"], "value": data}, iterations=100) } info["plots"].append(p) # Pottery Set p = { "ticker_label": "Pottery Set", "times": multitrial_time_test(set_pottery, {"redis_dict": pottery_dict, "value": data}, iterations=100) } info["plots"].append(p) reem_read_path = path_to_key_sequence(".pottery_comparison.sub_0.sub_1.sub_2.sub_3.sub_4.copy_0_single_key") pottery_read_path = path_to_key_sequence(".data.sub_0.sub_1.sub_2.sub_3.sub_4.copy_0_single_key") # REEM Get p = { "ticker_label": "REEM Get", "times": multitrial_time_test(get, {"keys": reem_read_path}, iterations=100) } info["plots"].append(p) # Pottery Get p = { "ticker_label": "Pottery Get", "times": multitrial_time_test(get_pottery, {"redis_dict": pottery_dict, "keys": pottery_read_path}, iterations=100) } info["plots"].append(p) plot_performance(info)
def test_keyexistserror_repr(self): d = RedisDict( redis=self.redis, key='pottery:tel', sape=4139, guido=4127, jack=4098, ) d # Workaround for Pyflakes. :-( try: RedisDict( redis=self.redis, key='pottery:tel', sape=4139, guido=4127, jack=4098, ) except KeyExistsError as wtf: assert repr(wtf) == ( f"KeyExistsError(redis=Redis<ConnectionPool<Connection<host=localhost,port=6379,db={self.redis_db}>>>, " "key='pottery:tel')") else: # pragma: no cover self.fail(msg='KeyExistsError not raised')
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']
def test_update(self): a = RedisDict(one=1, two=2, three=3) a.update() assert a == {'one': 1, 'two': 2, 'three': 3}
def test_init_with_kwargs(self): d = RedisDict(sape=4139, guido=4127, jack=4098) assert d == {'sape': 4139, 'jack': 4098, 'guido': 4127}
def test_init_with_key_value_pairs(self): d = RedisDict([('sape', 4139), ('guido', 4127), ('jack', 4098)]) assert d == {'sape': 4139, 'jack': 4098, 'guido': 4127}
def __init__(self, redis_url): self.redis = Redis.from_url(redis_url) self.phashdb = RedisDict(redis=self.redis, key='phashdb') # blacklist self.whashdb = RedisDict(redis=self.redis, key='whashdb') # blacklist self.phashdb_clean = RedisDict(redis=self.redis, key='phashdb_clean') # whitelist self.whashdb_clean = RedisDict(redis=self.redis, key='whashdb_clean') # whitelist
def test_membership_for_non_jsonifyable_element(self): redis_dict = RedisDict() assert not BaseException in redis_dict
def test_update(self): a = RedisDict(one=1, two=2, three=3) a.update() assert a == {'one': 1, 'two': 2, 'three': 3}
def test_get(self): a = RedisDict(one=1, two=2, three=3) assert a.get('one') == 1 assert a.get('one', 42) == 1 assert a.get('two') == 2 assert a.get('two', 42) == 2 assert a.get('three') == 3 assert a.get('three', 42) == 3 assert a.get('four') is None assert a.get('four', 42) == 42 a['four'] = 4 assert a.get('four') == 4 assert a.get('four', 42) == 4 del a['four'] assert a.get('four') is None assert a.get('four', 42) == 42
def test_get(self): a = RedisDict(one=1, two=2, three=3) assert a.get('one') == 1 assert a.get('one', 42) == 1 assert a.get('two') == 2 assert a.get('two', 42) == 2 assert a.get('three') == 3 assert a.get('three', 42) == 3 assert a.get('four') is None assert a.get('four', 42) == 42 a['four'] = 4 assert a.get('four') == 4 assert a.get('four', 42) == 4 del a['four'] assert a.get('four') is None assert a.get('four', 42) == 42
def scope(): raj = RedisDict(hobby='music', vegetarian=True) assert self.redis.exists(raj.key) return raj.key
def test_repr(self): a = RedisDict(one=1, two=2) assert repr(a) in { "RedisDict{'one': 1, 'two': 2}", "RedisDict{'two': 2, 'one': 1}", }
def test_json_dumps(self): a = RedisDict(one=1, two=2, three=3) assert json.dumps(a) == '{"one": 1, "two": 2, "three": 3}'
def test_keyexistserror_raised(self): d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098) with self.assertRaises(KeyExistsError): d = RedisDict(key='pottery:tel', sape=4139, guido=4127, jack=4098)
def test_iter(self): garbage = RedisDict() for num in range(1024): garbage[num] = num assert set(iter(garbage)) == set(range(1024))