"""douyin/handlers/screenshot_manager 子模块单元测试。 覆盖: - save_image: _sanitize_filename_part 纯函数 - save_files: 函数签名验证 """ from __future__ import annotations import pytest class TestSanitizeFilenamePart: """_sanitize_filename_part 纯函数测试。""" def test_empty_string(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part("") assert result == "" def test_none_input(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part(None) assert result == "" def test_removes_invalid_chars(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part('file<>:"/\\|?*name') assert "<" not in result assert ">" not in result assert ":" not in result assert '"' not in result assert "/" not in result assert "\\" not in result assert "|" not in result assert "?" not in result assert "*" not in result def test_normal_filename(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part("normal_filename") assert "normal" in result assert "filename" in result def test_chinese_filename(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part("福袋截图") assert "福袋" in result or len(result) > 0 def test_extracts_basename_from_path(self): from douyin.handlers.screenshot_manager.save_image import _sanitize_filename_part result = _sanitize_filename_part("/path/to/file.png") assert "path" not in result or "file" in result class TestSaveFilesModule: """save_files 模块测试。""" def test_cleanup_ocr_dir_exists(self): from douyin.handlers.screenshot_manager.save_files import cleanup_ocr_dir assert callable(cleanup_ocr_dir) def test_save_latest_attempt_exists(self): from douyin.handlers.screenshot_manager.save_files import save_latest_attempt assert callable(save_latest_attempt) def test_save_last_success_exists(self): from douyin.handlers.screenshot_manager.save_files import save_last_success assert callable(save_last_success) def test_save_attempt_from_file_exists(self): from douyin.handlers.screenshot_manager.save_files import save_attempt_from_file assert callable(save_attempt_from_file) def test_save_success_from_file_exists(self): from douyin.handlers.screenshot_manager.save_files import save_success_from_file assert callable(save_success_from_file) class TestSaveImageModule: """save_image 模块测试。""" def test_save_debug_image_exists(self): from douyin.handlers.screenshot_manager.save_image import save_debug_image assert callable(save_debug_image) class TestScreenshotManagerSubmodules: """screenshot_manager 子模块存在性测试。""" def test_paths_importable(self): from douyin.handlers.screenshot_manager import paths assert paths is not None def test_cleanup_importable(self): from douyin.handlers.screenshot_manager import cleanup assert cleanup is not None def test_async_save_importable(self): from douyin.handlers.screenshot_manager import async_save assert async_save is not None def test_save_files_importable(self): from douyin.handlers.screenshot_manager import save_files assert save_files is not None def test_save_image_importable(self): from douyin.handlers.screenshot_manager import save_image assert save_image is not None