Implement background exclusion and refactor folder structure
- Added configurable background exclusion (#1f2937) with tolerance - Implemented alpha thresholding (>= 128) to eliminate edge artifacts - Refactored folder structure into analyses/[slug]/images, settings, and results - Updated pattern puller to skip existing images and handle network errors - Updated .gitignore and automated tests for path integrity
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from PySide6 import QtWidgets
|
||||
from app.qt.main_window import MainWindow
|
||||
from app.qt.pattern_puller import PatternDownloadWorker
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def qt_app():
|
||||
from PySide6.QtWidgets import QApplication
|
||||
import sys
|
||||
app = QApplication.instance()
|
||||
if app is None:
|
||||
app = QApplication(sys.argv)
|
||||
yield app
|
||||
|
||||
|
||||
def test_export_settings_path_generation(qt_app, tmp_path):
|
||||
mock_widget = QtWidgets.QWidget()
|
||||
mock_widget.title_label = MagicMock()
|
||||
mock_widget.apply_theme = MagicMock()
|
||||
with patch('app.qt.main_window.TitleBar', return_value=mock_widget):
|
||||
window = MainWindow(language="en", defaults={}, reset_exclusions=False)
|
||||
|
||||
with patch("PySide6.QtWidgets.QFileDialog.getSaveFileName", return_value=("", "")) as mock_get_save:
|
||||
|
||||
# Test case 1: New subfolder structure (analyses/m4a1-s/images/1.png)
|
||||
root = tmp_path / "analyses" / "m4a1_s"
|
||||
img_dir = root / "images"
|
||||
img_dir.mkdir(parents=True)
|
||||
img_path = img_dir / "1.png"
|
||||
|
||||
window._current_image_path = img_path
|
||||
window.export_settings()
|
||||
|
||||
# Verify settings directory was created
|
||||
assert (root / "settings").exists()
|
||||
|
||||
# Verify default path given to QFileDialog
|
||||
args, kwargs = mock_get_save.call_args
|
||||
# args[2] is the default path string
|
||||
expected_path = str(root / "settings" / "icra_settings_m4a1_s.json")
|
||||
assert args[2] == expected_path
|
||||
|
||||
|
||||
def test_export_folder_path_generation(qt_app, tmp_path):
|
||||
mock_widget = QtWidgets.QWidget()
|
||||
mock_widget.title_label = MagicMock()
|
||||
mock_widget.apply_theme = MagicMock()
|
||||
with patch('app.qt.main_window.TitleBar', return_value=mock_widget):
|
||||
window = MainWindow(language="en", defaults={}, reset_exclusions=False)
|
||||
|
||||
with patch("PySide6.QtWidgets.QFileDialog.getSaveFileName", return_value=("", "")) as mock_get_save:
|
||||
# Mock processor paths
|
||||
root = tmp_path / "analyses" / "m4a1_s"
|
||||
img_dir = root / "images"
|
||||
img_dir.mkdir(parents=True)
|
||||
window.processor.preview_paths = [img_dir / "1.png"]
|
||||
|
||||
window.export_folder()
|
||||
|
||||
assert (root / "results").exists()
|
||||
args, kwargs = mock_get_save.call_args
|
||||
expected_path = str(root / "results" / "icra_results_m4a1_s.csv")
|
||||
assert args[2] == expected_path
|
||||
|
||||
|
||||
def test_pattern_download_worker_dir(tmp_path):
|
||||
worker = PatternDownloadWorker(slug="test-slug", save_dir=tmp_path / "analyses" / "test-slug" / "images")
|
||||
assert worker.save_dir == tmp_path / "analyses" / "test-slug" / "images"
|
||||
Reference in New Issue
Block a user