def test_default(mock_env): p = param.Str(default="DEBUG") value = p("LOG_LEVEL") assert value == "DEBUG"
def test_prefix(mock_env): p = param.Str(prefix="THIS_") value = p("ONE") assert value == "dev"
def test_override(mock_env): p = param.Str(override="THIS_ONE") value = p("HOST") assert value == "dev"
def test_required_prefix(mock_env): p = param.Str(required=True, prefix="MY_FIRST_") with pytest.raises(KeyError) as e_info: p("APP") assert "MY_FIRST_APP" in str(e_info)
def test_not_required(mock_env): p = param.Str() value = p("PASSWORD") assert not value
def test_required(mock_env): p = param.Str(required=True) with pytest.raises(KeyError) as e_info: p("LOG_LEVEL") assert "LOG_LEVEL" in str(e_info)
class EnvTestConfig(EnvConfig): TEST_VAR = param.Int(default=45) NEW_VAR = param.Str(override="SET_THIS_VAR")
class Inherit(EnvTestConfig): SERVICE_VAR = param.Str() REMOTE_HOST = param.Str(default="no-host")
class DefaultAppConfig(EnvConfig): """App env config.""" HOST = param.Str(required=True) PORT = param.Int(required=True) PASSWORD = param.Str(override="SECRET_REDIS_PW", required=True)
class AppConfig(DefaultAppConfig): SERVICE = param.Str(prefix="MY_APP_") VERSION = param.Int(default=1) ENV = param.Str(default="prod") REMOTE_HOST = param.Int(default=0)