def test_dict_call_child_copy(): bin_op = BinaryOp('__add__', 1, 2) call = DictCall("__call__", dict, {'a': bin_op, 'b': 2}) copy = call.copy() assert isinstance(call.args[1]['a'], BinaryOp) assert bin_op is not copy.args[1]['a']
def _case_when(__data, cases): if not isinstance(cases, dict): raise Exception("Cases must be a dictionary") dict_entries = dict( (strip_symbolic(k), strip_symbolic(v)) for k, v in cases.items()) cases_arg = Lazy(DictCall("__call__", dict, dict_entries)) return create_sym_call(case_when, __data, cases_arg)
# Node copying ================================================================ from siuba.siu import Call, BinaryOp, SliceOp, MetaArg, FuncArg, DictCall # Call @pytest.mark.parametrize('node', [ Call("__call__", lambda x, y=2: x + y, 1, y=2), BinaryOp("__add__", 1, 2), SliceOp("__siu_slice__", slice(0, 1)), SliceOp("__siu_slice__", (slice(0, 1), slice(2, 3))), MetaArg("_"), FuncArg("__custom_func__", lambda x: x), FuncArg(lambda x: x), DictCall("__call__", dict, { 'a': 1, 'b': 2 }) ]) def test_node_copy(node): copy = node.copy() assert isinstance(copy, node.__class__) assert copy is not node assert copy.func == node.func assert copy.args == node.args assert copy.kwargs == node.kwargs def test_dict_call_child_copy(): bin_op = BinaryOp('__add__', 1, 2) call = DictCall("__call__", dict, {'a': bin_op, 'b': 2}) copy = call.copy()