def test_empty(): def _fail_etl_func(i, e=None): return None, "nop" operation = alternative( substitution(["a"], etl_func=_fail_etl_func), substitution(["b"], etl_func=wrap(lambda x: x + 1))) (res, err) = operation(None) assert res is None assert err == {'b': 'b not found'}
def test_some_working(): operation = substitution(fields=["hello"], etl_func=match_dict({"world": "world of Ooo"})) (res, err) = operation({"hello": "world"}) assert res is not None assert "hello" in res assert res["hello"] == "world of Ooo" assert err is None
def test_empty_definition(): inp = {"a": 0.3} operation = substitution(["a"], etl_func=buckets_grouping(None, None)) (res, err) = operation(inp) assert res is None assert err is not None assert err == {'a': 'buckets not provided'}
def test_some_working(): def _fail_etl_func(i, e=None): return None, "nop" inp = {"a": "jajaja", "b": 1} operation = alternative( substitution(["a"], etl_func=_fail_etl_func), substitution(["b"], etl_func=wrap(lambda x: x + 1))) (res, err) = operation(inp) assert inp == {"a": "jajaja", "b": 1} assert res is not None assert "a" not in res assert "b" in res assert res["b"] == 2 assert err is None
def test_some_working(): inp = {"a": 0.3} operation = substitution(["a"], etl_func=buckets_grouping(0.25, 0.5)) (res, err) = operation(inp) assert res is not None assert "a" in res assert res["a"] == 2 assert err is None
def test_empty(): imp = None op = substitution(["cant"], wrap(add_one)) (res, err) = op(imp) assert res is None assert err == {"cant": "cant not found"}
def test_multiple_working(): imp = {"cant": 0, "sum": 1} op = substitution(["cant", "sum"], wrap(add_one)) (res, err) = op(imp) assert err is None assert res == {"cant": 1, "sum": 2}
def test_some_working(): imp = {"cant": 0} op = substitution(["cant"], wrap(add_one)) (res, err) = op(imp) assert res == {"cant": 1} assert err is None
def test_empty(): def _if_part(x): return x == 0 def _fun_part(x): return x + 1 operation = substitution(["a"], replace_if(_if_part, _fun_part)) (res, err) = operation(None) assert res is None assert err == {'a': 'a not found'}
def test_empty_input_if_then(): def _fn_cond(x): return x == 0 def _fn_then(x): return x + 1 operation = substitution(["a"], replace_if_else(_fn_cond, _fn_then)) (res, err) = operation(None) assert res is None assert err == {'a': 'a not found'}
def test_filtered_workflow(): def invert(x): return not x def must_true(x): return x def to_int(x): if x: return 1 return 0 inp = {"a": False} op = sequential(substitution(["a"], wrap(invert)), filter_tuple(["a"], wrap(must_true)), substitution(["a"], wrap(to_int))) (res, err) = op(inp) assert res == {"a": 1} assert err is None
def test_cond_true_replace_if_then_default_else(): def _fn_cond(x): return x == 0 def _fn_then(x): return x + 1 operation = substitution(["a"], replace_if_else(_fn_cond, _fn_then)) (res, err) = operation({"a": 100}) assert res is not None assert "a" in res assert res["a"] == 100 assert err is None
def test_some_working(): def _if_part(x): return x == 0 def _fun_part(x): return x + 1 inp = {"a": 0} operation = substitution(["a"], replace_if(_if_part, _fun_part)) (res, err) = operation(inp) assert inp is not None assert res is not None assert "a" in res assert res["a"] == 1 assert err is None
def test_not_matching(): operation = substitution(fields=["hello"], etl_func=match_dict({"who": "Tom"})) (res, err) = operation({"hello": "world"}) assert res is None assert err is not None assert err["hello"] == "world not found on dictionary"
def test_all_empty(): operation = substitution(["a"], etl_func=buckets_grouping(None, None)) (res, err) = operation(None) assert res is None assert err == {'a': 'buckets not provided'}
def test_empty(): operation = substitution(fields=["hello"], etl_func=match_dict(None)) (res, err) = operation({"hello": "world"}) assert res is None assert err is not None assert err["hello"] == "You need a dict for matching"
def test_empty(): operation = substitution(["a"], etl_func=buckets_grouping(25, 75)) (res, err) = operation(None) assert res is None assert err == {'a': 'a not found'}