def unicode_replaced_with_env_value(self): # Python 3 doesn't allow you to put 'bytes' objects into # os.environ, so the test makes no sense there. if six.PY3: return os.environ["RAFT_FOO"] = "myunicode" c = Config(defaults={"foo": u"myoldvalue"}) c.load_shell_env() assert c.foo == "myunicode" assert isinstance(c.foo, str)
def arbitrary_types_work_too(self): os.environ["RAFT_FOO"] = "whatever" class Meh(object): def __init__(self, thing=None): pass old_obj = Meh() c = Config(defaults={"foo": old_obj}) c.load_shell_env() assert isinstance(c.foo, Meh) assert c.foo is not old_obj
def booleans(self): for input_, result in ( ("0", False), ("1", True), ("", False), ("meh", True), ("false", True), ): os.environ["RAFT_FOO"] = input_ c = Config(defaults={"foo": bool()}) c.load_shell_env() assert c.foo == result
def numeric_types_become_casted(self): tests = [ (int, "5", 5), (float, "5.5", 5.5), # TODO: more? ] # Can't use '5L' in Python 3, even having it in a branch makes # it upset. if not six.PY3: tests.append((long, "5", long(5))) # noqa for old, new_, result in tests: os.environ["RAFT_FOO"] = new_ c = Config(defaults={"foo": old()}) c.load_shell_env() assert c.foo == result
def _uncastable_type(self, default): os.environ["RAFT_FOO"] = "stuff" c = Config(defaults={"foo": default}) c.load_shell_env()
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 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 env_vars_override_collection(self): os.environ["RAFT_OUTER_INNER_HOORAY"] = "env" c = Config() c.load_collection({"outer": {"inner": {"hooray": "defaults"}}}) c.load_shell_env() assert c.outer.inner.hooray == "env"
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 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 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 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 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 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 env_vars_override_project(self): os.environ["RAFT_OUTER_INNER_HOORAY"] = "env" c = Config(project_location=join(CONFIGS_PATH, "yaml")) c.load_project() c.load_shell_env() assert c.outer.inner.hooray == "env"
def env_vars_override_systemwide(self): os.environ["RAFT_OUTER_INNER_HOORAY"] = "env" c = Config(system_prefix=join(CONFIGS_PATH, "yaml/")) c.load_shell_env() assert c.outer.inner.hooray == "env"
def None_replaced(self): os.environ["RAFT_FOO"] = "something" c = Config(defaults={"foo": None}) c.load_shell_env() assert c.foo == "something"
def runtime_overrides_env_vars(self): os.environ["RAFT_OUTER_INNER_HOORAY"] = "env" c = Config(runtime_path=join(CONFIGS_PATH, "json", "raft.json")) c.load_runtime() c.load_shell_env() assert c.outer.inner.hooray == "json"
def preserves_env_data(self): os.environ["RAFT_FOO"] = "bar" c = Config(defaults={"foo": "notbar"}) c.load_shell_env() c2 = c.clone() assert c2.foo == "bar"