mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-10 09:07:37 +03:00
Mock cvtColor and resize from cv2 module
This commit is contained in:
parent
cf41ed8b79
commit
d99cdda5a7
37
.github/workflows/pull_request.yml
vendored
37
.github/workflows/pull_request.yml
vendored
@ -72,30 +72,8 @@ jobs:
|
||||
run: |
|
||||
ruff check frigate migrations docker *.py
|
||||
|
||||
devcontainer:
|
||||
runs-on: ubuntu-latest
|
||||
name: Build devcontainer
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Pre-build devcontainer image
|
||||
uses: devcontainers/ci@v0.3
|
||||
with:
|
||||
imageName: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||
push: always
|
||||
|
||||
python_tests:
|
||||
runs-on: ubuntu-latest
|
||||
needs: devcontainer
|
||||
name: Python Tests
|
||||
steps:
|
||||
- name: Check out code
|
||||
@ -108,15 +86,12 @@ jobs:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Pre-Run mypy in devcontainer
|
||||
- name: Build devcontainer image and run checks
|
||||
uses: devcontainers/ci@v0.3
|
||||
with:
|
||||
imageName: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||
push: never
|
||||
runCmd: python3 -u -m mypy --config-file frigate/mypy.ini frigate
|
||||
- name: Pre-Run mypy in devcontainer
|
||||
uses: devcontainers/ci@v0.3
|
||||
with:
|
||||
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||
push: never
|
||||
runCmd: python3 -u -m unittest
|
||||
push: always
|
||||
runCmd: |-
|
||||
python3 -u -m mypy --config-file frigate/mypy.ini frigate &&
|
||||
python3 -u -m unittest
|
||||
|
||||
@ -4,7 +4,7 @@ import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
MOCK_MODULES = [
|
||||
# "cv2",
|
||||
"cv2",
|
||||
# "numpy",
|
||||
"zmq",
|
||||
"peewee",
|
||||
@ -22,9 +22,11 @@ MOCK_MODULES = [
|
||||
"tensorflow.lite.python",
|
||||
"tensorflow.lite.python.interpreter",
|
||||
]
|
||||
|
||||
ORIGINAL_MODULES = {mod: sys.modules[mod] for mod in MOCK_MODULES if mod in sys.modules}
|
||||
|
||||
WIDTH = 720
|
||||
HEIGHT = 1280
|
||||
|
||||
|
||||
class TestCustomObjectClassificationZones(unittest.TestCase):
|
||||
"""Test that zone information is correctly added to custom classification MQTT messages"""
|
||||
@ -213,14 +215,24 @@ class TestCustomObjectClassificationIntegration(unittest.TestCase):
|
||||
pydantic_mock.BaseModel = type("BaseModel", (), {})
|
||||
pydantic_mock.Field = MagicMock(return_value=None)
|
||||
pydantic_mock.ConfigDict = MagicMock(return_value={})
|
||||
# Create a better mock for cv2 to handle calculations
|
||||
cv2_mock = MagicMock()
|
||||
def cvtColor(frame, color):
|
||||
return self.np.zeros((WIDTH, HEIGHT, 3), dtype=self.np.uint8)
|
||||
def resize(frame, size):
|
||||
return self.np.zeros((*size, 3), dtype=self.np.uint8)
|
||||
cv2_mock.cvtColor = cvtColor
|
||||
cv2_mock.resize = resize
|
||||
|
||||
for mod in MOCK_MODULES:
|
||||
sys.modules[mod] = MagicMock()
|
||||
sys.modules["pydantic"] = pydantic_mock
|
||||
sys.modules["cv2"] = cv2_mock
|
||||
|
||||
# Import numpy after it's been mocked
|
||||
import numpy as np
|
||||
|
||||
import cv2
|
||||
|
||||
self.np = np
|
||||
|
||||
try:
|
||||
@ -288,7 +300,7 @@ class TestCustomObjectClassificationIntegration(unittest.TestCase):
|
||||
]
|
||||
|
||||
# Create frame
|
||||
frame = self.np.zeros((720, 1280, 3), dtype=self.np.uint8)
|
||||
frame = self.np.zeros((WIDTH, HEIGHT, 3), dtype=self.np.uint8)
|
||||
|
||||
# Mock TFLite
|
||||
processor.interpreter = MagicMock()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user