示例#1
0
 def defaults_can_be_given_via_method(self):
     c = Config()
     assert "foo" not in c
     c.load_defaults({"foo": "bar"})
     assert c.foo == "bar"
示例#2
0
 def None_replaced(self):
     os.environ["RAFT_FOO"] = "something"
     c = Config(defaults={"foo": None})
     c.load_shell_env()
     assert c.foo == "something"
示例#3
0
 def _uncastable_type(self, default):
     os.environ["RAFT_FOO"] = "stuff"
     c = Config(defaults={"foo": default})
     c.load_shell_env()
示例#4
0
 def both_types_of_underscores_mixed(self):
     os.environ["RAFT_FOO_BAR_BIZ"] = "baz"
     c = Config(defaults={"foo_bar": {"biz": "notbaz"}})
     c.load_shell_env()
     assert c.foo_bar.biz == "baz"
示例#5
0
 def ambiguous_underscores_dont_guess(self):
     os.environ["RAFT_FOO_BAR"] = "biz"
     c = Config(defaults={"foo_bar": "wat", "foo": {"bar": "huh"}})
     c.load_shell_env()
示例#6
0
 def base_case_defaults_to_RAFT_prefix(self):
     os.environ["RAFT_FOO"] = "bar"
     c = Config(defaults={"foo": "notbar"})
     c.load_shell_env()
     assert c.foo == "bar"
示例#7
0
 def underscores_top_level(self):
     os.environ["RAFT_FOO_BAR"] = "biz"
     c = Config(defaults={"foo_bar": "notbiz"})
     c.load_shell_env()
     assert c.foo_bar == "biz"
示例#8
0
 def supports_mutation_via_attribute_access(self):
     c = Config({"foo": "bar"})
     assert c.foo == "bar"
     c.foo = "notbar"
     assert c.foo == "notbar"
     assert c["foo"] == "notbar"
示例#9
0
 def supports_nested_mutation_via_attribute_access(self):
     c = Config({"foo": {"bar": "biz"}})
     assert c.foo.bar == "biz"
     c.foo.bar = "notbiz"
     assert c.foo.bar == "notbiz"
     assert c["foo"]["bar"] == "notbiz"
示例#10
0
 def overrides_can_skip_merging(self):
     c = Config()
     c.load_overrides({"foo": "bar"}, merge=False)
     assert "foo" not in c
     c.merge()
     assert c.foo == "bar"
示例#11
0
 def defaults_to_invoke(self):
     assert Config().prefix == "raft"
示例#12
0
 def overrides_can_be_given_via_method(self):
     c = Config(defaults={"foo": "bar"})
     assert c.foo == "bar"  # defaults level
     c.load_overrides({"foo": "notbar"})
     assert c.foo == "notbar"  # overrides level
示例#13
0
 def defaults_can_skip_merging(self):
     c = Config()
     c.load_defaults({"foo": "bar"}, merge=False)
     assert "foo" not in c
     c.merge()
     assert c.foo == "bar"
示例#14
0
def _load(kwarg, type_, **kwargs):
    path = join(CONFIGS_PATH, type_ + "/")
    kwargs[kwarg] = path
    return Config(**kwargs)
示例#15
0
 def allows_comparison_with_real_dicts(self):
     c = Config({"foo": {"bar": "biz"}})
     assert c["foo"] == {"bar": "biz"}
示例#16
0
 def nonexistent_attr_setting_works_nested_too(self):
     c = Config()
     c.a_nest = {}
     assert c["a_nest"] == {}
     c.a_nest.an_egg = True
     assert c["a_nest"]["an_egg"]
示例#17
0
 def is_explicitly_not_hashable(self):
     hash(Config())
示例#18
0
 def string_display(self):
     "__str__ and friends"
     config = Config(defaults={"foo": "bar"})
     assert repr(config) == "<Config: {'foo': 'bar'}>"
示例#19
0
 def non_predeclared_settings_do_not_get_consumed(self):
     os.environ["RAFT_HELLO"] = "is it me you're looking for?"
     c = Config()
     c.load_shell_env()
     assert "HELLO" not in c
     assert "hello" not in c
示例#20
0
 def project_location_can_be_set_after_init(self):
     c = Config()
     assert "outer" not in c
     c.set_project_location(join(CONFIGS_PATH, "yml"))
     c.load_project()
     assert c.outer.inner.hooray == "yml"
示例#21
0
 def underscores_nested(self):
     os.environ["RAFT_FOO_BAR"] = "biz"
     c = Config(defaults={"foo": {"bar": "notbiz"}})
     c.load_shell_env()
     assert c.foo.bar == "biz"
示例#22
0
 def runtime_conf_via_cli_flag(self):
     c = Config(runtime_path=join(CONFIGS_PATH, "yaml", "raft.yaml"))
     c.load_runtime()
     assert c.outer.inner.hooray == "yaml"
示例#23
0
 def defaults_to_None(self):
     assert Config().env_prefix is None
示例#24
0
 def unknown_suffix_in_runtime_path_raises_useful_error(self):
     c = Config(runtime_path=join(CONFIGS_PATH, "screw.ini"))
     c.load_runtime()
示例#25
0
 def strings_replaced_with_env_value(self):
     os.environ["RAFT_FOO"] = u"myvalue"
     c = Config(defaults={"foo": "myoldvalue"})
     c.load_shell_env()
     assert c.foo == u"myvalue"
     assert isinstance(c.foo, six.text_type)
示例#26
0
 def nonexistent_files_are_skipped_and_logged(self, mock_debug):
     c = Config()
     c._load_yml = Mock(side_effect=IOError(2, "aw nuts"))
     c.set_runtime_path("is-a.yml")  # Triggers use of _load_yml
     c.load_runtime()
     mock_debug.assert_any_call("Didn't see any is-a.yml, skipping.")
示例#27
0
 def boolean_type_inputs_with_non_boolean_defaults(self):
     for input_ in ("0", "1", "", "meh", "false"):
         os.environ["RAFT_FOO"] = input_
         c = Config(defaults={"foo": "bar"})
         c.load_shell_env()
         assert c.foo == input_
示例#28
0
 def non_missing_file_IOErrors_are_raised(self):
     c = Config()
     c._load_yml = Mock(side_effect=IOError(17, "uh, what?"))
     c.set_runtime_path("is-a.yml")  # Triggers use of _load_yml
     c.load_runtime()
示例#29
0
 def collection_overrides_defaults(self):
     c = Config(defaults={"nested": {"setting": "default"}})
     c.load_collection({"nested": {"setting": "collection"}})
     assert c.nested.setting == "collection"
示例#30
0
 def is_iterable_like_dict(self):
     c = Config(defaults={"a": 1, "b": 2})
     assert set(c.keys()) == {"a", "b"}
     assert set(list(c)) == {"a", "b"}