Update test style
This commit is contained in:
parent
f188724d4b
commit
2db2253578
18 changed files with 778 additions and 686 deletions
62
tests/great_ai/test_async_starters.py
Normal file
62
tests/great_ai/test_async_starters.py
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
from asyncio import sleep
|
||||
|
||||
import pytest
|
||||
|
||||
from great_ai import (
|
||||
ArgumentValidationError,
|
||||
GreatAI,
|
||||
WrongDecoratorOrderError,
|
||||
parameter,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_trivial_cases() -> None:
|
||||
@GreatAI.create
|
||||
async def hello_world_1(name: str) -> str:
|
||||
await sleep(0.5)
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert (await hello_world_1("andras").output) == "Hello andras!"
|
||||
|
||||
@GreatAI.create
|
||||
async def hello_world_2(name: str) -> str:
|
||||
await sleep(0.5)
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert (await hello_world_2("andras").output) == "Hello andras!"
|
||||
|
||||
@GreatAI.create()
|
||||
async def hello_world_3(name: str) -> str:
|
||||
await sleep(0.5)
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert (await hello_world_3("andras").output) == "Hello andras!"
|
||||
|
||||
@GreatAI.create()
|
||||
async def hello_world_4(name):
|
||||
await sleep(0.5)
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert (await hello_world_4("andras").output) == "Hello andras!"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_with_parameter() -> None:
|
||||
@GreatAI.create
|
||||
@parameter("name", validator=lambda v: len(v) > 5)
|
||||
async def hello_world(name: str) -> str:
|
||||
await sleep(0.5)
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert (await hello_world("andras").output) == "Hello andras!"
|
||||
|
||||
with pytest.raises(ArgumentValidationError):
|
||||
await hello_world("short")
|
||||
|
||||
with pytest.raises(WrongDecoratorOrderError):
|
||||
|
||||
@parameter("name", validator=lambda v: len(v) > 5)
|
||||
@GreatAI.create
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import unittest
|
||||
from functools import lru_cache
|
||||
|
||||
import pytest
|
||||
|
|
@ -11,55 +10,62 @@ from great_ai import (
|
|||
)
|
||||
|
||||
|
||||
class TestHumanReadableToByte(unittest.TestCase):
|
||||
def test_create_simple_cases(self) -> None:
|
||||
@GreatAI.create
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
def test_create_trivial_cases() -> None:
|
||||
@GreatAI.create
|
||||
def hello_world_1(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
assert hello_world_1("andras").output == "Hello andras!"
|
||||
|
||||
@GreatAI.create
|
||||
def hello_world(name):
|
||||
return f"Hello {name}!"
|
||||
@GreatAI.create
|
||||
def hello_world_2(name):
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
assert hello_world_2("andras").output == "Hello andras!"
|
||||
|
||||
@GreatAI.create()
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
@GreatAI.create()
|
||||
def hello_world_3(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
assert hello_world_3("andras").output == "Hello andras!"
|
||||
|
||||
def test_create_with_other_decorator(self) -> None:
|
||||
@GreatAI.create
|
||||
@lru_cache
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
@GreatAI.create()
|
||||
def hello_world_4(name):
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
assert hello_world_4("andras").output == "Hello andras!"
|
||||
|
||||
@lru_cache
|
||||
@GreatAI.create()
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
def test_create_with_other_decorator() -> None:
|
||||
@GreatAI.create
|
||||
@lru_cache
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
|
||||
@lru_cache
|
||||
@GreatAI.create()
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("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")
|
||||
|
||||
with pytest.raises(WrongDecoratorOrderError):
|
||||
|
||||
def test_with_parameter(self) -> None:
|
||||
@GreatAI.create
|
||||
@parameter("name", validator=lambda v: len(v) > 5)
|
||||
@GreatAI.create
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
||||
assert hello_world("andras").output == "Hello andras!"
|
||||
|
||||
with pytest.raises(ArgumentValidationError):
|
||||
hello_world("short")
|
||||
|
||||
with pytest.raises(WrongDecoratorOrderError):
|
||||
|
||||
@parameter("name", validator=lambda v: len(v) > 5)
|
||||
@GreatAI.create
|
||||
def hello_world(name: str) -> str:
|
||||
return f"Hello {name}!"
|
||||
|
|
|
|||
9
tests/great_ai/test_great_ai.py
Normal file
9
tests/great_ai/test_great_ai.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
from great_ai import GreatAI
|
||||
|
||||
|
||||
def test_process_batch() -> None:
|
||||
@GreatAI.create(return_raw_result=True)
|
||||
def f(x):
|
||||
return x + 2
|
||||
|
||||
assert f.process_batch([3, 9, 34]) == [5, 11, 36]
|
||||
Loading…
Add table
Add a link
Reference in a new issue