mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-18 07:29:45 +00:00
Migrate to pydantic TypeAdapter
https://pydantic.dev/docs/validation/2.12/get-started/migration/#introduction-of-typeadapter
This commit is contained in:
parent
f74664a50d
commit
6e344b8b88
@ -3,7 +3,7 @@ from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import numpy as np
|
||||
import zmq
|
||||
from pydantic import parse_obj_as
|
||||
from pydantic import TypeAdapter
|
||||
|
||||
import frigate.detectors as detectors
|
||||
import frigate.object_detection.base
|
||||
@ -20,8 +20,8 @@ class TestLocalObjectDetector(unittest.TestCase):
|
||||
"frigate.detectors.api_types",
|
||||
{det_type: Mock() for det_type in DetectorTypeEnum},
|
||||
):
|
||||
test_cfg = parse_obj_as(
|
||||
DetectorConfig, ({"type": det_type, "model": {}})
|
||||
test_cfg = TypeAdapter(DetectorConfig).validate_python(
|
||||
{"type": det_type, "model": {}}
|
||||
)
|
||||
test_cfg.model.path = "/test/modelpath"
|
||||
test_obj = frigate.object_detection.base.LocalObjectDetector(
|
||||
@ -45,7 +45,9 @@ class TestLocalObjectDetector(unittest.TestCase):
|
||||
TEST_DATA = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
TEST_DETECT_RESULT = np.ndarray([1, 2, 4, 8, 16, 32])
|
||||
test_obj_detect = frigate.object_detection.base.LocalObjectDetector(
|
||||
detector_config=parse_obj_as(DetectorConfig, {"type": "cpu", "model": {}})
|
||||
detector_config=TypeAdapter(DetectorConfig).validate_python(
|
||||
{"type": "cpu", "model": {}}
|
||||
)
|
||||
)
|
||||
|
||||
mock_det_api = mock_cputfl.return_value
|
||||
@ -68,7 +70,9 @@ class TestLocalObjectDetector(unittest.TestCase):
|
||||
TEST_DATA = np.zeros((1, 32, 32, 3), np.uint8)
|
||||
TEST_DETECT_RESULT = np.ndarray([1, 2, 4, 8, 16, 32])
|
||||
|
||||
test_cfg = parse_obj_as(DetectorConfig, {"type": "cpu", "model": {}})
|
||||
test_cfg = TypeAdapter(DetectorConfig).validate_python(
|
||||
{"type": "cpu", "model": {}}
|
||||
)
|
||||
test_cfg.model.input_tensor = InputTensorEnum.nchw
|
||||
|
||||
test_obj_detect = frigate.object_detection.base.LocalObjectDetector(
|
||||
@ -117,7 +121,9 @@ class TestLocalObjectDetector(unittest.TestCase):
|
||||
4: "label-5",
|
||||
}
|
||||
|
||||
test_cfg = parse_obj_as(DetectorConfig, {"type": "cpu", "model": {}})
|
||||
test_cfg = TypeAdapter(DetectorConfig).validate_python(
|
||||
{"type": "cpu", "model": {}}
|
||||
)
|
||||
test_cfg.model = ModelConfig()
|
||||
test_obj_detect = frigate.object_detection.base.LocalObjectDetector(
|
||||
detector_config=test_cfg,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user