-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_utils.py
More file actions
95 lines (77 loc) · 2.82 KB
/
test_utils.py
File metadata and controls
95 lines (77 loc) · 2.82 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import unittest
from api import utils
class TestUtils(unittest.TestCase):
"""Test utils functions"""
def test_dict_merge_not_dict(self):
"""
second item is not a dict, which dict_merge will just return
"""
a = {'key': 'value'}
b = 'somethig'
c = utils.dict_merge(a, b)
self.assertEqual(c, b)
def test_dict_merge_simple(self):
a = {'key': 'value'}
b = {'key': 'value'}
c = utils.dict_merge(a, b)
self.assertEqual(c, {'key': 'value'})
a = {'key': 'value'}
b = {'key2': 'value'}
c = utils.dict_merge(a, b)
self.assertEqual(c, {'key': 'value', 'key2': 'value'})
def test_dict_merge_deeper(self):
a = {'key': 'value', 'here': {'without': 'you'}}
b = {'this': 'that', 'here': {'with': 'me'}, 'other': {'magic', 'unicorn'}}
c = utils.dict_merge(a, b)
self.assertEqual(c, {
'key': 'value',
'this': 'that',
'here': {
'with': 'me',
'without': 'you'
},
'other': {'magic', 'unicorn'}
})
def test_dict_merge_even_deeper(self):
a = {
'key': 'value',
'here': {'without': 'you'},
'other': {'scrubs': {'char3': 'Cox'}}
}
b = {
'this': 'that',
'here': {'with': 'me'},
'other': {'magic': 'unicorn', 'scrubs': {'char1': 'JD', 'char2': 'Turk'}}
}
c = utils.dict_merge(a, b)
self.assertEqual(c, {
'key': 'value',
'this': 'that',
'here': {'with': 'me', 'without': 'you'},
'other': {
'magic': 'unicorn',
'scrubs': {
'char1': 'JD',
'char2': 'Turk',
'char3': 'Cox'
}
}
})
def test_dict_merge_with_list(self):
a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
b = {'key': 'value', 'names': ['kenny', 'cartman', 'stan']}
c = utils.dict_merge(a, b)
self.assertEqual(c, {'key': 'value', 'names': ['bob', 'kyle', 'kenny',
'jimbo', 'cartman', 'stan']})
a = {'key': 'value', 'names': ['bob', 'kyle', 'kenny', 'jimbo']}
b = {'key': 'value', 'last_names': ['kenny', 'cartman', 'stan']}
c = utils.dict_merge(a, b)
self.assertEqual(c, {'key': 'value',
'names': ['bob', 'kyle', 'kenny', 'jimbo'],
'last_names': ['kenny', 'cartman', 'stan']})
def test_dict_merge_bad_merge(self):
"""Returns b because it isn't a dict"""
a = {'key': 'value'}
b = 'duh'
c = utils.dict_merge(a, b)
self.assertEqual(c, b)