Skip to content

Commit

Permalink
validate test
Browse files Browse the repository at this point in the history
  • Loading branch information
kharijarrett committed Jul 15, 2024
1 parent de0f0a4 commit 1083c07
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build:
setup:
./build.sh

test:
Expand Down
2 changes: 2 additions & 0 deletions src/motion_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def new_service(
@classmethod
def validate_config(cls, config: ServiceConfig) -> Sequence[str]:
source_cam = config.attributes.fields["cam_name"].string_value
if source_cam == "":
raise Exception("Source camera must be provided as 'cam_name'")
min_boxsize = config.attributes.fields["min_box_size"].number_value
if min_boxsize < 0:
raise Exception("Minimum bounding box size should be a positive integer")
Expand Down
26 changes: 22 additions & 4 deletions tests/test_motiondetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
from PIL import Image
from unittest.mock import MagicMock, patch
from viam.components.camera import Camera
from viam.proto.app.robot import ComponentConfig
from google.protobuf.struct_pb2 import Struct
from viam.services.vision import CaptureAllResult, Classification, Detection
from typing import List
from typing import List, Mapping, Any

import pytest
import cv2
import numpy as np

def make_component_config(dictionary: Mapping[str, Any]) -> ComponentConfig:
struct = Struct()
struct.update(dictionary=dictionary)
return ComponentConfig(attributes=struct)




class TestMotionDetector:

def getMD(self):
Expand All @@ -19,10 +29,18 @@ def getMD(self):
md.cam_name = "test"
md.camera = FakeCamera("test")
return md


def test_validate(self):
md = self.getMD()
empty_config = make_component_config({})
config =make_component_config({
"cam_name": "test"
})
with pytest.raises(Exception):
response = md.validate_config(config=empty_config)
response = md.validate_config(config=config)

def test_blah(self):
x = "blah"
assert "h" in x

def test_classifications(self):
img1 = Image.open("tests/img1.jpg")
Expand Down

0 comments on commit 1083c07

Please sign in to comment.