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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/usr/bin/env python2
'''
Unit tests for MultiInventory
'''
import unittest
import multi_inventory
# Removing invalid variable names for tests so that I can
# keep them brief
# pylint: disable=invalid-name
class MultiInventoryTest(unittest.TestCase):
'''
Test class for multiInventory
'''
# def setUp(self):
# '''setup method'''
# pass
def test_merge_simple_1(self):
'''Testing a simple merge of 2 dictionaries'''
a = {"key1" : 1}
b = {"key1" : 2}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": [1, 2]})
def test_merge_b_empty(self):
'''Testing a merge of an emtpy dictionary'''
a = {"key1" : 1}
b = {}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": 1})
def test_merge_a_empty(self):
'''Testing a merge of an emtpy dictionary'''
b = {"key1" : 1}
a = {}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": 1})
def test_merge_hash_array(self):
'''Testing a merge of a dictionary and a dictionary with an array'''
a = {"key1" : {"hasha": 1}}
b = {"key1" : [1, 2]}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": [{"hasha": 1}, 1, 2]})
def test_merge_array_hash(self):
'''Testing a merge of a dictionary with an array and a dictionary with a hash'''
a = {"key1" : [1, 2]}
b = {"key1" : {"hasha": 1}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": [1, 2, {"hasha": 1}]})
def test_merge_keys_1(self):
'''Testing a merge on a dictionary for keys'''
a = {"key1" : [1, 2], "key2" : {"hasha": 2}}
b = {"key2" : {"hashb": 1}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"key1": [1, 2], "key2": {"hasha": 2, "hashb": 1}})
def test_merge_recursive_1(self):
'''Testing a recursive merge'''
a = {"a" : {"b": {"c": 1}}}
b = {"a" : {"b": {"c": 2}}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"a": {"b": {"c": [1, 2]}}})
def test_merge_recursive_array_item(self):
'''Testing a recursive merge for an array'''
a = {"a" : {"b": {"c": [1]}}}
b = {"a" : {"b": {"c": 2}}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"a": {"b": {"c": [1, 2]}}})
def test_merge_recursive_hash_item(self):
'''Testing a recursive merge for a hash'''
a = {"a" : {"b": {"c": {"d": 1}}}}
b = {"a" : {"b": {"c": 2}}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"a": {"b": {"c": [{"d": 1}, 2]}}})
def test_merge_recursive_array_hash(self):
'''Testing a recursive merge for an array and a hash'''
a = {"a" : [{"b": {"c": 1}}]}
b = {"a" : {"b": {"c": 1}}}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"a": [{"b": {"c": 1}}]})
def test_merge_recursive_hash_array(self):
'''Testing a recursive merge for an array and a hash'''
a = {"a" : {"b": {"c": 1}}}
b = {"a" : [{"b": {"c": 1}}]}
result = {}
_ = [multi_inventory.MultiInventory.merge_destructively(result, x) for x in [a, b]]
self.assertEqual(result, {"a": [{"b": {"c": 1}}]})
# def tearDown(self):
# '''TearDown method'''
# pass
if __name__ == "__main__":
unittest.main()
|