Files
SQLmem/tests/test_config.py
T

54 lines
1.3 KiB
Python

import importlib
import sqlmem.config as cfg
def _reload(monkeypatch, **env_vars):
for key in ("SQLMEM_DEBUG", "SQLMEM_CACHE_DB", "SQLMEM_BACKUP_INTERVAL"):
monkeypatch.delenv(key, raising=False)
for key, val in env_vars.items():
monkeypatch.setenv(key, val)
importlib.reload(cfg)
def test_debug_defaults_to_false(monkeypatch):
_reload(monkeypatch)
assert cfg.DEBUG is False
def test_debug_true(monkeypatch):
_reload(monkeypatch, SQLMEM_DEBUG="true")
assert cfg.DEBUG is True
def test_debug_case_insensitive(monkeypatch):
_reload(monkeypatch, SQLMEM_DEBUG="TRUE")
assert cfg.DEBUG is True
def test_debug_explicit_false(monkeypatch):
_reload(monkeypatch, SQLMEM_DEBUG="false")
assert cfg.DEBUG is False
def test_cache_db_default_name(monkeypatch):
_reload(monkeypatch)
assert cfg.CACHE_DB_PATH.name == "cache.db"
def test_cache_db_custom_path(monkeypatch, tmp_path):
custom = str(tmp_path / "my_cache.db")
_reload(monkeypatch, SQLMEM_CACHE_DB=custom)
assert cfg.CACHE_DB_PATH == tmp_path / "my_cache.db"
def test_backup_interval_default(monkeypatch):
_reload(monkeypatch)
assert cfg.BACKUP_INTERVAL_SECONDS == 3600
def test_backup_interval_custom(monkeypatch):
_reload(monkeypatch, SQLMEM_BACKUP_INTERVAL="7200")
assert cfg.BACKUP_INTERVAL_SECONDS == 7200