Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
            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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
 def _uncastable_type(self, default):
     os.environ["RAFT_FOO"] = "stuff"
     c = Config(defaults={"foo": default})
     c.load_shell_env()
Ejemplo n.º 6
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_
Ejemplo n.º 7
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"
Ejemplo n.º 8
0
 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"
Ejemplo n.º 9
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)
Ejemplo n.º 10
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()
Ejemplo n.º 11
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"
Ejemplo n.º 12
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"
Ejemplo n.º 13
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"
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 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"
Ejemplo n.º 16
0
 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"
Ejemplo n.º 17
0
 def None_replaced(self):
     os.environ["RAFT_FOO"] = "something"
     c = Config(defaults={"foo": None})
     c.load_shell_env()
     assert c.foo == "something"
Ejemplo n.º 18
0
 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"
Ejemplo n.º 19
0
 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"