forked from dask/dask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_sharedict.py
82 lines (54 loc) · 1.53 KB
/
test_sharedict.py
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
81
82
from collections import Mapping
import pytest
from toolz import merge
from dask.sharedict import ShareDict
a = {'x': 1, 'y': 2}
b = {'z': 3}
c = {'w': 2}
def test_core():
s = ShareDict()
assert isinstance(s, Mapping)
s.update(a)
s.update(b)
assert s['x'] == 1
with pytest.raises(KeyError):
s['abc']
with pytest.raises((NotImplementedError, TypeError)):
s['abc'] = 123
def test_structure():
s = ShareDict()
s.update(a)
s.update(b)
s.update(c)
assert all(any(d is x for d in s.dicts.values())
for x in [a, b, c])
@pytest.mark.skip
def test_structure_2():
s = ShareDict()
s.update_with_key(a, key='a')
s.update_with_key(b, key='b')
s.update_with_key(c, key='c')
assert s.order == ['a', 'b', 'c']
s.update_with_key(b, key='b')
assert s.order == ['a', 'c', 'b']
def test_keys_items():
s = ShareDict()
s.update_with_key(a, key='a')
s.update_with_key(b, key='b')
s.update_with_key(c, key='c')
d = merge(a, b, c)
for fn in [dict, set, len]:
assert fn(s) == fn(d)
for fn in [lambda x: x.values(), lambda x: x.keys(), lambda x: x.items()]:
assert set(fn(s)) == set(fn(d))
def test_update_with_sharedict():
s = ShareDict()
s.update_with_key(a, key='a')
s.update_with_key(b, key='b')
s.update_with_key(c, key='c')
d = {'z': 5}
s2 = ShareDict()
s2.update_with_key(a, key='a')
s2.update_with_key(d, key='d')
s.update(s2)
assert s.dicts['a'] is s.dicts['a']