mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-10 09:07:37 +03:00
Fix formatting and patching
This commit is contained in:
parent
d99cdda5a7
commit
9ae54e1b2f
@ -1,28 +1,20 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
MOCK_MODULES = [
|
MOCK_MODULES = [
|
||||||
"cv2",
|
"frigate.data_processing.real_time.custom_classification.cv2",
|
||||||
# "numpy",
|
"frigate.data_processing.real_time.custom-classification.load_labels",
|
||||||
"zmq",
|
"frigate.data_processing.real_time.custom-classification.write_classification_attempt",
|
||||||
"peewee",
|
"frigate.data_processing.real_time.custom-classification.log",
|
||||||
"sherpa_onnx",
|
]
|
||||||
"pydantic",
|
AUTO_SPEC_MOCK_MODULES = [
|
||||||
"pydantic.fields",
|
"frigate.data_processing.real_time.custom_classification.Interpreter",
|
||||||
"frigate.comms.inter_process",
|
"frigate.data_processing.real_time.custom_classification.InferenceSpeed",
|
||||||
"frigate.comms.event_metadata_updater",
|
"frigate.data_processing.real_time.custom_classification.InterProcessRequestor",
|
||||||
"frigate.comms.embeddings_updater",
|
"frigate.data_processing.real_time.custom_classification.EventMetadataPublisher",
|
||||||
"frigate.log",
|
|
||||||
"tflite_runtime",
|
|
||||||
"tflite_runtime.interpreter",
|
|
||||||
"tensorflow",
|
|
||||||
"tensorflow.lite",
|
|
||||||
"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
|
WIDTH = 720
|
||||||
HEIGHT = 1280
|
HEIGHT = 1280
|
||||||
@ -209,31 +201,31 @@ class TestCustomObjectClassificationIntegration(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
"""Import the processor after mocking dependencies"""
|
"""Import the processor after mocking dependencies"""
|
||||||
# Create a better mock for pydantic to handle type annotations
|
|
||||||
pydantic_mock = MagicMock()
|
|
||||||
# Mock BaseModel as a simple class
|
|
||||||
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):
|
def cvtColor(frame, color):
|
||||||
return self.np.zeros((WIDTH, HEIGHT, 3), dtype=self.np.uint8)
|
return self.np.zeros((WIDTH, HEIGHT, 3), dtype=self.np.uint8)
|
||||||
|
|
||||||
def resize(frame, size):
|
def resize(frame, size):
|
||||||
return self.np.zeros((*size, 3), dtype=self.np.uint8)
|
return self.np.zeros((*size[0:1], 3), dtype=self.np.uint8)
|
||||||
cv2_mock.cvtColor = cvtColor
|
|
||||||
cv2_mock.resize = resize
|
|
||||||
|
|
||||||
|
self.patchers = {}
|
||||||
for mod in MOCK_MODULES:
|
for mod in MOCK_MODULES:
|
||||||
sys.modules[mod] = MagicMock()
|
patcher = patch(mod).start()
|
||||||
sys.modules["pydantic"] = pydantic_mock
|
self.patchers[mod] = patcher
|
||||||
sys.modules["cv2"] = cv2_mock
|
self.addCleanup(patcher.stop)
|
||||||
|
|
||||||
|
for mod in AUTO_SPEC_MOCK_MODULES:
|
||||||
|
patcher = patch(mod, autospec=True).start()
|
||||||
|
self.patchers[mod] = patcher
|
||||||
|
self.addCleanup(patcher.stop)
|
||||||
|
patcher.return_value = MagicMock()
|
||||||
|
|
||||||
|
mock_cv2 = self.patchers["frigate.data_processing.real_time.custom_classification.cv2"]
|
||||||
|
|
||||||
# Import numpy after it's been mocked
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
|
||||||
|
|
||||||
self.np = np
|
self.np = np
|
||||||
|
mock_cv2.cvtColor.side_effect = cvtColor
|
||||||
|
mock_cv2.resize.side_effect = resize
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from frigate.data_processing.real_time.custom_classification import (
|
from frigate.data_processing.real_time.custom_classification import (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user