"""Unit tests of the Python helpers in steamify-cachyos/patches (stdlib only). Run through tests/python-test.sh (REPO = the Steamify checkout), or: REPO=../steamify-cachyos python3 -m unittest tests/patches_test.py -v """ import contextlib import importlib.util import io import os import struct import tempfile import unittest from unittest import mock REPO = os.environ.get("REPO") or os.path.join(os.path.dirname(__file__), "..", "..", "steamify-cachyos") def load(name, filename): spec = importlib.util.spec_from_file_location(name, os.path.join(REPO, "patches", filename)) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod shortcuts = load("steam_shortcuts", "steam-shortcuts.py") notifier = load("steamify_notifier", "steamify-notifier.py") class VdfTests(unittest.TestCase): def test_roundtrip(self): root = [("shortcuts", [("0", [("appid", 123), ("AppName", "A"), ("tags", [])])])] self.assertEqual(shortcuts.parse(shortcuts.dump(root)), root) def test_empty_data_is_an_empty_list(self): self.assertEqual(shortcuts.parse(b""), [("shortcuts", [])]) def test_unknown_type_is_an_error(self): with self.assertRaises(ValueError): shortcuts.parse(b"\x07key\0") def test_ints_are_unsigned_32_bit(self): data = shortcuts.dump([("n", -1)]) self.assertEqual(struct.unpack_from("