mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 18:43:58 +03:00
Add unit tests
This commit is contained in:
parent
93058536e4
commit
7e20b7e88d
|
@ -106,7 +106,9 @@ def environment_variables():
|
|||
os.environ["CONFIG_TEST_ENV"] = "test-value"
|
||||
os.environ["CONFIG_TEST_PATH"] = "test-path"
|
||||
os.environ["DEFINED"] = "defined"
|
||||
os.environ["CONFIG_INT"] = "42"
|
||||
yield
|
||||
os.environ.pop("CONFIG_TEST_ENV", None)
|
||||
os.environ.pop("CONFIG_TEST_PATH", None)
|
||||
os.environ.pop("DEFINED", None)
|
||||
os.environ.pop("CONFIG_INT", None)
|
||||
|
|
|
@ -31,6 +31,42 @@ def test_option_default_none(config):
|
|||
assert config.option() is None
|
||||
|
||||
|
||||
def test_as_(config):
|
||||
config.from_env("CONFIG_INT", as_=int)
|
||||
assert config() == 42
|
||||
assert isinstance(config(), int)
|
||||
|
||||
|
||||
def test_as__default(config):
|
||||
config.from_env("UNDEFINED", as_=int, default="33")
|
||||
assert config() == 33
|
||||
assert isinstance(config(), int)
|
||||
|
||||
|
||||
def test_as__undefined_required(config):
|
||||
with raises(ValueError):
|
||||
config.from_env("UNDEFINED", as_=int, required=True)
|
||||
assert config() == {}
|
||||
|
||||
|
||||
def test_option_as_(config):
|
||||
config.option.from_env("CONFIG_INT", as_=int)
|
||||
assert config.option() == 42
|
||||
assert isinstance(config.option(), int)
|
||||
|
||||
|
||||
def test_option_as__default(config):
|
||||
config.option.from_env("UNDEFINED", as_=int, default="33")
|
||||
assert config.option() == 33
|
||||
assert isinstance(config.option(), int)
|
||||
|
||||
|
||||
def test_option_as__undefined_required(config):
|
||||
with raises(ValueError):
|
||||
config.option.from_env("UNDEFINED", as_=int, required=True)
|
||||
assert config.option() is None
|
||||
|
||||
|
||||
@mark.parametrize("config_type", ["strict"])
|
||||
def test_undefined_in_strict_mode(config):
|
||||
with raises(ValueError):
|
||||
|
|
Loading…
Reference in New Issue
Block a user