How to use environs - 10 common examples

To help you get started, we’ve selected a few environs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sloria / environs / tests / test_environs.py View on Github external
def test_env_isolation(set_env):
    set_env({"FOO": "foo"})
    env1 = environs.Env()

    @env1.parser_for("foo")
    def foo(value):
        return value

    env2 = environs.Env()

    # env1 has a parser for foo, but env2 does not
    assert env1.foo("FOO") == "foo"
    with pytest.raises(AttributeError):
        env2.foo("FOO")
github sloria / environs / tests / test_environs.py View on Github external
def env(self):
        return environs.Env(eager=False)
github sloria / environs / tests / test_environs.py View on Github external
def enum_parser(value, choices):
            if value not in choices:
                raise environs.EnvError("Invalid!")
            return value
github sloria / environs / tests / test_environs.py View on Github external
def always_fail(value):
    raise environs.EnvError("something went wrong")
github sloria / environs / tests / test_environs.py View on Github external
def test_error_message_for_prefixed_var(self, env):
        with env.prefixed("APP_"):
            with pytest.raises(environs.EnvError, match='Environment variable "APP_INT" invalid'):
                env.int("INT", validate=lambda val: val < 42)
github sloria / environs / tests / test_environs.py View on Github external
def test_custom_parser_not_called_after_seal(self, env, set_env):
        set_env({"URL": "test.test/"})

        @env.parser_for("https_url")
        def https_url(value):
            return "https://" + value

        env.seal()
        with pytest.raises(environs.EnvSealedError, match="Env has already been sealed"):
            env.https_url("URL")
github sloria / environs / tests / test_environs.py View on Github external
def test_validation(self, env, set_env):
        set_env({"INT": "invalid", "DTIME": "notadatetime"})
        env.int("INT")
        env.datetime("DTIME")
        env.str("REQUIRED")
        with pytest.raises(environs.EnvValidationError) as excinfo:
            env.seal()
        exc = excinfo.value
        msg = exc.args[0]
        assert "REQUIRED" in msg
        assert "INT" in msg
        assert "DTIME" in msg
        assert "REQUIRED" in exc.error_messages
        assert "INT" in exc.error_messages
        assert "DTIME" in exc.error_messages
github sloria / environs / tests / test_environs.py View on Github external
def test_cannot_override_built_in_parser(self, set_env, env):
        def https_url(value):
            return "https://" + value

        with pytest.raises(environs.ParserConflictError):
            env.add_parser("url", https_url)
github Python3WebSpider / AdslProxy / adslproxy / settings.py View on Github external
# coding=utf-8
from environs import Env

env = Env()

# 拨号间隔,单位秒
DIAL_CYCLE = env.int('DIAL_CYCLE', 100)
# 拨号出错重试间隔
DIAL_ERROR_CYCLE = env.int('DIAL_ERROR_CYCLE', 5)
# 拨号命令
DIAL_BASH = env.str('DIAL_BASH', 'adsl-stop;adsl-start')
# 拨号网卡
DIAL_IFNAME = env.str('DIAL_IFNAME', 'ppp0')

# 客户端唯一标识
CLIENT_NAME = env.str('CLIENT_NAME', 'adsl1')

# Redis数据库IP
REDIS_HOST = env.str('REDIS_HOST', 'localhost')
# Redis数据库密码, 如无则填None