forked from KeyviDev/keyvi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterators_test.py
More file actions
80 lines (64 loc) · 2.78 KB
/
iterators_test.py
File metadata and controls
80 lines (64 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from test_tools import tmp_dictionary
import sys
import os
import json
import warnings
from keyvi.compiler import JsonDictionaryCompiler
TEST_DEPRECATIONS = os.getenv("KEYVI_SKIP_TEST_DEPRECATIONS") != "1"
root = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(root, "../"))
key_values = [("a", {"a": 2}), ("b", {"b": 2}), ("c", {"c": 2}), ("d", {"d": 2})]
def generate_dictionary_compiler():
dictionary_compiler = JsonDictionaryCompiler({"memory_limit_mb": "10"})
for key, value in key_values:
dictionary_compiler.add(key, json.dumps(value))
return dictionary_compiler
def test_keys():
with tmp_dictionary(
generate_dictionary_compiler(), "test_keys.kv"
) as keyvi_dictionary:
for (base_key, _), keyvi_key in zip(key_values, keyvi_dictionary.keys()):
assert base_key == keyvi_key
if TEST_DEPRECATIONS:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
for (base_key, _), keyvi_key in zip(
key_values, keyvi_dictionary.GetAllKeys()
):
assert base_key == keyvi_key
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
def test_values():
with tmp_dictionary(
generate_dictionary_compiler(), "test_values.kv"
) as keyvi_dictionary:
for (_, base_value), keyvi_value in zip(key_values, keyvi_dictionary.values()):
assert base_value == keyvi_value
if TEST_DEPRECATIONS:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
for (_, base_value), keyvi_value in zip(
key_values, keyvi_dictionary.GetAllValues()
):
assert base_value == keyvi_value
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)
def test_items():
with tmp_dictionary(
generate_dictionary_compiler(), "test_items.kv"
) as keyvi_dictionary:
for (base_key, base_value), (keyvi_key, keyvi_value) in zip(
key_values, keyvi_dictionary.items()
):
assert base_key == keyvi_key
assert base_value == keyvi_value
if TEST_DEPRECATIONS:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
for (base_key, base_value), (keyvi_key, keyvi_value) in zip(
key_values, keyvi_dictionary.GetAllItems()
):
assert base_key == keyvi_key
assert base_value == keyvi_value
assert len(w) == 1
assert issubclass(w[-1].category, DeprecationWarning)