Skip to content

Commit

Permalink
tests: updated test for more comprehensive testing
Browse files Browse the repository at this point in the history
Added tertiary nested layer and check for values that evaluate to False but are not None type.
  • Loading branch information
gtdang authored and ntolley committed Jul 26, 2024
1 parent 82835c6 commit 7477084
Showing 1 changed file with 46 additions and 13 deletions.
59 changes: 46 additions & 13 deletions hnn_core/tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,46 +784,79 @@ def test_fig_tabs_dropdown_lists(setup_gui):

def test_update_nested_dict():
"""Tests nested dictionary updates values appropriately."""
original = {'a': 0,
'b': {'a2': 0, 'b2': 0},
original = {'a': 1,
'b': {'a2': 0,
'b2': {'a3': 0
}
},
}

# Changes at each level
changes = {'a': 1,
'b': {'a2': 1, 'b2': 0},
changes = {'a': 2,
'b': {'a2': 1,
'b2': {'a3': 1
}
},
}
updated = _update_nested_dict(original, changes)
expected = changes
assert updated == expected

# Omitted items should not be changed from in the original
omission = {'a': 1,
omission = {'a': 2,
'b': {'a2': 0},
}
expected = {'a': 1,
'b': {'a2': 0, 'b2': 0},
expected = {'a': 2,
'b': {'a2': 0,
'b2': {'a3': 0
}
},
}
updated = _update_nested_dict(original, omission)
assert updated == expected

# Additional items should be added
addition = {'a': 1,
'b': {'a2': 0, 'b2': 0, 'c2': 1},
'c': 1,
addition = {'a': 2,
'b': {'a2': 0,
'b2': {'a3': 0,
'b3': 0,
},
'c2': 1
},
'c': 1
}
expected = addition
updated = _update_nested_dict(original, addition)
assert updated == expected

# Test passing of None values
has_none = {'a': 0,
'b': {'a2': None, 'b2': 0},
has_none = {'a': 1,
'b': {'a2': None},
}
# Default behavior will not pass in None values to the update
expected = original # No change expected
updated = _update_nested_dict(original, has_none)
assert updated == expected
# Skip_none set of False will pass in None values to the update
updated = _update_nested_dict(original, has_none, skip_none=False)
expected = has_none
expected = {'a': 1,
'b': {'a2': None,
'b2': {'a3': 0
}
},
}
assert updated == expected

# Values that evaluate to False that but are not None type should be passed
# to the updated dict by default.
has_nulls = {'a': 0,
'b': {'a2': np.nan,
'b2': {'a3': False,
'b3': ''
}
},
}
# Skip_none set of False will pass in None values to the update
updated = _update_nested_dict(original, has_nulls)
expected = has_nulls
assert updated == expected

0 comments on commit 7477084

Please sign in to comment.