Add Dynaconf test

This commit is contained in:
nicolargo 2025-11-04 23:10:17 +01:00
parent f1bd18a3a5
commit 0c57cbda0c
3 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,7 @@ dependencies = [
"windows-curses; platform_system == 'Windows'",
"shtab; platform_system != 'Windows'",
"jinja2",
"dynaconf[ini]>=3.2.12",
]
description = "A cross-platform curses-based monitoring tool"
dynamic = ["version"]

View File

@ -0,0 +1,15 @@
# Test python-decouple
# https://github.com/HBNetwork/python-decouple
import os
from decouple import Config, RepositoryIni
GLANCES_CONFIG_FILE = os.environ.get("GLANCES_CONFIG_FILE", "../../conf/glances.conf")
print(f"Using config file: {GLANCES_CONFIG_FILE}")
config = Config(RepositoryIni(GLANCES_CONFIG_FILE))
print(config.get('refresh', cast=int))
# 👉 Python-decouple does not support multiple sections in .ini files natively...

View File

@ -0,0 +1,23 @@
# Test Dynaconf
# https://www.dynaconf.com/
import os
from dynaconf import Dynaconf, Validator
GLANCES_CONFIG_FILE = os.environ.get("GLANCES_CONFIG_FILE", "../../conf/glances.conf")
print(f"Using config file: {GLANCES_CONFIG_FILE}")
settings = Dynaconf(settings_files=[GLANCES_CONFIG_FILE])
# Cast and validate settings
settings.validators.register(Validator("global.refresh", cast=int, gte=1))
settings.validators.validate()
# print(settings.global.refresh) <== global is a Python keyword so error
# read as a string from ini file
assert settings.get('global').get('refresh') == 2
assert settings.GLOBAL.refresh == 2
assert settings['global']['refresh'] == 2
assert settings['global.refresh'] == 2