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: |
|
run: |
|
||||||
ruff check frigate migrations docker *.py
|
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:
|
python_tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: devcontainer
|
|
||||||
name: Python Tests
|
name: Python Tests
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
@ -108,15 +86,12 @@ jobs:
|
|||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.repository_owner }}
|
username: ${{ github.repository_owner }}
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
- name: Pre-Run mypy in devcontainer
|
- name: Build devcontainer image and run checks
|
||||||
uses: devcontainers/ci@v0.3
|
uses: devcontainers/ci@v0.3
|
||||||
with:
|
with:
|
||||||
|
imageName: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||||
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
||||||
push: never
|
push: always
|
||||||
runCmd: python3 -u -m mypy --config-file frigate/mypy.ini frigate
|
runCmd: |-
|
||||||
- name: Pre-Run mypy in devcontainer
|
python3 -u -m mypy --config-file frigate/mypy.ini frigate &&
|
||||||
uses: devcontainers/ci@v0.3
|
python3 -u -m unittest
|
||||||
with:
|
|
||||||
cacheFrom: ${{ env.REGISTRY }}/${{ env.DEV_IMAGE_NAME }}
|
|
||||||
push: never
|
|
||||||
runCmd: python3 -u -m unittest
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import unittest
|
|||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
MOCK_MODULES = [
|
MOCK_MODULES = [
|
||||||
# "cv2",
|
"cv2",
|
||||||
# "numpy",
|
# "numpy",
|
||||||
"zmq",
|
"zmq",
|
||||||
"peewee",
|
"peewee",
|
||||||
@ -22,9 +22,11 @@ MOCK_MODULES = [
|
|||||||
"tensorflow.lite.python",
|
"tensorflow.lite.python",
|
||||||
"tensorflow.lite.python.interpreter",
|
"tensorflow.lite.python.interpreter",
|
||||||
]
|
]
|
||||||
|
|
||||||
ORIGINAL_MODULES = {mod: sys.modules[mod] for mod in MOCK_MODULES if mod in sys.modules}
|
ORIGINAL_MODULES = {mod: sys.modules[mod] for mod in MOCK_MODULES if mod in sys.modules}
|
||||||
|
|
||||||
|
WIDTH = 720
|
||||||
|
HEIGHT = 1280
|
||||||
|
|
||||||
|
|
||||||
class TestCustomObjectClassificationZones(unittest.TestCase):
|
class TestCustomObjectClassificationZones(unittest.TestCase):
|
||||||
"""Test that zone information is correctly added to custom classification MQTT messages"""
|
"""Test that zone information is correctly added to custom classification MQTT messages"""
|
||||||
@ -213,13 +215,23 @@ class TestCustomObjectClassificationIntegration(unittest.TestCase):
|
|||||||
pydantic_mock.BaseModel = type("BaseModel", (), {})
|
pydantic_mock.BaseModel = type("BaseModel", (), {})
|
||||||
pydantic_mock.Field = MagicMock(return_value=None)
|
pydantic_mock.Field = MagicMock(return_value=None)
|
||||||
pydantic_mock.ConfigDict = MagicMock(return_value={})
|
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:
|
for mod in MOCK_MODULES:
|
||||||
sys.modules[mod] = MagicMock()
|
sys.modules[mod] = MagicMock()
|
||||||
sys.modules["pydantic"] = pydantic_mock
|
sys.modules["pydantic"] = pydantic_mock
|
||||||
|
sys.modules["cv2"] = cv2_mock
|
||||||
|
|
||||||
# Import numpy after it's been mocked
|
# Import numpy after it's been mocked
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import cv2
|
||||||
|
|
||||||
self.np = np
|
self.np = np
|
||||||
|
|
||||||
@ -288,7 +300,7 @@ class TestCustomObjectClassificationIntegration(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Create frame
|
# 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
|
# Mock TFLite
|
||||||
processor.interpreter = MagicMock()
|
processor.interpreter = MagicMock()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user