mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 09:15:22 +03:00
tox tests initial commit
This commit is contained in:
parent
9edf38347c
commit
05c7c66147
19
.github/workflows/pull_request.yml
vendored
19
.github/workflows/pull_request.yml
vendored
@ -44,3 +44,22 @@ jobs:
|
|||||||
- name: Test
|
- name: Test
|
||||||
run: npm run test
|
run: npm run test
|
||||||
working-directory: ./web
|
working-directory: ./web
|
||||||
|
|
||||||
|
pytest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
python-version: ['3.8']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
python -m pip install --upgrade pip
|
||||||
|
python -m pip install tox tox-gh-actions
|
||||||
|
- name: Test with tox
|
||||||
|
run: tox -e unittests
|
||||||
|
|||||||
@ -77,9 +77,6 @@ class FrigateApp:
|
|||||||
self.config = user_config.runtime_config
|
self.config = user_config.runtime_config
|
||||||
|
|
||||||
for camera_name in self.config.cameras.keys():
|
for camera_name in self.config.cameras.keys():
|
||||||
# generage the ffmpeg commands
|
|
||||||
self.config.cameras[camera_name].create_ffmpeg_cmds()
|
|
||||||
|
|
||||||
# create camera_metrics
|
# create camera_metrics
|
||||||
self.camera_metrics[camera_name] = {
|
self.camera_metrics[camera_name] = {
|
||||||
"camera_fps": mp.Value("d", 0.0),
|
"camera_fps": mp.Value("d", 0.0),
|
||||||
|
|||||||
@ -537,6 +537,8 @@ class CameraConfig(FrigateBaseModel):
|
|||||||
return self._ffmpeg_cmds
|
return self._ffmpeg_cmds
|
||||||
|
|
||||||
def create_ffmpeg_cmds(self):
|
def create_ffmpeg_cmds(self):
|
||||||
|
if "_ffmpeg_cmds" in self:
|
||||||
|
return
|
||||||
ffmpeg_cmds = []
|
ffmpeg_cmds = []
|
||||||
for ffmpeg_input in self.ffmpeg.inputs:
|
for ffmpeg_input in self.ffmpeg.inputs:
|
||||||
ffmpeg_cmd = self._get_ffmpeg_cmd(ffmpeg_input)
|
ffmpeg_cmd = self._get_ffmpeg_cmd(ffmpeg_input)
|
||||||
@ -845,7 +847,8 @@ class FrigateConfig(FrigateBaseModel):
|
|||||||
logger.warning(
|
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."
|
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
|
config.cameras[name] = camera_config
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|||||||
20
frigate/test/README.md
Normal file
20
frigate/test/README.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Running unit tests from devcontainer
|
||||||
|
If you're using devcontainer, you can use the following command to run unit tests:
|
||||||
|
```
|
||||||
|
python3 -m unittest
|
||||||
|
```
|
||||||
|
|
||||||
|
# Running unit tests locally
|
||||||
|
Local development might be a bit trickier. The frigate has a defaults, which are not compatible with the local setup. For instance, `/labelmap.txt` should be located in the root.
|
||||||
|
|
||||||
|
To run unit tests, you can use `tox`.
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
Make sure you have python3.8 installed in your system. You also might need to install `python3.8-dev` package
|
||||||
|
```
|
||||||
|
sudo apt-get update && sudo apt-get install -y python3.8 python3.8-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running tests
|
||||||
|
To run tests, use `tox -e unittests` command.
|
||||||
|
`tox` uses pytest runner and rely on `conftest.py` to mock some of the modules and mock builtins.open to read the `/labelmap.txt` file.
|
||||||
26
frigate/test/conftest.py
Normal file
26
frigate/test/conftest.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest import mock
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def fake_open(filename, *args, **kvargs):
|
||||||
|
if filename == '/labelmap.txt':
|
||||||
|
content = "0 person\n1 bicycle"
|
||||||
|
else:
|
||||||
|
raise FileNotFoundError(filename)
|
||||||
|
file_object = mock.mock_open(read_data=content).return_value
|
||||||
|
file_object.__iter__.return_value = content.splitlines(True)
|
||||||
|
return file_object
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
|
def filesystem_mock():
|
||||||
|
with mock.patch("builtins.open", new=fake_open, create=True):
|
||||||
|
yield
|
||||||
|
|
||||||
|
# monkeypatch tflite_runtime
|
||||||
|
# in case of moving to the pytest completely, this can be done in more pyhonic way
|
||||||
|
module = type(sys)('tflite_runtime')
|
||||||
|
sys.modules['tflite_runtime'] = module
|
||||||
|
|
||||||
|
module = type(sys)('tflite_runtime.interpreter')
|
||||||
|
module.load_delegate = mock.MagicMock()
|
||||||
|
sys.modules['tflite_runtime.interpreter'] = module
|
||||||
17
frigate/test/requirements.test.txt
Normal file
17
frigate/test/requirements.test.txt
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
opencv-python-headless
|
||||||
|
numpy
|
||||||
|
imutils
|
||||||
|
scipy
|
||||||
|
psutil
|
||||||
|
Flask
|
||||||
|
paho-mqtt
|
||||||
|
PyYAML
|
||||||
|
matplotlib
|
||||||
|
click
|
||||||
|
setproctitle
|
||||||
|
peewee
|
||||||
|
peewee_migrate
|
||||||
|
pydantic
|
||||||
|
zeroconf
|
||||||
|
ws4py
|
||||||
|
pytest
|
||||||
@ -572,7 +572,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert config == frigate_config.dict(exclude_unset=True)
|
assert config == frigate_config.dict(exclude_unset=True)
|
||||||
|
|
||||||
runtime_config = frigate_config.runtime_config
|
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):
|
def test_motion_contour_area_dynamic(self):
|
||||||
|
|
||||||
@ -601,7 +601,7 @@ class TestConfig(unittest.TestCase):
|
|||||||
assert config == frigate_config.dict(exclude_unset=True)
|
assert config == frigate_config.dict(exclude_unset=True)
|
||||||
|
|
||||||
runtime_config = frigate_config.runtime_config
|
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):
|
def test_merge_labelmap(self):
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import cv2
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from unittest import TestCase, main
|
from unittest import TestCase, main
|
||||||
from frigate.video import box_overlaps, reduce_boxes
|
from frigate.video import box_overlaps, reduce_boxes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user