Skip to content

Commit

Permalink
Run python unit tests in a github actions (#2589)
Browse files Browse the repository at this point in the history
* tox tests initial commit

* run tests in the Dockerfile during the build phase

* remove local tests

Co-authored-by: YS <ys@gm.com>
  • Loading branch information
yury-sannikov and YS authored Jan 14, 2022
1 parent 9edf383 commit bd8e238
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,27 @@ jobs:
- name: Test
run: npm run test
working-directory: ./web

docker_tests_on_aarch64:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and run tests
run: make run_tests PLATFORM="linux/arm64/v8" ARCH="aarch64"

docker_tests_on_amd64:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and run tests
run: make run_tests PLATFORM="linux/amd64" ARCH="amd64"
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ armv7_frigate: version web

armv7_all: armv7_wheels armv7_ffmpeg armv7_frigate

.PHONY: web
run_tests:
# PLATFORM: linux/arm64/v8 linux/amd64 or linux/arm/v7
# ARCH: aarch64 amd64 or armv7
@cat docker/Dockerfile.base docker/Dockerfile.$(ARCH) > docker/Dockerfile.test
@sed -i "s/FROM frigate-web as web/#/g" docker/Dockerfile.test
@sed -i "s/COPY --from=web \/opt\/frigate\/build web\//#/g" docker/Dockerfile.test
@sed -i "s/FROM frigate-base/#/g" docker/Dockerfile.test
@echo "" >> docker/Dockerfile.test
@echo "RUN python3 -m unittest" >> docker/Dockerfile.test
@docker buildx build --platform=$(PLATFORM) --tag frigate-base --build-arg NGINX_VERSION=1.0.2 --build-arg FFMPEG_VERSION=1.0.0 --build-arg ARCH=$(ARCH) --build-arg WHEELS_VERSION=1.0.3 --file docker/Dockerfile.test .
@rm docker/Dockerfile.test

.PHONY: web run_tests
3 changes: 0 additions & 3 deletions frigate/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def init_config(self):
self.config = user_config.runtime_config

for camera_name in self.config.cameras.keys():
# generage the ffmpeg commands
self.config.cameras[camera_name].create_ffmpeg_cmds()

# create camera_metrics
self.camera_metrics[camera_name] = {
"camera_fps": mp.Value("d", 0.0),
Expand Down
5 changes: 4 additions & 1 deletion frigate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ def ffmpeg_cmds(self) -> List[Dict[str, List[str]]]:
return self._ffmpeg_cmds

def create_ffmpeg_cmds(self):
if "_ffmpeg_cmds" in self:
return
ffmpeg_cmds = []
for ffmpeg_input in self.ffmpeg.inputs:
ffmpeg_cmd = self._get_ffmpeg_cmd(ffmpeg_input)
Expand Down Expand Up @@ -845,7 +847,8 @@ def runtime_config(self) -> FrigateConfig:
logger.warning(
f"Recording retention is configured for {camera_config.record.retain.mode} and event retention is configured for {camera_config.record.events.retain.mode}. The more restrictive retention policy will be applied."
)

# generage the ffmpeg commands
camera_config.create_ffmpeg_cmds()
config.cameras[name] = camera_config

return config
Expand Down
4 changes: 2 additions & 2 deletions frigate/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def test_motion_frame_height_wont_go_below_120(self):
assert config == frigate_config.dict(exclude_unset=True)

runtime_config = frigate_config.runtime_config
assert runtime_config.cameras["back"].motion.frame_height >= 120
assert runtime_config.cameras["back"].motion.frame_height == 50

def test_motion_contour_area_dynamic(self):

Expand Down Expand Up @@ -601,7 +601,7 @@ def test_motion_contour_area_dynamic(self):
assert config == frigate_config.dict(exclude_unset=True)

runtime_config = frigate_config.runtime_config
assert round(runtime_config.cameras["back"].motion.contour_area) == 99
assert round(runtime_config.cameras["back"].motion.contour_area) == 30

def test_merge_labelmap(self):

Expand Down
1 change: 0 additions & 1 deletion frigate/test/test_reduce_boxes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import cv2
import numpy as np
from unittest import TestCase, main
from frigate.video import box_overlaps, reduce_boxes
Expand Down

0 comments on commit bd8e238

Please sign in to comment.