Skip to content

Commit

Permalink
test ambiguous case
Browse files Browse the repository at this point in the history
  • Loading branch information
jokasimr committed Nov 27, 2023
1 parent 87de9b2 commit bcf2f9f
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions tests/pipeline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,38 @@ def p1(x: T1, y: T2) -> C[T1, T2]:
def p2(x: A, y: T2) -> C[A, T2]:
return C[A, T2]("Medium", "Generic")

def p3(x: A, y: B) -> C[A, B]:
def p3(x: T2, y: B) -> C[T2, B]:
return C[T2, B]("Generic", "Medium")

def p4(x: A, y: B) -> C[A, B]:
return C[A, B]("Kinda", "Special")

pl = sl.Pipeline([p1, p2, p3], params={A: 'A', B: 'B'})
pl = sl.Pipeline([p1, p2, p3, p4], params={A: 'A', B: 'B'})

assert pl.compute(C[A, B]) == C("Kinda", "Special")
assert pl.compute(C[A, A]) == C("Medium", "Generic")
assert pl.compute(C[B, A]) == C("Very", "Generic")
assert pl.compute(C[A, A]) == C("Medium", "Generic")
assert pl.compute(C[B, B]) == C("Generic", "Medium")
assert pl.compute(C[A, B]) == C("Kinda", "Special")


def test_prioritizes_specialized_provider_raises() -> None:
A = NewType('A', str)
B = NewType('B', str)
T1 = TypeVar('T1')
T2 = TypeVar('T2')

@dataclass
class C(Generic[T1, T2]):
first: T1
second: T2

def p1(x: A, y: T1) -> C[A, T1]:
return C[A, T1]("Special", "Generic")

def p2(x: T1, y: B) -> C[T1, B]:
return C[T1, B]("Generic", "Special")

pl = sl.Pipeline([p1, p2], params={A: 'A', B: 'B'})

with pytest.raises(sl.AmbiguousProvider):
pl.compute(C[A, B])

0 comments on commit bcf2f9f

Please sign in to comment.