mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-09-30 03:01:21 +02:00
Fix plate detection calibration persistence
- Check cv2.imwrite() return value to catch silent failures - Verify reference image file exists after save - Validate file size is reasonable (>1KB) to detect corruption - Add logging for save, rotate, and delete operations - Use temp directory for plate calibration during tests to avoid deleting real user calibration files Previously, calibration could report success even if the image file failed to save. Additionally, running tests would delete real calibration files because tests shared the same plate_calibration_dir.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
"""Shared test fixtures for BamBuddy backend tests."""
|
||||
|
||||
import asyncio
|
||||
import atexit
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from collections.abc import AsyncGenerator
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -24,6 +28,19 @@ from backend.app.core.config import settings # noqa: E402
|
||||
|
||||
settings.log_to_file = False
|
||||
|
||||
# Use a temp directory for plate calibration to avoid deleting real calibration files
|
||||
_test_plate_cal_dir = Path(tempfile.mkdtemp(prefix="bambuddy_test_plate_cal_"))
|
||||
settings.plate_calibration_dir = _test_plate_cal_dir
|
||||
|
||||
|
||||
# Clean up temp directory when tests finish
|
||||
def _cleanup_test_plate_cal_dir():
|
||||
if _test_plate_cal_dir.exists():
|
||||
shutil.rmtree(_test_plate_cal_dir, ignore_errors=True)
|
||||
|
||||
|
||||
atexit.register(_cleanup_test_plate_cal_dir)
|
||||
|
||||
from backend.app.core.database import Base # noqa: E402
|
||||
|
||||
# Use in-memory SQLite for tests
|
||||
|
||||
Reference in New Issue
Block a user