Skip to content
Snippets Groups Projects
Commit 9f2b9b5e authored by Malte Nyhuis's avatar Malte Nyhuis
Browse files

cleanup

parent a43e2927
No related branches found
No related tags found
1 merge request!10Merge recent changes in master to we_ahrens
from ntrfc.dictutils.dict_utils import nested_dict_pairs_iterator, delete_keys_from_dict, compare_dictionaries, \
set_in_dict, get_from_dict, merge
def test_nested_dict_pairs_iterator():
"""
tests if nested_dict_pairs_iterator returns the right list for a nested dict
nested_dict_pairs_iterator is used for returning a nested dict as a list
which comes in handy when handling nested directories with files
"""
from ntrfc.dictutils.dict_utils import nested_dict_pairs_iterator
test_dictionary = {"0": {"0": 0, "1": 1}, "1": 1}
check = [('0', '0', 0), ('0', '1', 1), ('1', 1)]
assert check == list(nested_dict_pairs_iterator(test_dictionary)), "error"
def test_delete_keys_from_dict():
from ntrfc.dictutils.dict_utils import delete_keys_from_dict
test_dictionary = {"a": 0, "b": 1}
delete_keys_from_dict(test_dictionary, "a")
assert "a" not in test_dictionary.keys()
......@@ -22,6 +20,7 @@ def test_delete_keys_from_dict():
def test_compare_dictionaries():
from ntrfc.dictutils.dict_utils import compare_dictionaries
d1 = {"name": {"param_1": 0, "param_2": 3}}
d2 = {"name": {"param_1": 4, "param_2": 1}}
ke, ve = compare_dictionaries(d1, d2)
......@@ -30,9 +29,10 @@ def test_compare_dictionaries():
def test_setInDict():
dict = {"toplevel": {"value_1": 0, "value_2": 2}}
set_in_dict(dict, ["toplevel", "value_2"], 3)
assert dict["toplevel"]["value_2"] == 3
from ntrfc.dictutils.dict_utils import set_in_dict
dictionary = {"toplevel": {"value_1": 0, "value_2": 2}}
set_in_dict(dictionary, ["toplevel", "value_2"], 3)
assert dictionary["toplevel"]["value_2"] == 3
def test_getFromDict():
......@@ -41,12 +41,16 @@ def test_getFromDict():
dataDict: dictionary
mapList: list of keys to access value
"""
dict = {"toplevel": {"midlevel": {"value_1": 1, "value_2": 0}}}
from ntrfc.dictutils.dict_utils import get_from_dict
assert get_from_dict(dict, ["toplevel", "midlevel", "value_2"]) == 0
dictionary = {"toplevel": {"midlevel": {"value_1": 1, "value_2": 0}}}
assert get_from_dict(dictionary, ["toplevel", "midlevel", "value_2"]) == 0
def test_merge():
from ntrfc.dictutils.dict_utils import merge
dict_1 = {"toplevel_1": {"value_11": 0}}
dict_2 = {"toplevel_1": {"value_12": 1}, "toplevel_2": {"value_21": 3}}
assert merge(dict_1, dict_2) == {'toplevel_1': {'value_11': 0, 'value_12': 1}, 'toplevel_2': {'value_21': 3}}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment