Esempio n. 1
0
 def test_env_var_is_set_then_gets_removed_without_default_raises_exception(self):
     os.environ["FOO"] = "BAR"
     config = Config()
     config.from_envar("FOO")
     del os.environ["FOO"]
     with pytest.raises(KeyError):
         config["FOO"]
Esempio n. 2
0
 def test_from_env_var_with_default_value(self):
     config = Config()
     os.environ["FOO"] = "BAR"
     config.from_envar("FOO", default="BAZ")
     assert config["FOO"] == "BAR"
     del os.environ["FOO"]
     assert config["FOO"] == "BAZ"
Esempio n. 3
0
    def test_from_envar_that_doesnt_exist_raises_warning(self):
        config = Config()
        with pytest.warns(RuntimeWarning) as warn:
            config.from_envar("BAR")

        assert len(warn) == 1
        assert "not found" in warn[0].message.args[0]
Esempio n. 4
0
def test_env_var_is_set_then_gets_removed_with_default_value_set():
    config = Config()
    config.from_object(DevConfig)
    config.from_envar("FOO")
    assert config["FOO"] == "BAR"
    del os.environ["FOO"]
    assert config["FOO"] == "BAZ"
Esempio n. 5
0
 def test_from_envar_and_change_after_setting_value(self):
     os.environ["FOO"] = "BAR"
     config = Config()
     config.from_envar("FOO")
     assert config["FOO"] == "BAR"
     os.environ["FOO"] = "BAZ"
     assert config["FOO"] == "BAZ"
     del os.environ["FOO"]
Esempio n. 6
0
 def test_from_env_var_with_default_value_and_alias(self):
     config = Config()
     os.environ["FOO"] = "BAR"
     config.from_envar("FOO", rename="FOOBAR", default="BAZ")
     assert config["FOOBAR"] == "BAR"
     del os.environ["FOO"]
     assert config["FOOBAR"] == "BAZ"
     with pytest.raises(KeyError):
         config["FOO"]  # should not be part of config
Esempio n. 7
0
 def test_env_var_can_be_renamed(self):
     try:
         del os.environ["FOO_DEBUG"]
     except KeyError:
         pass
     os.environ["FOO_DEBUG"] = "true"
     config = Config()
     config.from_envar("FOO_DEBUG", rename="DEBUG")
     assert config["DEBUG"] is True
Esempio n. 8
0
 def test_user_can_change_value_manually_but_env_value_takes_precedence(self):
     os.environ["FOO"] = "expected"
     config = Config()
     config["FOO"] = "not expected"
     config.from_envar("FOO")
     assert config["FOO"] == "expected"
Esempio n. 9
0
 def test_from_envar_that_doesnt_exist_but_exists_in_config_object(self):
     config = Config()
     config["BAR"] = "BAZ"
     config.from_envar("BAR")
     assert "BAR" in config
     assert config["BAR"] == "BAZ"
Esempio n. 10
0
 def test_from_env_var_that_equals_not_found(self):
     config = Config()
     os.environ["FOO"] = "not found"
     config.from_envar("FOO")
     assert config["FOO"] == "not found"
Esempio n. 11
0
# -*- coding: utf-8 -*-
# alternatively, you can load config values from a .env file path
# note: you can choose which file is more important, .env or from object
#       by choosing which order to load the files in
from pathlib import Path

from configureme import Config

from .config import DevConfig

# create your config object to be used in your application
config = Config()

# load your configuration from a default object
config.from_object(DevConfig)


path = Path("examples/basic") / ".env"
config.from_dotenv(str(path))

# you can also watch environment variables
# note: environment variables will always take precedence
#       over any other value
config.from_envar("TESTING")