Merge pull request #2444 from NousResearch/hermes/hermes-31d7db3b

fix(tests): replace FakePath with monkeypatch for Python 3.12 compat
This commit is contained in:
Teknium 2026-03-22 03:52:56 -07:00 committed by GitHub
commit 887e8a8d84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -290,21 +290,17 @@ class TestEnsureUserSystemdEnv:
monkeypatch.delenv("DBUS_SESSION_BUS_ADDRESS", raising=False) monkeypatch.delenv("DBUS_SESSION_BUS_ADDRESS", raising=False)
monkeypatch.setattr(os, "getuid", lambda: 42) monkeypatch.setattr(os, "getuid", lambda: 42)
# Patch Path so /run/user/42 resolves to our tmp dir (which exists) # Patch Path.exists so /run/user/42 appears to exist.
from pathlib import Path as RealPath # Using a FakePath subclass breaks on Python 3.12+ where
# PosixPath.__new__ ignores the redirected path argument.
class FakePath(type(RealPath())): _orig_exists = gateway_cli.Path.exists
def __new__(cls, *args): monkeypatch.setattr(
p = str(args[0]) if args else "" gateway_cli.Path, "exists",
if p == "/run/user/42": lambda self: True if str(self) == "/run/user/42" else _orig_exists(self),
return RealPath.__new__(cls, str(tmp_path)) )
return RealPath.__new__(cls, *args)
monkeypatch.setattr(gateway_cli, "Path", FakePath)
gateway_cli._ensure_user_systemd_env() gateway_cli._ensure_user_systemd_env()
# Function sets the canonical string, not the fake path
assert os.environ.get("XDG_RUNTIME_DIR") == "/run/user/42" assert os.environ.get("XDG_RUNTIME_DIR") == "/run/user/42"
def test_sets_dbus_address_when_bus_socket_exists(self, tmp_path, monkeypatch): def test_sets_dbus_address_when_bus_socket_exists(self, tmp_path, monkeypatch):