-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_dict_tools.py
71 lines (62 loc) · 1.38 KB
/
test_dict_tools.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
import pytest
from dict_tools import *
def test_map_keys():
myfunc = (lambda x: x+'_suffix')
mydict = {
'fbi': 0,
'open': 1,
'up': 2,
}
myresult = {
'fbi_suffix': 0,
'open_suffix': 1,
'up_suffix': 2,
}
assert map_keys(myfunc, mydict) == myresult
def test_map_values():
myfunc = (lambda x: x+1)
mydict = {
'one': 0,
'two': 1,
'three': 2,
}
myresult = {
'one': 1,
'two': 2,
'three': 3,
}
assert map_values(myfunc, mydict) == myresult
def test_flattened_items():
mydict = {
'ur': ('mum', 'fat'),
'no': ('pomegranates',),
}
myresult = [
('ur', 'mum'),
('ur', 'fat'),
('no', 'pomegranates'),
]
assert [i for i in flattened_items(mydict)] == myresult
def test_invert_dict():
mydict = {
'subscribe to': 'Dull Bananas',
'hotel': 'trivago',
}
myresult = {
'Dull Bananas': 'subscribe to',
'trivago': 'hotel',
}
assert invert_dict(mydict) == myresult
def test_group_by():
assert group_by(
[
('foo', 420),
('bar', 666),
('foo', 69),
('bar', 42),
],
key=lambda value: value[0],
) == {
'foo': [('foo', 420), ('foo', 69)],
'bar': [('bar', 666), ('bar', 42)],
}