def test_dict_list_handler(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) dict1 = {} for j in range(repeats): # fill with some random data for i in range(10): dict1[str(uuid4())] = str(uuid4()) dict1[str(uuid4())] = np.random.rand(1)[0] # test normal dict key = str(uuid4()) db.set(key, dict1) dict2 = db.get(key) for key, value1 in dict1.items(): value2 = dict2[key] assert value1 == value2 # test OrderedDict key = str(uuid4()) db.set(key, OrderedDict(dict1)) dict2 = db.get(key) for key, value1 in dict1.items(): value2 = dict2[key] assert value1 == value2 db.delete_db() db.close()
def test_col(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for num in np.random.randint(0, 100, size=(repeats)): key = str(uuid4()) db.set(key, int(num), col=1) db.set(key, int(num) + 3, col='test') value = db.get(key) assert value is None value = db.get(key, col=1) assert value == num, 'Int value from redisk different from the expected value!' value = db.get(key, col='test') assert value == num + 3, 'Int value from redisk different from the expected value!' db.delete_db()
def test_string_handler(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for i in range(repeats): expected = str(uuid4()) key = str(uuid4()) db.set(key, expected) value = db.get(key) assert value == expected, 'String value from redisk different from the expected value!'
def test_numpy_handler_2D(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for arr in np.random.rand(repeats, 10, 5): key = str(uuid4()) db.set(key, arr) value = db.get(key) assert type(value) == type(arr), 'Types are different' np.testing.assert_array_equal(value, arr, 'Arrays are not equal!') db.delete_db()
def test_int_list_handler(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for num in np.random.randint(0, 100, size=(repeats, 10)): num = num.tolist() key = str(uuid4()) db.set(key, num) value = db.get(key) assert type(value) == type(num), 'Types are different' assert len(value) == 10, 'Length is different' assert type(value[0]) == type(num[0]), 'Inner types are different' for x1, x2 in zip(value, num): assert x1 == x2, 'Int value from redisk different from the expected value!' db.delete_db()
def test_int_str_handler(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for major in range(repeats): data = [] for minor in range(10): data.append(str(uuid4())) key = str(uuid4()) db.set(key, data) value = db.get(key) assert type(value) == type(data), 'Types are different' assert len(value) == 10, 'Length is different' assert type(value[0]) == type(data[0]), 'Inner types are different' for x1, x2 in zip(value, data): assert x1 == x2, 'String value from redisk different from the expected value!' db.delete_db()
def test_key_iter(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) keys = [str(uuid4()) for i in range(10)] cols = [str(uuid4()) for i in range(10)] values = [str(uuid4()) for i in range(10)] for key, col, value in zip(keys, cols, values): db.set(key, value, col=col) keys, cols, values = set(keys), set(cols), set(values) count = 0 for key, col in db.key_col_pairs(): value = db.get(key, col=col) count += 1 if (key in keys and col in cols and value in values) else 0 assert count == 10 db.delete_db()
def test_close_open(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) keys = [] expects = [] for i in range(repeats): expected = str(uuid4()) key = str(uuid4()) db.set(key, expected) keys.append(key) expects.append(expected) db.close() tbl.close_connection() tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) for key, expected in zip(keys, expects): value = db.get(key) assert value == expected, 'String value from redisk different from the expected value!' db.delete_db()
def test_append(): tbl = Table(name='test', base_dir=base_path) db = Redisk(tbl) length = 3 data = [] for i in range(repeats): key = str(uuid4()) lvalues = np.random.randint(0, 100, size=(10)).tolist() data.append((key, lvalues)) for num in lvalues: db.append(key, num, length) db.close() for key, expected in data: value = db.get(key) assert type(value) == type(expected), 'Types are different' assert len(value) == 10, 'Length is different' assert type(value[0]) == type(expected[0]), 'Inner types are different' for x1, x2 in zip(value, expected): assert x1 == x2, 'Int value from redisk different from the expected value!' db.delete_db()