Esempio n. 1
0
def test_drop_arg():
    a = [1]
    b = [2]
    mapped_args = ParamArgMapper.map_args(copy_fn,
                                          args=[a, b],
                                          kwargs={},
                                          drop_args="a")
    assert ["b"] == list(mapped_args.keys())

    mapped_args = ParamArgMapper.map_args(copy_fn,
                                          args=[a, b],
                                          kwargs={},
                                          drop_args=["a", "b"])
    assert [] == list(mapped_args.keys())
Esempio n. 2
0
def test_copy_all():
    a = [1]
    b = [2]
    mapped_args = ParamArgMapper.map_args(copy_fn,
                                          args=[a, b],
                                          kwargs={},
                                          copy_args=COPY_ALL_ARGS)

    a.append(10)
    b.append(10)

    assert mapped_args["a"] == [1]
    assert mapped_args["b"] == [2]
Esempio n. 3
0
def test_copy_some():
    a = [1]
    b = [2]
    mapped_args = ParamArgMapper.map_args(copy_fn,
                                          args=[a, b],
                                          kwargs={},
                                          copy_args=["a"])

    a.append(10)
    b.append(10)

    assert mapped_args["a"] == [1]
    assert mapped_args["b"] == [2, 10]
Esempio n. 4
0
 def wrapper(*args, **kwargs):
     objective_name = objective or callable.__name__
     args_data = ParamArgMapper.map_args(callable,
                                         args,
                                         kwargs,
                                         copy_args=copy_args,
                                         drop_args=drop_args)
     msg = JournalContent(
         context=ctx,
         objective=objective_name,
         arguments=args_data,
     )
     try:
         results = callable(*args, **kwargs)
         results_data = ParamArgMapper.map_results(
             results, result_names=result_names)
         msg.results = results_data
         logger.info(msg="", extra={"journal_content": msg})
         return results
     except Exception as exc:
         msg.exception = ExceptionMsg.from_exception(exc)
         logger.exception(msg="", extra={"journal_content": msg})
         raise
Esempio n. 5
0
def test_unbound():
    actual_args = unbound_param_arg_map("p1",
                                        "pkw1",
                                        "pkw2",
                                        "pkw3",
                                        kw1="kw1",
                                        kw2="kw2",
                                        kw3="kw3")
    mapped_args = ParamArgMapper.map_args(
        unbound_param_arg_map,
        ["p1", "pkw1", "pkw2", "pkw3"],
        {
            "kw1": "kw1",
            "kw2": "kw2",
            "kw3": "kw3"
        },
    )
    assert actual_args == mapped_args
Esempio n. 6
0
def test_single_name():
    results = ["a"]
    results_map = ParamArgMapper.map_results(results, "a")
    assert results_map == {"a": "a"}
Esempio n. 7
0
def test_mismatch():
    results = ("a", "b")
    with pytest.raises(ResultNameMappingError):
        ParamArgMapper.map_results(results, ["a"])
Esempio n. 8
0
def test_some_mapped():
    results = ("a", "b")
    results_map = ParamArgMapper.map_results(results, ["a", DROP_RESULT])
    assert results_map == {"a": "a"}
Esempio n. 9
0
def test_all_mapped():
    results = ("a", "b")
    results_map = ParamArgMapper.map_results(results, ["a", "b"])
    assert results_map == {"a": "a", "b": "b"}
Esempio n. 10
0
def test_no_names():
    results = ("a", "b")
    results_map = ParamArgMapper.map_results(results)
    assert results_map == results
Esempio n. 11
0
def test_single_result():
    results = "a"
    results_map = ParamArgMapper.map_results(results, "a")
    assert results_map == {"a": "a"}
Esempio n. 12
0
def test_bound_static():
    actual_args = BoundMethod.static_method("p1")
    mapped_args = ParamArgMapper.map_args(BoundMethod.static_method, ["p1"],
                                          {})
    assert actual_args == mapped_args
Esempio n. 13
0
def test_bound_obj():
    obj = BoundMethod()
    actual_args = obj.obj_method("p1")
    mapped_args = ParamArgMapper.map_args(obj.obj_method, ["p1"], {})
    assert actual_args == mapped_args