d93da0d8b4
CI / Lint, Typecheck & Test (push) Has been cancelled
将 src/pyflowx/cli/_ops/ 整体迁移至 src/pyflowx/ops/, 与 cli/ 平级 (工具函数非 CLI 专属, 可被 YAML 任务编排通用引用). 分类保持不变: dev (git/pip/bump/autofmt), files (date/level/back/zip), media (pdf/screenshot), system (ls/pack/ssh). 同步更新 15 个引用文件 (yaml_loader + 14 个测试) 的 import 路径, README 模块结构表与 test_registry docstring.
98 lines
4.4 KiB
Python
98 lines
4.4 KiB
Python
"""Tests for cli.screenshot module."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from pyflowx.conditions import Constants
|
|
from pyflowx.ops import media
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# get_screenshot_path
|
|
# ---------------------------------------------------------------------- #
|
|
class TestGetScreenshotPath:
|
|
"""Test get_screenshot_path function."""
|
|
|
|
def test_get_screenshot_path_with_filename(self, tmp_path: Path) -> None:
|
|
"""Should get screenshot path with filename."""
|
|
with patch.object(Path, "home", return_value=tmp_path):
|
|
result = media.get_screenshot_path("test.png")
|
|
assert result.name == "test.png"
|
|
|
|
def test_get_screenshot_path_without_filename(self, tmp_path: Path) -> None:
|
|
"""Should get screenshot path without filename."""
|
|
with patch.object(Path, "home", return_value=tmp_path):
|
|
result = media.get_screenshot_path()
|
|
assert "screenshot_" in result.name
|
|
assert result.suffix == ".png"
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# take_screenshot_full
|
|
# ---------------------------------------------------------------------- #
|
|
class TestTakeScreenshotFull:
|
|
"""Test take_screenshot_full function."""
|
|
|
|
def test_take_screenshot_full_windows(self, tmp_path: Path) -> None:
|
|
"""Should take full screenshot on Windows."""
|
|
with patch.object(Constants, "IS_WINDOWS", True), patch.object(Constants, "IS_MACOS", False), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_full()
|
|
assert mock_run.called
|
|
|
|
def test_take_screenshot_full_macos(self, tmp_path: Path) -> None:
|
|
"""Should take full screenshot on macOS."""
|
|
with patch.object(Constants, "IS_WINDOWS", False), patch.object(Constants, "IS_MACOS", True), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_full()
|
|
assert mock_run.called
|
|
|
|
def test_take_screenshot_full_linux(self, tmp_path: Path) -> None:
|
|
"""Should take full screenshot on Linux."""
|
|
with patch.object(Constants, "IS_WINDOWS", False), patch.object(Constants, "IS_MACOS", False), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_full()
|
|
assert mock_run.called
|
|
|
|
|
|
# ---------------------------------------------------------------------- #
|
|
# take_screenshot_area
|
|
# ---------------------------------------------------------------------- #
|
|
class TestTakeScreenshotArea:
|
|
"""Test take_screenshot_area function."""
|
|
|
|
def test_take_screenshot_area_windows(self, tmp_path: Path) -> None:
|
|
"""Should take area screenshot on Windows."""
|
|
with patch.object(Constants, "IS_WINDOWS", True), patch.object(Constants, "IS_MACOS", False), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_area()
|
|
assert mock_run.called
|
|
|
|
def test_take_screenshot_area_macos(self, tmp_path: Path) -> None:
|
|
"""Should take area screenshot on macOS."""
|
|
with patch.object(Constants, "IS_WINDOWS", False), patch.object(Constants, "IS_MACOS", True), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_area()
|
|
assert mock_run.called
|
|
|
|
def test_take_screenshot_area_linux(self, tmp_path: Path) -> None:
|
|
"""Should take area screenshot on Linux."""
|
|
with patch.object(Constants, "IS_WINDOWS", False), patch.object(Constants, "IS_MACOS", False), patch.object(
|
|
Path, "home", return_value=tmp_path
|
|
), patch("subprocess.run") as mock_run:
|
|
mock_run.return_value = MagicMock(returncode=0)
|
|
media.take_screenshot_area()
|
|
assert mock_run.called
|