File size: 1,368 Bytes
e8055cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """Global test setup that keeps unit tests independent of optional native packages."""
from __future__ import annotations
import importlib.util
import sys
import types
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
class _FakeCapture:
def __init__(self, path):
self.path = path
def get(self, prop):
return 0.0
def release(self):
pass
if importlib.util.find_spec("cv2") is None and "cv2" not in sys.modules:
cv2 = types.ModuleType("cv2")
cv2.CAP_PROP_FPS = 5
cv2.INTER_NEAREST = 0
cv2.MORPH_CLOSE = 3
cv2.RETR_EXTERNAL = 0
cv2.RETR_CCOMP = 2
cv2.CHAIN_APPROX_SIMPLE = 0
cv2.GC_PR_BGD = 2
cv2.GC_PR_FGD = 3
cv2.GC_FGD = 1
cv2.GC_INIT_WITH_MASK = 1
cv2.VideoCapture = _FakeCapture
cv2.resize = lambda image, size, interpolation=None: image
cv2.erode = lambda image, kernel, iterations=1: image
cv2.dilate = lambda image, kernel, iterations=1: image
cv2.morphologyEx = lambda image, op, kernel: image
cv2.findContours = lambda image, mode, method: ([], None)
cv2.approxPolyDP = lambda contour, epsilon, closed: contour
cv2.contourArea = lambda contour: 0
cv2.imread = lambda path: None
cv2.grabCut = lambda *args, **kwargs: None
sys.modules["cv2"] = cv2
|