-
Notifications
You must be signed in to change notification settings - Fork 802
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: check dependency close method * import annotations * return string only --------- Co-authored-by: YuXuan Tay <tay.yuxuan@gt.tech.gov.sg>
- Loading branch information
1 parent
1b3ea7e
commit a29f799
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
from starlette.testclient import TestClient | ||
|
||
import bentoml | ||
|
||
|
||
@bentoml.service(metrics={"enabled": False}) | ||
class Model: | ||
model = {"hello": "world"} | ||
|
||
@bentoml.api() | ||
def get(self, key: str) -> str: | ||
return self.model.get(key, "") | ||
|
||
|
||
@bentoml.service(metrics={"enabled": False}) | ||
class Service: | ||
model = bentoml.depends(Model) | ||
|
||
@bentoml.api() | ||
def get(self, key: str) -> dict[str, str]: | ||
return {"value": self.model.get(key)} | ||
|
||
|
||
def test_simple_service(): | ||
with TestClient(app=Model.to_asgi()) as client: | ||
resp = client.post("/get", json={"key": "hello"}) | ||
|
||
assert resp.status_code == 200 | ||
assert resp.text == "world" | ||
|
||
|
||
def test_composed_service(): | ||
with TestClient(app=Service.to_asgi()) as client: | ||
resp = client.post("/get", json={"key": "hello"}) | ||
|
||
assert resp.status_code == 200 | ||
assert resp.json() == {"value": "world"} |