예제 #1
0
def test_ok():
    with patch("os.environ", {"foo": "quux", "bar": "10", "baz": "True"}):
        assert load_env(fields(Config)) == {
            "foo": "quux",
            "bar": 10,
            "baz": True
        }
예제 #2
0
 def test_parses_string(self):
     with patch("os.environ", {"foo": "bar"}):
         assert load_env(fields(Config)) == {"foo": "bar"}
예제 #3
0
 def test_with_no_value(self):
     with patch("os.environ", {"foo": ""}):
         assert load_env(fields(Config)) == {"foo": ""}
예제 #4
0
 def test_parses_bool_falsy_value(self, val):
     with patch("os.environ", {"baz": val}):
         assert load_env(fields(Config)) == {"baz": False}
예제 #5
0
 def test_raises_on_invalid_value(self):
     with raises(ConfigError):
         with patch("os.environ", {"baz": "quux"}):
             load_env(fields(Config))
예제 #6
0
 def test_prefix_multiple_underscore(self):
     env = {"prefix__foo": "quux"}
     with patch("os.environ", env):
         actual = load_env(fields(Config), env_prefix="prefix__")
         assert actual == {"foo": "quux"}
예제 #7
0
 def test_with_prefix(self, prefix):
     env = {"prefix_foo": "quux", "PREFIX_BAR": "10"}
     with patch("os.environ", env):
         actual = load_env(fields(Config), env_prefix=prefix)
         assert actual == {"foo": "quux", "bar": 10}
예제 #8
0
 def test_parses_negative_numbers(self, val):
     with patch("os.environ", {"bar": val}):
         assert load_env(fields(Config)) == {"bar": -10}
예제 #9
0
 def test_tries_read_uppercase(self):
     with patch("os.environ", {"FOO": "blep"}):
         assert load_env(fields(Config)) == {"foo": "blep"}
예제 #10
0
 def test_prefers_same_case(self):
     with patch("os.environ", {"foo": "quux", "FOO": "blep"}):
         assert load_env(fields(Config)) == {"foo": "quux"}
예제 #11
0
def test_ignores_unknown_env():
    assert load_env(fields(Config)) == {}
예제 #12
0
def test_empty_env():
    with patch("os.environ", {}):
        assert load_env(fields(Config)) == {}
예제 #13
0
 def test_fails_on_invalid_value(self):
     with raises(ConfigError):
         with patch("os.environ", {"bar": "no"}):
             load_env(fields(Config))
예제 #14
0
 def test_parses_strings_with_whitespace(self):
     with patch("os.environ", {"foo": "bar baz quux"}):
         assert load_env(fields(Config)) == {"foo": "bar baz quux"}
예제 #15
0
 def test_mixed_case(self):
     env = {"foo": "quux", "BAR": "10", "Baz": "False"}
     with patch("os.environ", env):
         actual = load_env(fields(Config))
         assert actual == {"foo": "quux", "bar": 10}
예제 #16
0
 def test_parses_strings_with_quotes(self):
     with patch("os.environ", {"foo": 'bar="baz"'}):
         assert load_env(fields(Config)) == {"foo": 'bar="baz"'}
예제 #17
0
 def test_parses_ok(self, val):
     with patch("os.environ", {"bar": val}):
         assert load_env(fields(Config)) == {"bar": 10}