Ejemplo n.º 1
0
 def test_update_condition(self):
     annotations = Annotations(merge_method=add,
                               finalized=False,
                               condition=if_existing)
     annotations.update(Annotations(condition=always))
     assert add == annotations.merge_method
     assert not annotations.finalized
     assert always == annotations.condition
Ejemplo n.º 2
0
 def test_update_finalized(self):
     annotations = Annotations(merge_method=add,
                               finalized=False,
                               condition=if_existing)
     annotations.update(Annotations(finalized=True))
     assert add == annotations.merge_method
     assert annotations.finalized
     assert if_existing == annotations.condition
Ejemplo n.º 3
0
 def test_update_merge_method(self):
     annotations = Annotations(merge_method=add,
                               finalized=True,
                               condition=if_existing)
     annotations.update(Annotations(merge_method=overwrite))
     assert overwrite == annotations.merge_method
     assert annotations.finalized
     assert if_existing == annotations.condition
Ejemplo n.º 4
0
 def test_set_condition(self):
     fancy_dict = FancyDict()
     fancy_dict["key"] = "value"
     fancy_dict["key_not_merging"] = "value"
     fancy_dict.annotate("key_not_merging",
                         Annotations(condition=lambda o, n: False))
     assert {"key": "value"} == FancyDict(fancy_dict)
Ejemplo n.º 5
0
 def test_update_annotations(self):
     annotations = Annotations(finalized=True)
     updating_fancy_dict = FancyDict(key=1)
     updating_fancy_dict.annotate("key", annotations)
     base_fancy_dict = FancyDict()
     base_fancy_dict.update(updating_fancy_dict)
     assert base_fancy_dict.get_annotations("key").finalized
Ejemplo n.º 6
0
 def test_merge_method(self):
     base_dict = FancyDict()
     base_dict["counter"] = 1
     update_dict = FancyDict(counter=1)
     update_dict.annotate("counter", Annotations(merge_method=add))
     base_dict.update(update_dict)
     assert 2 == base_dict["counter"]
Ejemplo n.º 7
0
 def decode(cls, key=None, value=None):
     annotations = Annotations(
         merge_method=cls._parse_merge_method(key),
         condition=cls._parse_condition(key),
         finalized=cls._parse_finalized(key),
     )
     key = cls._parse_key(key)
     return {
         "key": key,
         "value": value,
         "annotations": annotations
     }
Ejemplo n.º 8
0
 def test_setitem_allow_change_even_if_finalized(self):
     fancy_dict = FancyDict(finalized=1)
     fancy_dict.annotate("finalized", Annotations(finalized=True))
     fancy_dict["finalized"] = 2
     assert 2 == fancy_dict["finalized"]
Ejemplo n.º 9
0
 def decode(cls, key=None, value=None):
     annotations = Annotations(finalized=True)
     key = "DECODED"
     return {"key": key, "value": value, "annotations": annotations}
Ejemplo n.º 10
0
 def test_update_existing_annotations(self):
     annotations = Annotations(finalized=True)
     fancy_dict = FancyDict(key=1)
     fancy_dict.annotate("key", annotations)
     fancy_dict.annotate("key", finalized=False)
     assert not annotations.finalized
Ejemplo n.º 11
0
 def test_finalized(self):
     fancy_dict = FancyDict(finalized=1)
     fancy_dict.annotate("finalized", Annotations(finalized=True))
     fancy_dict.update(finalized=2)
     assert 1 == fancy_dict["finalized"]
Ejemplo n.º 12
0
 def test_defaults(self):
     annotations = Annotations()
     assert overwrite == annotations.merge_method
     assert always == annotations.condition
     assert not annotations.finalized
Ejemplo n.º 13
0
 def test_attribute_error_if_not_in_defaults(self):
     with pytest.raises(AttributeError):
         assert not Annotations().no_attribute
Ejemplo n.º 14
0
 def test_default_if_none_was_set(self):
     annotations = Annotations(condition=None)
     assert always == annotations.condition
Ejemplo n.º 15
0
 def test_get_none(self):
     annotations = Annotations()
     assert annotations.get("condition") is None