Open smidm opened 1 month ago
It depends on how you test your API, can you show an example of testing function?
I'm mocking following:
pose_service
pose
MMPoseModel
pose
def mock_pose(self, image, persons):
return [
Person(
top_left=person.top_left,
bottom_right=person.bottom_right,
detection_confidence=person.detection_confidence,
keypoints=[],
) for person in persons
]
# bypass the pose estimation and return the detection results
monkeypatch.setattr('pose_service.pose.MMPoseModel.inner.pose.func', mock_pose)
sample_image = Image.new('RGB', (200, 100)) # width, height
service = poseservice()
# force both
img, rotation_ccw, persons = service.detect_pose_and_image_rotation(
sample_image,
rotation_ccw=90,
bounding_box=BoundingBox(
top_left=Coordinate(x=0.1, y=0.1),
bottom_right=Coordinate(x=0.2, y=0.2),
)
)
assert img.shape == (200, 100, 3)
assert rotation_ccw == 90
assert len(persons) == 1
assert isinstance(persons[0], Person)
assert persons[0].top_left == Coordinate(x=0.1, y=0.1)
assert persons[0].bottom_right == Coordinate(x=0.2, y=0.2)
service = poseservice()
What is poseservice()
and how does it interact with the mocked service?
Feature request
I really appreciated https://docs.bentoml.com/en/latest/guides/testing.html#unit-tests. It would be helpful to include also docs on mocking the bentoml decorated API methods.
The api method defined at
package.module.Service.api_endpoint
is located after the application of@bentoml.service
and@bentoml.api
decorators atpackage.module.Service.inner.api_endpoint.func
, which is not clear.I use:
Motivation
No response
Other
No response