Example #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"]
Example #2
0
 def test_user_can_use_number_types_with_dotenv(self, env_path):
     config = Config()
     config.from_dotenv(env_path)
     assert isinstance(config["MAX_LINES"], int)
     assert config["MAX_LINES"] == 10
     assert isinstance(config["TEMPERATURE"], float)
     assert config["TEMPERATURE"] == 98.2
Example #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]
Example #4
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"
Example #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"]
Example #6
0
def test_dunder_ne():
    config_one = Config()
    config_one["DEBUG"] = True

    config_two = Config()
    config_two["DEBUG"] = False

    assert config_one != config_two
Example #7
0
def test_dunder_eq():
    config_one = Config()
    config_one["DEBUG"] = True

    config_two = Config()
    config_two["DEBUG"] = True

    assert config_one == config_two
Example #8
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
Example #9
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
Example #10
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"
Example #11
0
 def test_from_obj_and_then_dotenv(self, env_path):
     config = Config()
     config.from_dotenv(env_path)
     config.from_object(DevConfig)
     assert "DEBUG" in config
     assert "TESTING" in config
     assert config["DEBUG"] is True
     assert config["TESTING"] is False
Example #12
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"
Example #13
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"
Example #14
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")
Example #15
0
def test_user_can_change_value_manually_but_env_value_takes_precedence():
    config = Config()
    config["FOO"] = "BAZ"
    assert config["FOO"] == "BAR"
Example #16
0
 def test_user_can_change_value_manually(self):
     config = Config()
     config["BAZ"] = "FOO"
     assert config["BAZ"] == "FOO"
Example #17
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"
Example #18
0
 def test_from_object(self):
     config = Config()
     config.from_object(DevConfig)
     assert "DEBUG" in config
     assert config["DEBUG"] is True
Example #19
0
 def test_dunder_str(self):
     expected = "{'DEBUG': True}"
     config = Config()
     config["DEBUG"] = True
     assert str(config) == expected
Example #20
0
 def test_from_dotenv(self, env_path):
     config = Config()
     config.from_dotenv(env_path)
     assert "DEBUG" in config
     assert config["DEBUG"] is True