Esempio n. 1
0
 def test_merge_list_traditional(self):
     """
     Test traditional list merge, where a key present in dict2 will be converted
     to a list
     """
     mdict = copy.deepcopy(self.dict1)
     mdict["A"] = ["B", "b"]
     ret = dictupdate.merge_list(copy.deepcopy(self.dict1), {"A": "b"})
     self.assertEqual(mdict, ret)
Esempio n. 2
0
 def test_merge_list_traditional(self):
     '''
     Test traditional list merge, where a key present in dict2 will be converted
     to a list
     '''
     mdict = copy.deepcopy(self.dict1)
     mdict['A'] = ['B', 'b']
     ret = dictupdate.merge_list(copy.deepcopy(self.dict1), {'A': 'b'})
     self.assertEqual(mdict, ret)
Esempio n. 3
0
 def test_merge_list_traditional(self):
     '''
     Test traditional list merge, where a key present in dict2 will be converted
     to a list
     '''
     mdict = copy.deepcopy(self.dict1)
     mdict['A'] = ['B', 'b']
     ret = dictupdate.merge_list(copy.deepcopy(self.dict1), {'A': 'b'})
     self.assertEqual(mdict, ret)
Esempio n. 4
0
    def test_merge_list_append(self):
        '''
        This codifies the intended behaviour that items merged into a dict val that is already
        a list that those items will *appended* to the list, and not magically merged in
        '''
        mdict = copy.deepcopy(self.dict1)
        mdict['A'] = ['B', 'b', 'c']

        # Prepare a modified copy of dict1 that has a list as a val for the key of 'A'
        mdict1 = copy.deepcopy(self.dict1)
        mdict1['A'] = ['B']
        ret = dictupdate.merge_list(mdict1, {'A': ['b', 'c']})
        self.assertEqual({'A': [['B'], ['b', 'c']], 'C': {'D': 'E', 'F': {'I': 'J', 'G': 'H'}}}, ret)
Esempio n. 5
0
    def test_merge_list_append(self):
        '''
        This codifies the intended behaviour that items merged into a dict val that is already
        a list that those items will *appended* to the list, and not magically merged in
        '''
        mdict = copy.deepcopy(self.dict1)
        mdict['A'] = ['B', 'b', 'c']

        # Prepare a modified copy of dict1 that has a list as a val for the key of 'A'
        mdict1 = copy.deepcopy(self.dict1)
        mdict1['A'] = ['B']
        ret = dictupdate.merge_list(mdict1, {'A': ['b', 'c']})
        self.assertEqual({'A': [['B'], ['b', 'c']], 'C': {'D': 'E', 'F': {'I': 'J', 'G': 'H'}}}, ret)
Esempio n. 6
0
def _join_return_dicts(ret1, ret2):
    ret = merge_list(ret1, ret2)

    # Join multiple 'stdout' and 'stderr' outputs
    # after merging the two output dicts
    if isinstance(ret['stdout'], list):
        ret['stdout'] = ''.join(ret['stdout'])
    if isinstance(ret['stderr'], list):
        ret['stderr'] = ''.join(ret['stderr'])

    # We only need the latest 'success' and 'retcode'
    # values after merging the two output dicts.
    ret['success'] = ret['success'][1]
    ret['retcode'] = ret['retcode'][1]

    return ret
Esempio n. 7
0
    def test_merge_list_append(self):
        """
        This codifies the intended behaviour that items merged into a dict val that is already
        a list that those items will *appended* to the list, and not magically merged in
        """
        mdict = copy.deepcopy(self.dict1)
        mdict["A"] = ["B", "b", "c"]

        # Prepare a modified copy of dict1 that has a list as a val for the key of 'A'
        mdict1 = copy.deepcopy(self.dict1)
        mdict1["A"] = ["B"]
        ret = dictupdate.merge_list(mdict1, {"A": ["b", "c"]})
        self.assertEqual(
            {
                "A": [["B"], ["b", "c"]],
                "C": {
                    "D": "E",
                    "F": {
                        "I": "J",
                        "G": "H"
                    }
                }
            }, ret)