Skip to content
Snippets Groups Projects
Commit c4aeb10e authored by Eric Pershey's avatar Eric Pershey
Browse files

adding tests for data.py

parent dc583365
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ def merge_dictionaries(dct_a: Dict[K, V], dct_b: Dict[K, V], default: object, op
class partial_arg_kw:
"""a helper function to apply arguments and kwargs to a function.
partial args are applied first and kwargs are applied after the partial kwargs."""
def __init__(self, func, *args, **kwargs):
self.func = func
self.args = args
......
# Copyright (C) 2024, UChicago Argonne, LLC
# Licensed under the 3-clause BSD license. See accompanying LICENSE.txt file
# in the top-level directory.
import operator
from Octeres.data import partial_arg_kw, merge_dictionaries
def test_merge_dictionaries_00():
dct_a = dict(a=1, b=2, e=5)
dct_b = dict(c=3, d=4)
dct_c = dict(a=1, b=2, c=3, d=4, e=5)
assert merge_dictionaries(dct_a, dct_b, None, lambda a, b: b) == dct_c
dct_a = dict(a=1, b=2, e=5)
dct_b = dict(c=3, b=123, d=4)
dct_c = dict(a=1, b=123, c=3, d=4, e=5)
assert merge_dictionaries(dct_a, dct_b, None, lambda a, b: b) == dct_c
dct_c2 = dict(a=1, b=2, c=None, d=None, e=5) # odd case, left gets from dct_a.get(c, None) and returns a which is None
assert merge_dictionaries(dct_a, dct_b, None, lambda a, b: a) == dct_c2
dct_c3 = dict(a=1, b=125, c=3, d=4, e=5)
assert merge_dictionaries(dct_a, dct_b, 0, operator.add) == dct_c3
dct_c4 = dict(a=1, b=125, c=13, d=14, e=5)
assert merge_dictionaries(dct_a, dct_b, 10, operator.add) == dct_c4
def test_partial_arg_kw_00():
def func(a, b, c, d=1):
return a, b, c, d
func2 = partial_arg_kw(func, 10, d=2)
result = func2(3, 4)
assert result == (10, 3, 4, 2)
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