コード例 #1
0
    def clear(self, *, essence: bodies.BodyEssence) -> bodies.BodyEssence:
        essence = super().clear(essence=essence)

        # Work around an issue with mypy not treating TypedDicts as MutableMappings.
        essence_dict = cast(Dict[Any, Any], essence)
        dicts.remove(essence_dict, self.field)

        return essence
コード例 #2
0
    def build(
            self,
            *,
            body: bodies.Body,
            extra_fields: Optional[Iterable[dicts.FieldSpec]] = None,
    ) -> bodies.BodyEssence:
        essence = super().build(body=body, extra_fields=extra_fields)

        # Work around an issue with mypy not treating TypedDicts as MutableMappings.
        essence_dict = cast(Dict[Any, Any], essence)
        dicts.remove(essence_dict, self.field)

        return essence
コード例 #3
0
ファイル: progress.py プロジェクト: silveryfu/kopf
 def purge(
     self,
     *,
     key: handlers.HandlerId,
     body: bodies.Body,
     patch: patches.Patch,
 ) -> None:
     absent = object()
     key_field = self.field + (key, )
     body_value = dicts.resolve(body, key_field, absent)
     patch_value = dicts.resolve(patch, key_field, absent)
     if body_value is not absent:
         dicts.ensure(patch, key_field, None)
     elif patch_value is not absent:
         dicts.remove(patch, key_field)
コード例 #4
0
ファイル: progress.py プロジェクト: silveryfu/kopf
 def purge(
     self,
     *,
     key: handlers.HandlerId,
     body: bodies.Body,
     patch: patches.Patch,
 ) -> None:
     absent = object()
     for full_key in self.make_keys(key, body=body):
         key_field = ['metadata', 'annotations', full_key]
         body_value = dicts.resolve(body, key_field, absent)
         patch_value = dicts.resolve(patch, key_field, absent)
         if body_value is not absent:
             dicts.ensure(patch, key_field, None)
         elif patch_value is not absent:
             dicts.remove(patch, key_field)
コード例 #5
0
 def purge(
     self,
     *,
     key: handlers.HandlerId,
     body: bodies.Body,
     patch: patches.Patch,
 ) -> None:
     absent = object()
     full_key = self.make_key(key)
     key_field = ['metadata', 'annotations', full_key]
     body_value = dicts.resolve(body, key_field, absent, assume_empty=True)
     patch_value = dicts.resolve(patch,
                                 key_field,
                                 absent,
                                 assume_empty=True)
     if body_value is not absent:
         dicts.ensure(patch, key_field, None)
     elif patch_value is not absent:
         dicts.remove(patch, key_field)
コード例 #6
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_existing_key():
    d = {'abc': {'def': {'hij': 'val', 'hello': 'world'}}}
    remove(d, ['abc', 'def', 'hij'])
    assert d == {'abc': {'def': {'hello': 'world'}}}
コード例 #7
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_empty_path():
    d = {}
    with pytest.raises(ValueError) as e:
        remove(d, [])
    assert "Removing a root of a dict is impossible" in str(e.value)
コード例 #8
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_nonmapping_key():
    d = {'key': 'val'}
    with pytest.raises(TypeError):
        remove(d, ['key', 'sub'])
コード例 #9
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_parent_cascaded_deletion_up_to_a_middle():
    d = {'abc': {'def': {'hij': 'val'}, 'hello': 'world'}}
    remove(d, ['abc', 'def', 'hij'])
    assert d == {'abc': {'hello': 'world'}}
コード例 #10
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_parent_cascaded_deletion_up_to_the_root():
    d = {'abc': {'def': {'hij': 'val'}}}
    remove(d, ['abc', 'def', 'hij'])
    assert d == {}
コード例 #11
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_unexisting_key_in_unexisting_dict():
    d = {}
    remove(d, ['abc', 'def', 'hij'])
    assert d == {}
コード例 #12
0
ファイル: test_removing.py プロジェクト: nnazeer/kopf
def test_unexisting_key_in_existing_dict():
    d = {'abc': {'def': {'hello': 'world'}}}
    remove(d, ['abc', 'def', 'hij'])
    assert d == {'abc': {'def': {'hello': 'world'}}}