Skip to content

Commit

Permalink
Merge pull request #23 from viam-labs/side
Browse files Browse the repository at this point in the history
lock np
  • Loading branch information
kharijarrett authored Jul 15, 2024
2 parents 75eb996 + 1083c07 commit cabc26b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 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: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pillow == 10.0.1
numpy==2.0.0
numpy == 1.25.0
viam-sdk
pyinstaller
pylint
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 cabc26b

Please sign in to comment.