blob: 8498e2f84395d7ad0518a1f4e30ce02f211fe312 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
"""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
|