def defaults_can_be_given_via_method(self): c = Config() assert "foo" not in c c.load_defaults({"foo": "bar"}) assert c.foo == "bar"
def None_replaced(self): os.environ["RAFT_FOO"] = "something" c = Config(defaults={"foo": None}) c.load_shell_env() assert c.foo == "something"
def _uncastable_type(self, default): os.environ["RAFT_FOO"] = "stuff" c = Config(defaults={"foo": default}) c.load_shell_env()
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"
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()
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"
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"
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"
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"
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"
def defaults_to_invoke(self): assert Config().prefix == "raft"
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
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"
def _load(kwarg, type_, **kwargs): path = join(CONFIGS_PATH, type_ + "/") kwargs[kwarg] = path return Config(**kwargs)
def allows_comparison_with_real_dicts(self): c = Config({"foo": {"bar": "biz"}}) assert c["foo"] == {"bar": "biz"}
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"]
def is_explicitly_not_hashable(self): hash(Config())
def string_display(self): "__str__ and friends" config = Config(defaults={"foo": "bar"}) assert repr(config) == "<Config: {'foo': 'bar'}>"
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
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"
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"
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"
def defaults_to_None(self): assert Config().env_prefix is None
def unknown_suffix_in_runtime_path_raises_useful_error(self): c = Config(runtime_path=join(CONFIGS_PATH, "screw.ini")) c.load_runtime()
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)
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.")
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_
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()
def collection_overrides_defaults(self): c = Config(defaults={"nested": {"setting": "default"}}) c.load_collection({"nested": {"setting": "collection"}}) assert c.nested.setting == "collection"
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"}