"""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