Exemple #1
0
    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
Exemple #2
0
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"}})
Exemple #3
0
 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
Exemple #4
0
    def test_nested_refresh(self):
        config = Config.from_yaml("foo.yml")
        config.foo.refresh()

        assert config == Config({"foo": {"bar": 4}})
Exemple #5
0
 def test_null_default_value(self):
     input_ = {"foo": "<% ENV[foo, null] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is None
Exemple #6
0
 def test_attribute_passthrough(self):
     config = Config({"bar": 4})
     assert list(config.items()) == [("bar", 4)]
Exemple #7
0
def test_empty_config():
    Config()
Exemple #8
0
 def test_static_lookup_missing(self):
     config = Config({})
     with pytest.raises(AttributeError):
         config.bar
Exemple #9
0
    def test_iterable(self):
        config = Config({"foo": "bar", "bar": {"nested": 4}})

        items = list(config)
        assert sorted(items) == [("bar", Config({"nested": 4})),
                                 ("foo", "bar")]
Exemple #10
0
def test_json():
    config = Config.from_json("foo.json")
    assert config.foo.bar == 4
    assert config.foo.baz == "a4sdf"
Exemple #11
0
 def test_file_loader_file_exists(self, _):
     input_ = {"file": "<% FILE[foo.txt, 1] %>"}
     config = Config(post_process(yaml, input_))
     assert config.file == "woah!"
Exemple #12
0
 def test_list(self):
     input_ = {"foo": ["<% ENV[foo, 1] %>", "<% ENV[bar, 1] %>"]}
     config = Config(post_process(yaml, input_))
     assert config.foo == [2, 3]
Exemple #13
0
 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
Exemple #14
0
 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"}
Exemple #15
0
 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"}
Exemple #16
0
 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
Exemple #17
0
 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"
Exemple #18
0
def test_yaml():
    config = Config.from_yaml("foo.yml")
    assert config.foo.bar == 4
Exemple #19
0
def test_toml():
    config = Config.from_toml("foo.toml")
    assert config.foo.bar == 4
    assert config.foo.baz == "a4sdf"
Exemple #20
0
 def test_file_loader_file_doesnt_exist(self):
     input_ = {"file": "<% FILE[bar.txt, 1] %>"}
     config = Config(post_process(yaml, input_))
     assert config.file == "1"
Exemple #21
0
 def test_to_dict(self):
     result = Config({"foo": "bar"}).to_dict()
     assert result == {"foo": "bar"}
Exemple #22
0
 def test_null(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is None
Exemple #23
0
 def test_static_lookup(self):
     config = Config({"foo": "bar", "bar": {"nested": 4}})
     assert config.bar.nested == 4
Exemple #24
0
 def test_boolean(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is True
Exemple #25
0
 def test_dyanmic_lookup(self):
     config = Config({"foo": "bar", "bar": {"nested": 4}})
     assert config["bar"]["nested"] == 4
Exemple #26
0
 def test_float(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == 65.8
Exemple #27
0
 def test_dynamic_lookup_missing(self):
     config = Config({})
     with pytest.raises(KeyError):
         config["bar"]
Exemple #28
0
 def test_string_with_special_char_prefix(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == ">abcdef1234"
Exemple #29
0
 def test_string(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == "abcdef1234"
Exemple #30
0
 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"