Esempio n. 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
Esempio n. 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"}})
Esempio n. 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
Esempio n. 4
0
    def test_nested_refresh(self):
        config = Config.from_yaml("foo.yml")
        config.foo.refresh()

        assert config == Config({"foo": {"bar": 4}})
Esempio n. 5
0
 def test_null_default_value(self):
     input_ = {"foo": "<% ENV[foo, null] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is None
Esempio n. 6
0
 def test_attribute_passthrough(self):
     config = Config({"bar": 4})
     assert list(config.items()) == [("bar", 4)]
Esempio n. 7
0
def test_empty_config():
    Config()
Esempio n. 8
0
 def test_static_lookup_missing(self):
     config = Config({})
     with pytest.raises(AttributeError):
         config.bar
Esempio n. 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")]
Esempio n. 10
0
def test_json():
    config = Config.from_json("foo.json")
    assert config.foo.bar == 4
    assert config.foo.baz == "a4sdf"
Esempio n. 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!"
Esempio n. 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]
Esempio n. 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
Esempio n. 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"}
Esempio n. 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"}
Esempio n. 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
Esempio n. 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"
Esempio n. 18
0
def test_yaml():
    config = Config.from_yaml("foo.yml")
    assert config.foo.bar == 4
Esempio n. 19
0
def test_toml():
    config = Config.from_toml("foo.toml")
    assert config.foo.bar == 4
    assert config.foo.baz == "a4sdf"
Esempio n. 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"
Esempio n. 21
0
 def test_to_dict(self):
     result = Config({"foo": "bar"}).to_dict()
     assert result == {"foo": "bar"}
Esempio n. 22
0
 def test_null(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is None
Esempio n. 23
0
 def test_static_lookup(self):
     config = Config({"foo": "bar", "bar": {"nested": 4}})
     assert config.bar.nested == 4
Esempio n. 24
0
 def test_boolean(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo is True
Esempio n. 25
0
 def test_dyanmic_lookup(self):
     config = Config({"foo": "bar", "bar": {"nested": 4}})
     assert config["bar"]["nested"] == 4
Esempio n. 26
0
 def test_float(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == 65.8
Esempio n. 27
0
 def test_dynamic_lookup_missing(self):
     config = Config({})
     with pytest.raises(KeyError):
         config["bar"]
Esempio n. 28
0
 def test_string_with_special_char_prefix(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == ">abcdef1234"
Esempio n. 29
0
 def test_string(self):
     input_ = {"foo": "<% ENV[foo] %>"}
     config = Config(post_process(yaml, input_))
     assert config.foo == "abcdef1234"
Esempio n. 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"