Skip to content

Commit

Permalink
refactor shared code to helper function, tests still pass
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinland committed Feb 12, 2025
1 parent c01b450 commit ad05127
Showing 1 changed file with 17 additions and 36 deletions.
53 changes: 17 additions & 36 deletions tests/test_motiondetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def getMD():
md.camera = FakeCamera("test")
return md

@staticmethod
async def get_output(md):
out = await md.capture_all_from_camera("test",return_image=True,
return_classifications=True,
return_detections=True,
return_object_point_clouds=True)
assert isinstance(out, CaptureAllResult)
assert out.image is not None
assert out.classifications is not None
assert len(out.classifications) == 1
assert out.classifications[0]["class_name"] == "motion"
return out


def test_validate(self):
md = self.getMD()
Expand Down Expand Up @@ -79,15 +92,7 @@ async def test_properties(self):
@pytest.mark.asyncio
async def test_captureall(self):
md = self.getMD()
out = await md.capture_all_from_camera("test",return_image=True,
return_classifications=True,
return_detections=True,
return_object_point_clouds=True)
assert isinstance(out, CaptureAllResult)
assert out.image is not None
assert out.classifications is not None
assert len(out.classifications) == 1
assert out.classifications[0]["class_name"] == "motion"
out = await self.get_output(md)
assert out.detections is not None
assert out.detections[0]["class_name"] == "motion"
assert out.objects is None
Expand All @@ -97,15 +102,7 @@ async def test_captureall(self):
async def test_captureall_not_too_large(self):
md = self.getMD()
md.max_box_size = 1000000000
out = await md.capture_all_from_camera("test",return_image=True,
return_classifications=True,
return_detections=True,
return_object_point_clouds=True)
assert isinstance(out, CaptureAllResult)
assert out.image is not None
assert out.classifications is not None
assert len(out.classifications) == 1
assert out.classifications[0]["class_name"] == "motion"
out = await self.get_output(md)
assert out.detections is not None
assert out.detections[0]["class_name"] == "motion"
assert out.objects is None
Expand All @@ -115,29 +112,13 @@ async def test_captureall_not_too_large(self):
async def test_captureall_too_small(self):
md = self.getMD()
md.min_box_size = 1000000000
out = await md.capture_all_from_camera("test",return_image=True,
return_classifications=True,
return_detections=True,
return_object_point_clouds=True)
assert isinstance(out, CaptureAllResult)
assert out.image is not None
assert out.classifications is not None
assert len(out.classifications) == 1
assert out.classifications[0]["class_name"] == "motion"
out = await self.get_output(md)
assert out.detections == []


@pytest.mark.asyncio
async def test_captureall_too_large(self):
md = self.getMD()
md.max_box_size = 5
out = await md.capture_all_from_camera("test",return_image=True,
return_classifications=True,
return_detections=True,
return_object_point_clouds=True)
assert isinstance(out, CaptureAllResult)
assert out.image is not None
assert out.classifications is not None
assert len(out.classifications) == 1
assert out.classifications[0]["class_name"] == "motion"
out = await self.get_output(md)
assert out.detections == []

0 comments on commit ad05127

Please sign in to comment.