Set up mcquack as a proper uv package with flat layout (no src/ directory). Uses hatchling build backend to support single-file module structure. Added pytest as dev dependency with fixtures for testing against temporary directories instead of actual macOS LaunchAgent paths. - Rename list() to list_agents() to avoid shadowing builtin (Python 3.14 compat) - Add mock_dirs fixture that monkeypatches LAUNCH_AGENTS_DIR and LOGS_DIR - Add mock_script and mock_launchctl fixtures - 26 tests covering list, create, edit, show, delete commands - Parameterized tests for argument handling - XML validation tests independent of plistlib Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
61 lines
1.5 KiB
Python
61 lines
1.5 KiB
Python
"""Pytest configuration and fixtures for mcquack tests."""
|
|
|
|
import os
|
|
import stat
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_dirs(tmp_path, monkeypatch):
|
|
"""Set up temporary directories for LAUNCH_AGENTS_DIR and LOGS_DIR.
|
|
|
|
Returns a dict with the paths for test assertions.
|
|
"""
|
|
import mcquack
|
|
|
|
launch_agents_dir = tmp_path / "LaunchAgents"
|
|
logs_dir = tmp_path / "Logs"
|
|
launch_agents_dir.mkdir()
|
|
logs_dir.mkdir()
|
|
|
|
monkeypatch.setattr(mcquack, "LAUNCH_AGENTS_DIR", launch_agents_dir)
|
|
monkeypatch.setattr(mcquack, "LOGS_DIR", logs_dir)
|
|
|
|
return {
|
|
"launch_agents_dir": launch_agents_dir,
|
|
"logs_dir": logs_dir,
|
|
"tmp_path": tmp_path,
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_script(tmp_path):
|
|
"""Create a mock executable script for testing.
|
|
|
|
Returns the path to the script.
|
|
"""
|
|
script = tmp_path / "test_script.sh"
|
|
script.write_text("#!/bin/bash\necho 'hello'\n")
|
|
script.chmod(script.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
return script
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_launchctl(monkeypatch):
|
|
"""Mock subprocess.run to avoid actual launchctl calls.
|
|
|
|
Returns a list that captures all subprocess.run calls for assertions.
|
|
"""
|
|
import subprocess
|
|
|
|
calls = []
|
|
|
|
def mock_run(args, **kwargs):
|
|
calls.append({"args": args, "kwargs": kwargs})
|
|
result = subprocess.CompletedProcess(args=args, returncode=0, stdout="", stderr="")
|
|
return result
|
|
|
|
monkeypatch.setattr("subprocess.run", mock_run)
|
|
return calls
|