def test_equality(self): config = Config({"bar": 4}) config2 = Config({"bar": 4}) raw_data = {"bar": 4} config3 = Config({"bar": 5}) assert config == config2 assert config == raw_data assert config != config3
def test_nested_refresh(): m1 = mock_key_value("bar", 4) m2 = mock_key_value("baz", "foo") config = Config.from_yaml("foo.yml") assert config == Config({"foo": {"bar": 4, "baz": "foo"}}) m1(13) m2("wat") config.foo.refresh() assert config == Config({"foo": {"bar": 13, "baz": "wat"}})
def test_integer_value_with_pre_or_post(self): input_ = { "foo": {"bar": "1<% ENV[foo] %>", "baz": "<% ENV[foo] %>2", "qux": "1<% ENV[foo] %>2"} } config = Config(post_process(yaml, input_)) assert config.foo.bar == 15 assert config.foo.baz == 52 assert config.foo.qux == 152
def test_nested_refresh(self): config = Config.from_yaml("foo.yml") config.foo.refresh() assert config == Config({"foo": {"bar": 4}})
def test_null_default_value(self): input_ = {"foo": "<% ENV[foo, null] %>"} config = Config(post_process(yaml, input_)) assert config.foo is None
def test_attribute_passthrough(self): config = Config({"bar": 4}) assert list(config.items()) == [("bar", 4)]
def test_empty_config(): Config()
def test_static_lookup_missing(self): config = Config({}) with pytest.raises(AttributeError): config.bar
def test_iterable(self): config = Config({"foo": "bar", "bar": {"nested": 4}}) items = list(config) assert sorted(items) == [("bar", Config({"nested": 4})), ("foo", "bar")]
def test_json(): config = Config.from_json("foo.json") assert config.foo.bar == 4 assert config.foo.baz == "a4sdf"
def test_file_loader_file_exists(self, _): input_ = {"file": "<% FILE[foo.txt, 1] %>"} config = Config(post_process(yaml, input_)) assert config.file == "woah!"
def test_list(self): input_ = {"foo": ["<% ENV[foo, 1] %>", "<% ENV[bar, 1] %>"]} config = Config(post_process(yaml, input_)) assert config.foo == [2, 3]
def test_env_var_exists_with_default(self): input_ = {"foo": {"bar": "<% ENV[bar, 1] %>"}} config = Config(post_process(yaml, input_)) assert config.foo.bar == 3
def test_multiple_matches(self): input_ = {"foo": "<% ENV[foo] %>+<% ENV[bar] %>=<% ENV[baz] %>"} config = Config(post_process(yaml, input_)) assert config.to_dict() == {"foo": "one+two=three"}
def test_object_values(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert type(config.foo) == Config assert config.foo.to_dict() == {"hello": "world"}
def test_env_var_exists_no_default(self): input_ = {"foo": {"bar": "<% ENV[bar] %>"}, "bax": "foo", "baz": 5} config = Config(post_process(yaml, input_)) assert config.foo.bar == 1 assert config.bax == "foo" assert config.baz == 5
def test_null_default_value_with_pre_and_post(self): input_ = {"foo": "1<% ENV[foo, null] %>2"} config = Config(post_process(yaml, input_)) assert config.foo == "1null2"
def test_yaml(): config = Config.from_yaml("foo.yml") assert config.foo.bar == 4
def test_toml(): config = Config.from_toml("foo.toml") assert config.foo.bar == 4 assert config.foo.baz == "a4sdf"
def test_file_loader_file_doesnt_exist(self): input_ = {"file": "<% FILE[bar.txt, 1] %>"} config = Config(post_process(yaml, input_)) assert config.file == "1"
def test_to_dict(self): result = Config({"foo": "bar"}).to_dict() assert result == {"foo": "bar"}
def test_null(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert config.foo is None
def test_static_lookup(self): config = Config({"foo": "bar", "bar": {"nested": 4}}) assert config.bar.nested == 4
def test_boolean(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert config.foo is True
def test_dyanmic_lookup(self): config = Config({"foo": "bar", "bar": {"nested": 4}}) assert config["bar"]["nested"] == 4
def test_float(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert config.foo == 65.8
def test_dynamic_lookup_missing(self): config = Config({}) with pytest.raises(KeyError): config["bar"]
def test_string_with_special_char_prefix(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert config.foo == ">abcdef1234"
def test_string(self): input_ = {"foo": "<% ENV[foo] %>"} config = Config(post_process(yaml, input_)) assert config.foo == "abcdef1234"
def test_string_value_with_pre_or_post(self): input_ = {"foo": "1<% ENV[foo] %>2"} config = Config(post_process(yaml, input_)) assert config.foo == "1>234!2"