mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-09-27 17:58:47 +00:00
python: match backend switch error text
This commit is contained in:
@@ -230,8 +230,8 @@ def lib_for(backend: Backend) -> ctypes.CDLL:
|
||||
if _lib is not None:
|
||||
if _backend != backend:
|
||||
raise RuntimeError(
|
||||
f"libsimplex already loaded with backend={_backend!r}; "
|
||||
f"cannot switch to {backend!r} in the same process"
|
||||
f"libsimplex already loaded with backend={_backend}; "
|
||||
f"cannot switch to {backend} in the same process"
|
||||
)
|
||||
return _lib
|
||||
libs_dir = _resolve_libs_dir(backend)
|
||||
|
||||
@@ -3,7 +3,8 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from simplex_chat._native import _cache_root, _download, _resolve_libs_dir
|
||||
from simplex_chat import _native
|
||||
from simplex_chat._native import _cache_root, _download, _resolve_libs_dir, lib_for
|
||||
from simplex_chat._version import LIBS_VERSION
|
||||
|
||||
|
||||
@@ -97,7 +98,18 @@ def test_libc_on_windows_is_ucrt(monkeypatch):
|
||||
loaded: list[str | None] = []
|
||||
monkeypatch.setattr("sys.platform", "win32")
|
||||
monkeypatch.setattr("ctypes.CDLL", lambda name: loaded.append(name))
|
||||
from simplex_chat import _native
|
||||
|
||||
_native._load_libc()
|
||||
assert loaded == ["ucrtbase"]
|
||||
|
||||
|
||||
def test_lib_for_rejects_backend_switch(monkeypatch):
|
||||
monkeypatch.setattr(_native, "_lib", object())
|
||||
monkeypatch.setattr(_native, "_backend", "sqlite")
|
||||
monkeypatch.setattr(
|
||||
_native, "_resolve_libs_dir", lambda _: pytest.fail("must not resolve libs")
|
||||
)
|
||||
with pytest.raises(RuntimeError) as exc:
|
||||
lib_for("postgres")
|
||||
assert str(exc.value) == (
|
||||
"libsimplex already loaded with backend=sqlite; cannot switch to postgres in the same process"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user