Newer
Older
# 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)