Skip to content

Commit

Permalink
fix TestModder.test_dict_modify failing from clashing variable name k…
Browse files Browse the repository at this point in the history
…ey in custodian/ansible/actions.py
  • Loading branch information
janosh committed Apr 9, 2024
1 parent 0e0bf29 commit 6f45839
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions custodian/ansible/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def set(input_dict, settings, directory=None) -> None:
directory (None): dummy parameter for compatibility with FileActions
"""
for key, val in settings.items():
dct, key = get_nested_dict(input_dict, key)
dct[key] = val
dct, sub_key = get_nested_dict(input_dict, key)
dct[sub_key] = val

@staticmethod
def unset(input_dict, settings, directory=None) -> None:
Expand All @@ -84,11 +84,11 @@ def push(input_dict, settings, directory=None) -> None:
directory (None): dummy parameter for compatibility with FileActions
"""
for key, val in settings.items():
dct, key = get_nested_dict(input_dict, key)
if key in dct:
dct[key].append(val)
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct:
dct[sub_key].append(val)
else:
dct[key] = [val]
dct[sub_key] = [val]

@staticmethod
def push_all(input_dict, settings, directory=None) -> None:
Expand All @@ -110,19 +110,19 @@ def push_all(input_dict, settings, directory=None) -> None:
@staticmethod
def inc(input_dict, settings, directory=None) -> None:
"""
Increment a value using MongdoDB syntax.
Increment a value using MongoDB syntax.
Args:
input_dict (dict): The input dictionary to be modified.
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for key, val in settings.items():
dct, key = get_nested_dict(input_dict, key)
if key in dct:
dct[key] += val
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct:
dct[sub_key] += val
else:
dct[key] = val
dct[sub_key] = val

@staticmethod
def rename(input_dict, settings, directory=None) -> None:
Expand All @@ -149,13 +149,13 @@ def add_to_set(input_dict, settings, directory=None) -> None:
directory (None): dummy parameter for compatibility with FileActions
"""
for key, val in settings.items():
dct, key = get_nested_dict(input_dict, key)
if key in dct and (not isinstance(dct[key], list)):
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct and (not isinstance(dct[sub_key], list)):
raise ValueError(f"Keyword {key} does not refer to an array.")
if key in dct and val not in dct[key]:
dct[key].append(val)
elif key not in dct:
dct[key] = val
if sub_key in dct and val not in dct[sub_key]:
dct[sub_key].append(val)
elif sub_key not in dct:
dct[sub_key] = val

@staticmethod
def pull(input_dict, settings, directory=None) -> None:
Expand Down Expand Up @@ -201,13 +201,13 @@ def pop(input_dict, settings, directory=None) -> None:
directory (None): dummy parameter for compatibility with FileActions
"""
for key, val in settings.items():
dct, key = get_nested_dict(input_dict, key)
if key in dct and (not isinstance(dct[key], list)):
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct and (not isinstance(dct[sub_key], list)):
raise ValueError(f"Keyword {key} does not refer to an array.")
if val == 1:
dct[key].pop()
dct[sub_key].pop()
elif val == -1:
dct[key].pop(0)
dct[sub_key].pop(0)


class FileActions:
Expand Down

0 comments on commit 6f45839

Please sign in to comment.