mirror of https://github.com/nicolargo/glances.git
Add Dynaconf test
This commit is contained in:
parent
f1bd18a3a5
commit
0c57cbda0c
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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...
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue