Fix typing and minor issues

This commit is contained in:
Andras Schmelczer 2022-07-07 14:12:44 +02:00
parent 2db2253578
commit 72ab627a34
54 changed files with 635 additions and 589 deletions

View file

@ -0,0 +1,72 @@
from functools import lru_cache
import pytest
from great_ai import (
ArgumentValidationError,
GreatAI,
WrongDecoratorOrderError,
parameter,
)
def test_create_trivial_cases() -> None:
@GreatAI.create
def hello_world_1(name: str) -> str:
return f"Hello {name}!"
assert hello_world_1("andras").output == "Hello andras!"
@GreatAI.create
def hello_world_2(name): # type: ignore
return f"Hello {name}!"
assert hello_world_2("andras").output == "Hello andras!"
@GreatAI.create()
def hello_world_3(name: str) -> str:
return f"Hello {name}!"
assert hello_world_3("andras").output == "Hello andras!"
@GreatAI.create()
def hello_world_4(name): # type: ignore
return f"Hello {name}!"
assert hello_world_4("andras").output == "Hello andras!"
def test_create_with_other_decorator() -> None:
@GreatAI.create
@lru_cache
def hello_world_1(name: str) -> str:
return f"Hello {name}!"
assert hello_world_1("andras").output == "Hello andras!"
@lru_cache
@GreatAI.create()
def hello_world_2(name: str) -> str:
return f"Hello {name}!"
assert hello_world_2("andras").output == "Hello andras!"
def test_with_parameter() -> None:
@GreatAI.create
@parameter("name", validator=lambda v: len(v) > 5)
def hello_world(name: str) -> str:
return f"Hello {name}!"
assert hello_world("andras").output == "Hello andras!"
with pytest.raises(ArgumentValidationError):
hello_world("short")
def test_wrong_order() -> None:
with pytest.raises(WrongDecoratorOrderError):
@parameter("name", validator=lambda v: len(v) > 5)
@GreatAI.create
def hello_world(name: str) -> str:
return f"Hello {name}!"