示例#1
0
 def test_deep_extend_illegal_addition(self):
     '''
     Test errorhandling extending lists with illegal types.
     '''
     # Extend with an illegal type
     for extend_with in [42, None]:
         with self.assertRaisesRegex(SaltInvocationError,
                                     r"Cannot extend {} with a {}."
                                     "".format(type([]), type(extend_with))):
             dictupdate.extend_dict_key_value({}, 'foo', extend_with)
示例#2
0
 def test_deep_extend_illegal_source(self):
     '''
     Test errorhandling extending things that are not a list.
     '''
     # Extend an illegal type
     for extend_this in [{}, 42, 'bar']:
         with self.assertRaisesRegex(SaltInvocationError,
                                     r"The last key contains a {}, which cannot extend."
                                     "".format(type(extend_this))):
             dictupdate.extend_dict_key_value({'foo': extend_this}, 'foo', [42])
示例#3
0
    def test_deep_extend(self):
        '''
        Test extending a list.
        Note that the provided value (to extend with) will be coerced to a list
        if this is not already a list. This can cause unexpected behaviour.
        '''
        sdict = {'bar': {'baz': [1, 2]}}
        res = dictupdate.extend_dict_key_value(sdict, 'bar:baz', [42, 42])
        self.assertEqual({'bar': {'baz': [1, 2, 42, 42]}}, res)

        # Extend a not-yet existing list
        res = dictupdate.extend_dict_key_value({}, 'bar:baz:qux', [42])
        self.assertEqual({'bar': {'baz': {'qux': [42]}}}, res)

        # Extend with a dict (remember, foo has been updated in the first test)
        res = dictupdate.extend_dict_key_value(sdict, 'bar:baz', {'qux': 'quux'})
        self.assertEqual({'bar': {'baz': [1, 2, 42, 42, 'qux']}}, res)
    def test_deep_extend(self):
        """
        Test extending a list.
        Note that the provided value (to extend with) will be coerced to a list
        if this is not already a list. This can cause unexpected behaviour.
        """
        sdict = {"bar": {"baz": [1, 2]}}
        res = dictupdate.extend_dict_key_value(sdict, "bar:baz", [42, 42])
        self.assertEqual({"bar": {"baz": [1, 2, 42, 42]}}, res)

        # Extend a not-yet existing list
        res = dictupdate.extend_dict_key_value({}, "bar:baz:qux", [42])
        self.assertEqual({"bar": {"baz": {"qux": [42]}}}, res)

        # Extend with a dict (remember, foo has been updated in the first test)
        res = dictupdate.extend_dict_key_value(sdict, "bar:baz",
                                               {"qux": "quux"})
        self.assertEqual({"bar": {"baz": [1, 2, 42, 42, "qux"]}}, res)