Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
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()