Exemplo n.º 1
0
def test_set_nested_value_adds_new_key_val_pair():
    d = {'attributes': {'some_osm_tag': 'hello'}}
    value = {'attributes': {'some_tag': 'bye'}}
    return_d = dict_support.set_nested_value(d, value)

    assert return_d == {
        'attributes': {
            'some_osm_tag': 'hello',
            'some_tag': 'bye'
        }
    }
Exemplo n.º 2
0
 def update(self):
     if self.has_updates():
         if isinstance(self.data, dict):
             for attachment in self.attachments:
                 attachment_data = dict_support.get_nested_value(self.data, attachment)
                 if isinstance(attachment_data, (list, set)):
                     value = attachment_data.__class__(map(self.map.get, attachment_data))
                 else:
                     value = self.map[attachment_data]
                 self.data = dict_support.set_nested_value(
                     self.data, dict_support.nest_at_leaf(deepcopy(attachment), value))
         else:
             for attachment in self.attachments:
                 if all([isinstance(x, (list, set)) for x in self.data[attachment]]):
                     self.data[attachment] = self.data[attachment].apply(
                         lambda x: x.__class__([self.map[i] for i in x]))
                 else:
                     self.data[attachment] = self.data[attachment].replace(self.map)
         self.build_identity_map()
Exemplo n.º 3
0
def test_set_nested_value_overwrites_current_value():
    d = {'attributes': {'some_osm_tag': 'hello'}}
    value = {'attributes': {'some_osm_tag': 'bye'}}
    return_d = dict_support.set_nested_value(d, value)

    assert return_d == {'attributes': {'some_osm_tag': 'bye'}}
Exemplo n.º 4
0
def test_set_nested_value_creates_new_nest_in_place_of_single_value():
    d = {'attributes': 1}
    value = {'attributes': {'some_tag': 'bye'}}
    return_d = dict_support.set_nested_value(d, value)

    assert return_d == {'attributes': {'some_tag': 'bye'}}