Make smart call deduplication
This commit is contained in:
@@ -60,3 +60,49 @@ def test_default_consumer_args():
|
||||
)
|
||||
res = p2(B(42.1))
|
||||
assert res == (42, "(42, (42, '42'))")
|
||||
|
||||
|
||||
def test_pipeline_with_subgraph_duplicates():
|
||||
repo = ConvRepo()
|
||||
|
||||
b_to_a_calls = [0]
|
||||
|
||||
@repo.mark_injector()
|
||||
def b_to_a(b: B) -> A:
|
||||
b_to_a_calls[0] += 1
|
||||
return A(int(b.b))
|
||||
|
||||
@repo.mark_injector()
|
||||
def a_to_b(a: A) -> B:
|
||||
return B(float(a.a))
|
||||
|
||||
@repo.mark_injector()
|
||||
def int_to_a(i: int) -> A:
|
||||
return A(i)
|
||||
|
||||
type ret1 = tuple[int, str]
|
||||
|
||||
cons1_calls = [0]
|
||||
cons2_calls = [0]
|
||||
|
||||
def consumer1(dep: A, opt_dep: optC = '42') -> A:
|
||||
cons1_calls[0] += 1
|
||||
return A(dep.a + int(opt_dep))
|
||||
|
||||
def consumer2(dep: A) -> optC:
|
||||
cons2_calls[0] += 1
|
||||
return str(dep.a)
|
||||
|
||||
p1 = repo.create_pipeline(
|
||||
(B,),
|
||||
[consumer1, consumer2, consumer1, consumer2, consumer1, consumer2, consumer1, consumer2, consumer1],
|
||||
force_commutative=True,
|
||||
allow_sync=True,
|
||||
allow_async=False,
|
||||
force_async=False
|
||||
)
|
||||
res = p1(B(42.1))
|
||||
assert res.a == 42 + (42 * 31)
|
||||
assert b_to_a_calls[0] == 1
|
||||
assert cons1_calls[0] == 5
|
||||
assert cons2_calls[0] == 4
|
||||
|
||||
Reference in New Issue
Block a user