Пример #1
0
def test_try_include():
    """
    We test using dev-default.py
    """
    scope = {}
    settings_manager = SettingsManager(scope)

    env_file = os.path.join(os.path.dirname(__file__), "dev-default.py")
    settings_manager.try_include(env_file)
    assert scope["TEST_SETTING"] == "hello"
Пример #2
0
def test_try_include_non_default():
    """
    We test instantiating SettingsManager with name 'settings'
    and using dev-non-default.py
    """
    scope = {}
    settings = SettingsManager(scope, "settings")

    env_file = os.path.join(os.path.dirname(__file__), "dev-non-default.py")
    settings.try_include(env_file)
    assert scope["TEST_SETTING"] == "hello"
Пример #3
0
settings_manager = SettingsManager(globals())
settings_manager.set_option("TEST_SETTING", "world")
print(TEST_SETTING)

# setting from env
os.environ["ENV_SETTING"] = "my_setting"  # setting env variable
settings_manager.set_from_env("ENV_SETTING")
print(ENV_SETTING)

# setting boolean
settings_manager.set_bool("BOOL_SETTING", False)
print(BOOL_SETTING)

# setting boolean overriden from env var from env
os.environ["ENV_BOOL"] = "True"  # setting env variable
settings_manager.set_bool("ENV_BOOL", False)
print(ENV_BOOL)

# setting int from env
os.environ["ENV_INT"] = "123"  # setting env variable
settings_manager.set_option("ENV_INT", None, envvar_type=int)
print(ENV_INT)

# setting default
settings_manager.set_default("DEFAULT_SETTING", "my_defualt")
print(DEFAULT_SETTING)

# include another file (./test.py)
settings_manager.try_include("./test.py")
print(EXTERNAL_SETTING)