Skip to content

Commit

Permalink
fix: add dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
xianml committed May 27, 2024
1 parent e3100fd commit 9486a4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
11 changes: 10 additions & 1 deletion tests/e2e/bento_new_sdk/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import subprocess
import sys
from pathlib import Path

import pytest
Expand All @@ -8,7 +10,14 @@

@pytest.fixture(scope="package", autouse=True)
def prepare_models() -> None:
pass
for example in E2E_EXAMPLES:
if not (EXAMPLE_DIR / example / "prepare_model.py").exists():
continue
subprocess.run(
[sys.executable, str(EXAMPLE_DIR / example / "prepare_model.py")],
check=True,
cwd=str(EXAMPLE_DIR / example),
)


@pytest.fixture
Expand Down
2 changes: 2 additions & 0 deletions tests/e2e/bento_new_sdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
scikit-learn
pydantic>=2
transformers
torch
29 changes: 19 additions & 10 deletions tests/e2e/bento_new_sdk/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@

port = 35678

EXAMPLE_INPUT = "Breaking News: In an astonishing turn of events, the small \
town of Willow Creek has been taken by storm as local resident Jerry Thompson's cat, \
Whiskers, performed what witnesses are calling a 'miraculous and gravity-defying leap.' \
Eyewitnesses report that Whiskers, an otherwise unremarkable tabby cat, jumped \
a record-breaking 20 feet into the air to catch a fly. The event, which took \
place in Thompson's backyard, is now being investigated by scientists for potential \
breaches in the laws of physics. Local authorities are considering a town festival \
to celebrate what is being hailed as 'The Leap of the Century."


@pytest.mark.asyncio
async def test_async_serve_and_prediction(examples: Path) -> None:
Expand All @@ -26,29 +35,29 @@ async def test_async_serve_and_prediction(examples: Path) -> None:
],
)

await asyncio.sleep(5)
await asyncio.sleep(30)

try:
with bentoml.SyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result

async with bentoml.AsyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = await client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = await client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result
finally:
server.terminate()


def test_local_prediction(examples: Path) -> None:
service = bentoml.load(str(examples / "quickstart"))()
result = service.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = service.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result


def test_build_and_prediction(examples: Path) -> None:
bento = bentoml.bentos.build(
"service.py:IrisClassifier", build_ctx=str(examples / "quickstart")
"service.py:Summarization", build_ctx=str(examples / "quickstart")
)
server = subprocess.Popen(
[
Expand All @@ -64,7 +73,7 @@ def test_build_and_prediction(examples: Path) -> None:

try:
with bentoml.SyncHTTPClient(f"http://127.0.0.1:{port}") as client:
result = client.classify([[4.9, 3.0, 1.4, 0.2]])
assert result == [0]
result = client.summarize(EXAMPLE_INPUT)
assert "Whiskers" in result
finally:
server.terminate()

0 comments on commit 9486a4f

Please sign in to comment.