"""Tests for fungus.umu_manager — Steam Runtime timestamp helpers.""" import pytest @pytest.fixture() def tmp_steamrt_file(tmp_data_dir): """Provide a temporary steamrt.txt path in the user data directory.""" steamrt_dir = tmp_data_dir / "fungus-launcher" steamrt_dir.mkdir(parents=True, exist_ok=True) return steamrt_dir / "steamrt.txt" @pytest.fixture() def patched_steamrt_file(tmp_steamrt_file): """Patch STEAMRT_CHECK_FILE to point to a temporary file.""" from fungus import umu_manager as um original = um.STEAMRT_CHECK_FILE um.STEAMRT_CHECK_FILE = str(tmp_steamrt_file) yield tmp_steamrt_file um.STEAMRT_CHECK_FILE = original class TestGetSteamrtLastCheck: def test_returns_none_when_file_missing(self, patched_steamrt_file): # Ensure file does not exist patched_steamrt_file.unlink(missing_ok=True) from fungus.umu_manager import get_steamrt_last_check assert get_steamrt_last_check() is None def test_returns_timestamp_when_file_exists(self, patched_steamrt_file): patched_steamrt_file.write_text("2025-07-01 14:30") from fungus.umu_manager import get_steamrt_last_check assert get_steamrt_last_check() == "2025-07-01 14:30" def test_returns_none_when_file_empty(self, patched_steamrt_file): patched_steamrt_file.write_text("") from fungus.umu_manager import get_steamrt_last_check assert get_steamrt_last_check() is None def test_strips_whitespace(self, patched_steamrt_file): patched_steamrt_file.write_text(" 2025-06-15 09:00 \n") from fungus.umu_manager import get_steamrt_last_check assert get_steamrt_last_check() == "2025-06-15 09:00" class TestSaveSteamrtLastCheck: def test_writes_timestamp(self, patched_steamrt_file): from fungus.umu_manager import save_steamrt_last_check result = save_steamrt_last_check() assert result is True content = patched_steamrt_file.read_text().strip() # Should match YYYY-MM-DD HH:MM pattern assert len(content) == 16 assert content[4] == "-" assert content[7] == "-" assert content[10] == " " assert content[13] == ":" def test_returns_false_on_write_failure(self, monkeypatch): from fungus.umu_manager import save_steamrt_last_check as _save # Mock open to raise OSError, ensuring the test works even as root def mock_open_raises(*args, **kwargs): raise OSError("Permission denied") monkeypatch.setattr("builtins.open", mock_open_raises) result = _save() assert result is False