test: isolate embedding device env override tests

Agent-Logs-Url: https://github.com/MemPalace/mempalace/sessions/3213a67a-6871-4bb2-9ae0-23fa11001a22

Co-authored-by: igorls <4753812+igorls@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-24 23:09:23 +00:00
committed by GitHub
parent 25c885ae0b
commit 9fbdba17ca
+7 -7
View File
@@ -20,12 +20,14 @@ def test_config_from_file():
assert cfg.palace_path == "/custom/palace" assert cfg.palace_path == "/custom/palace"
def test_embedding_device_defaults_to_auto(): def test_embedding_device_defaults_to_auto(monkeypatch):
monkeypatch.delenv("MEMPALACE_EMBEDDING_DEVICE", raising=False)
cfg = MempalaceConfig(config_dir=tempfile.mkdtemp()) cfg = MempalaceConfig(config_dir=tempfile.mkdtemp())
assert cfg.embedding_device == "auto" assert cfg.embedding_device == "auto"
def test_embedding_device_from_config_is_normalized(tmp_path): def test_embedding_device_from_config_is_normalized(tmp_path, monkeypatch):
monkeypatch.delenv("MEMPALACE_EMBEDDING_DEVICE", raising=False)
with open(tmp_path / "config.json", "w") as f: with open(tmp_path / "config.json", "w") as f:
json.dump({"embedding_device": " CUDA "}, f) json.dump({"embedding_device": " CUDA "}, f)
@@ -33,15 +35,13 @@ def test_embedding_device_from_config_is_normalized(tmp_path):
assert cfg.embedding_device == "cuda" assert cfg.embedding_device == "cuda"
def test_embedding_device_env_overrides_config(tmp_path): def test_embedding_device_env_overrides_config(tmp_path, monkeypatch):
with open(tmp_path / "config.json", "w") as f: with open(tmp_path / "config.json", "w") as f:
json.dump({"embedding_device": "cpu"}, f) json.dump({"embedding_device": "cpu"}, f)
os.environ["MEMPALACE_EMBEDDING_DEVICE"] = " CoreML " monkeypatch.setenv("MEMPALACE_EMBEDDING_DEVICE", " CoreML ")
try:
cfg = MempalaceConfig(config_dir=str(tmp_path)) cfg = MempalaceConfig(config_dir=str(tmp_path))
assert cfg.embedding_device == "coreml" assert cfg.embedding_device == "coreml"
finally:
del os.environ["MEMPALACE_EMBEDDING_DEVICE"]
def test_env_override(): def test_env_override():