def test_py_value(loom_env): @tasks.py_task() def to_str(a): return str(a.unwrap()) @tasks.py_task(context=True) def to_tuple(ctx, a): b = tuple(a.unwrap()) return ctx.wrap(b) @tasks.py_task() def join(a, b): return [a, b] loom_env.start(2) v = tasks.py_value([(1, 2)]) v2 = tasks.py_value(("30", None)) t = to_str(v) result = loom_env.submit_and_gather(t) assert result == b"[(1, 2)]" t = to_tuple(v) result = loom_env.submit_and_gather(t) assert result == ((1, 2), ) v.resource_request = cpu1 v2.resource_request = cpu1 t = join(v, v2) result = loom_env.submit_and_gather(t) assert result == [[(1, 2)], ("30", None)]
def test_py_call(loom_env): def f(a, b): return "{}, {}, {}, {}".format(str(a.read(), encoding="ascii"), a.size(), str(b.read(), encoding="ascii"), b.size()) def g(): return "Test" loom_env.start(1) c = tasks.const("ABC") d = tasks.const("12345") p = tasks.py_call(tasks.py_value(f), (c, d)) q = tasks.py_call(tasks.py_value(g)) result1, result2 = loom_env.submit_and_gather((p, q)) assert result1 == b"ABC, 3, 12345, 5" assert result2 == b"Test"
def test_py_wrap_wrapped(loom_env): @tasks.py_task(context=True) def task(ctx, a): return ctx.wrap(a) loom_env.start(2) v = tasks.py_value("ABC") t = task(v) result = loom_env.submit_and_gather(t) assert result == "ABC"
def test_py_fail_invalid_result(loom_env): def f(): return 42.0 loom_env.start(1) a = tasks.py_call(tasks.py_value(f), ()) with pytest.raises(TaskFailed): loom_env.submit_and_gather(a)
def test_py_fail_too_few_args(loom_env): def f(a): return "ABC" loom_env.start(1) a = tasks.py_call(tasks.py_value(f), ()) with pytest.raises(TaskFailed): loom_env.submit_and_gather(a)
def test_py_fail_too_many_args(loom_env): def g(): return "Test" loom_env.start(1) c = tasks.const("ABC") a = tasks.py_call(tasks.py_value(g), (c, )) with pytest.raises(TaskFailed): loom_env.submit_and_gather(a)
def test_py_redirect3(loom_env): def f(a): return tasks.run("cat X", [(a, "X")]) loom_env.start(1) c = tasks.const("DataData") a = tasks.py_call(tasks.py_value(f), (c, )) result = loom_env.submit_and_gather(a) assert b"DataData" in result
def test_py_redirect1(loom_env): def f(a, b): return tasks.merge((a, b)) loom_env.start(1) c = tasks.const("ABC") d = tasks.const("12345") a = tasks.py_call(tasks.py_value(f), (c, d)) result = loom_env.submit_and_gather(a) assert result == b"ABC12345"
def test_py_redirect2(loom_env): def f(a, b): return tasks.run("/bin/ls $X", [(b, "$X")]) loom_env.start(1) c = tasks.const("abcdef") d = tasks.const("/") a = tasks.py_call(tasks.py_value(f), (c, d)) result = loom_env.submit_and_gather(a) assert b"bin\n" in result assert b"usr\n" in result
def test_py_task_deserialization3(loom_env): loom_env.start(2) objs = tuple(tasks.py_value(str(i + 1000)) for i in range(100)) x = tasks.array_make(objs) loom_env.submit_and_gather(x)