about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-07-03 10:54:24 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-07-03 10:54:24 +0300
commitdb430d45af995079bd33b35665c1fc664d7d316e (patch)
treeb5bec5a30ed5d0831af5a2d0c48a2a63b6e7a0c6
parent257e0a3f5fcff3b138ffbc42efd8ac27c95763ba (diff)
downloadfungus-launcher-db430d45af995079bd33b35665c1fc664d7d316e.tar.gz
fungus-launcher-db430d45af995079bd33b35665c1fc664d7d316e.tar.xz
some new basic tests
-rw-r--r--tests/test_proton_steamrt_mapping.py82
-rw-r--r--tests/test_steamrt_timestamp.py83
2 files changed, 165 insertions, 0 deletions
diff --git a/tests/test_proton_steamrt_mapping.py b/tests/test_proton_steamrt_mapping.py
new file mode 100644
index 0000000..ec9f12f
--- /dev/null
+++ b/tests/test_proton_steamrt_mapping.py
@@ -0,0 +1,82 @@
+"""Tests for proton-to-SteamRuntime version mapping helpers."""
+
+from fungus.umu_manager import extract_proton_version, proton_to_steamrt_variant
+
+
+class TestExtractProtonVersion:
+    """Tests for the extract_proton_version helper."""
+
+    def test_proton_official_11(self):
+        assert extract_proton_version("Proton-11.0-1") == "11"
+
+    def test_proton_official_10(self):
+        assert extract_proton_version("Proton-10.0-1") == "10"
+
+    def test_proton_official_9(self):
+        assert extract_proton_version("Proton-9.0-1") == "9"
+
+    def test_ge_proton_11(self):
+        assert extract_proton_version("GE-Proton11-1") == "11"
+
+    def test_ge_proton_10(self):
+        assert extract_proton_version("GE-Proton10-1") == "10"
+
+    def test_ge_proton_9(self):
+        assert extract_proton_version("GE-Proton9-11") == "9"
+
+    def test_em_proton(self):
+        assert extract_proton_version("EM-1.0") == "1"
+
+    def test_empty_string(self):
+        assert extract_proton_version("") is None
+
+    def test_none(self):
+        assert extract_proton_version(None) is None
+
+    def test_unknown_prefix(self):
+        # Unknown prefixes are not stripped, so parsing fails
+        assert extract_proton_version("Unknown-5.0") is None
+
+    def test_no_version_number(self):
+        assert extract_proton_version("Proton-") is None
+
+    def test_ge_proton_no_number(self):
+        assert extract_proton_version("GE-Proton") is None
+
+
+class TestProtonToSteamrtVariant:
+    """Tests for the proton_to_steamrt_variant helper."""
+
+    def test_proton_11(self):
+        assert proton_to_steamrt_variant("Proton-11.0-1") == "steamrt4"
+
+    def test_proton_10(self):
+        assert proton_to_steamrt_variant("Proton-10.0-1") == "steamrt3"
+
+    def test_proton_9(self):
+        assert proton_to_steamrt_variant("Proton-9.0-1") == "steamrt3"
+
+    def test_ge_proton_11(self):
+        assert proton_to_steamrt_variant("GE-Proton11-1") == "steamrt4"
+
+    def test_ge_proton_10(self):
+        assert proton_to_steamrt_variant("GE-Proton10-1") == "steamrt3"
+
+    def test_ge_proton_9(self):
+        assert proton_to_steamrt_variant("GE-Proton9-11") == "steamrt3"
+
+    def test_em_proton(self):
+        assert proton_to_steamrt_variant("EM-1.0") == "steamrt3"
+
+    def test_empty_fallback(self):
+        assert proton_to_steamrt_variant("") == "steamrt3"
+
+    def test_none_fallback(self):
+        assert proton_to_steamrt_variant(None) == "steamrt3"
+
+    def test_unknown_prefix_fallback(self):
+        # Unknown prefix → no version extracted → falls back to steamrt3
+        assert proton_to_steamrt_variant("Unknown-5.0") == "steamrt3"
+
+    def test_no_version_fallback(self):
+        assert proton_to_steamrt_variant("Proton-") == "steamrt3"
diff --git a/tests/test_steamrt_timestamp.py b/tests/test_steamrt_timestamp.py
new file mode 100644
index 0000000..f0fcecb
--- /dev/null
+++ b/tests/test_steamrt_timestamp.py
@@ -0,0 +1,83 @@
+"""Tests for fungus.umu_manager — Steam Runtime timestamp helpers."""
+
+import os
+from pathlib import Path
+from unittest.mock import patch
+
+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)
+    path = steamrt_dir / "steamrt.txt"
+    return path
+
+
+@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, patched_steamrt_file):
+        from fungus import umu_manager as um
+        from fungus.umu_manager import save_steamrt_last_check as _save
+
+        # Point to a non-writable location
+        um.STEAMRT_CHECK_FILE = "/root/steamrt.txt"
+        result = _save()
+        assert result is False
+
+        # Restore
+        um.STEAMRT_CHECK_FILE = str(patched_steamrt_file)