63 lines
1.2 KiB
Python
63 lines
1.2 KiB
Python
from dataclasses import dataclass
|
|
|
|
from src.breakshaft.convertor import ConvRepo
|
|
|
|
|
|
@dataclass
|
|
class A:
|
|
a: int
|
|
|
|
|
|
@dataclass
|
|
class B:
|
|
b: float
|
|
|
|
|
|
type optC = str
|
|
|
|
|
|
def test_default_consumer_args():
|
|
repo = ConvRepo()
|
|
|
|
@repo.mark_injector()
|
|
def b_to_a(b: B) -> A:
|
|
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]
|
|
|
|
def consumer1(dep: A, opt_dep: optC = '42') -> ret1:
|
|
return dep.a, opt_dep
|
|
|
|
def consumer2(dep: A, dep1: ret1) -> optC:
|
|
return str((dep.a, dep1))
|
|
|
|
p1 = repo.create_pipeline(
|
|
(B,),
|
|
[consumer1, consumer2],
|
|
force_commutative=True,
|
|
allow_sync=True,
|
|
allow_async=False,
|
|
force_async=False
|
|
)
|
|
res = p1(B(42.1))
|
|
assert res == "(42, (42, '42'))"
|
|
|
|
p2 = repo.create_pipeline(
|
|
(B,),
|
|
[consumer1, consumer2, consumer1],
|
|
force_commutative=True,
|
|
allow_sync=True,
|
|
allow_async=False,
|
|
force_async=False
|
|
)
|
|
res = p2(B(42.1))
|
|
assert res == (42, "(42, (42, '42'))")
|