Exemple #1
0
def test_update_returns_with_updates():

    original = immutable({'alpha': 1, 'beta': 2, 'dalet': 4})

    result = update(original, alpha=10)

    assert original is not result
    assert result.get('alpha') == 10
Exemple #2
0
def test_update_handles_deep_objects():

    original = immutable({'alpha': {'color': 23}, 'beta': 2, 'dalet': 4})

    result = update(original, alpha={'color': 10})

    assert original is not result
    assert result.get('alpha').get('color') == 10
Exemple #3
0
def test_update_returns_new_instance():

    original = immutable({'alpha': 1, 'beta': 2, 'dalet': 4})

    result = update(original)

    assert original == result
    assert original is not result
Exemple #4
0
 def apply_function_values(attr):
     """Allows us to support passing a special Function as the
     value of the attribute. Here, if the value property is a
     Function we move it to the func property to be used later
     and call it to get the real value"""
     is_function = lambda val: isinstance(
         val, Immutable
     ) and val.expression is not None and val.value is not None
     if is_function(attr.value):
         fn = attr.value
         return update(attr, func=fn, value=fn.value())
     return attr
Exemple #5
0
 def build_value_type_tree(attr):
     """Last step in parsing pipeline, reads the value of the
     attribute and uses boto's serializer to convert it to that
     freaky tree with type indicators that dynamo requires"""
     return update(attr, value=TypeSerializer().serialize(attr.value))
Exemple #6
0
 def build_key(attr):
     """Builds the key that can be used to reference
     the attribute's value in an expression"""
     return update(attr, key=f':{attr.key}')
Exemple #7
0
 def replace_reserved_key(attr):
     """Finds reserved dynamo keywords in the attribute
     names and sets an alias the is safe to use instead"""
     return update(attr, alias=get_safe_alias(attr.original))