Allow passing [ConversionPoint] into get_conversion with a type remap for ConversionPoint
This commit is contained in:
47
tests/test_typehints_remap.py
Normal file
47
tests/test_typehints_remap.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Annotated
|
||||
|
||||
import pytest
|
||||
|
||||
from breakshaft.models import ConversionPoint
|
||||
from src.breakshaft.convertor import ConvRepo
|
||||
|
||||
|
||||
@dataclass
|
||||
class A:
|
||||
a: int
|
||||
|
||||
|
||||
@dataclass
|
||||
class B:
|
||||
b: float
|
||||
|
||||
|
||||
def test_basic():
|
||||
repo = ConvRepo()
|
||||
|
||||
@repo.mark_injector()
|
||||
def int_to_a(i: int) -> A:
|
||||
return A(i)
|
||||
|
||||
type HackInt = int
|
||||
|
||||
def consumer(dep: A) -> int:
|
||||
return dep.a
|
||||
|
||||
type NewA = A
|
||||
type_remap = {'dep': NewA, 'return': Annotated[HackInt, 'fuck']}
|
||||
|
||||
assert len(ConversionPoint.from_fn(consumer, type_remap=type_remap)) == 1
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
fn1 = repo.get_conversion((int,), ConversionPoint.from_fn(consumer, type_remap=type_remap),
|
||||
force_commutative=True, force_async=False, allow_async=False)
|
||||
|
||||
repo.mark_injector(type_remap={'i': int, 'return': NewA})(int_to_a)
|
||||
|
||||
fn1 = repo.get_conversion((int,), ConversionPoint.from_fn(consumer, type_remap=type_remap),
|
||||
force_commutative=True, force_async=False, allow_async=False)
|
||||
|
||||
assert fn1(42) == 42
|
||||
|
||||
Reference in New Issue
Block a user