Beispiel #1
0
 def user_overrides_collection(self):
     c = Config(user_prefix=join(CONFIGS_PATH, "json/"))
     c.load_collection({"outer": {"inner": {"hooray": "defaults"}}})
     assert c.outer.inner.hooray == "json"
Beispiel #2
0
 def can_be_used_directly_after_init(self):
     # No load() here...
     c = Config({'lots of these': 'tests look similar'})
     eq_(c['lots of these'], 'tests look similar')
Beispiel #3
0
 def is_iterable_like_dict(self):
     c = Config(defaults={'a': 1, 'b': 2})
     eq_(set(c.keys()), {'a', 'b'})
     eq_(set(list(c)), {'a', 'b'})
Beispiel #4
0
 def overrides_dict_is_first_posarg(self):
     c = Config({'new': 'data', 'run': {'hide': True}})
     eq_(c.run.hide, True)  # default is False
     eq_(c.run.warn, False)  # in global defaults, untouched
     eq_(c.new, 'data')  # data only present at overrides layer
Beispiel #5
0
 def system_and_user_files_loaded_automatically(self, merge, load_u,
                                                load_s):
     Config()
     load_s.assert_called_once_with(merge=False)
     load_u.assert_called_once_with(merge=False)
     merge.assert_called_once_with()
Beispiel #6
0
 def default_user_prefix_is_homedir_plus_dot(self, load_yaml):
     Config()
     load_yaml.assert_any_call(expanduser('~/.invoke.yaml'))
Beispiel #7
0
 def configure_runtime_path(self, load_yaml):
     Config(runtime_path='some/path.yaml').load_runtime()
     load_yaml.assert_any_call('some/path.yaml')
Beispiel #8
0
 def runtime_overrides_collection(self):
     c = Config(runtime_path=join(CONFIGS_PATH, "json", "invoke.json"))
     c.load_collection({"outer": {"inner": {"hooray": "defaults"}}})
     c.load_runtime()
     assert c.outer.inner.hooray == "json"
Beispiel #9
0
 def yml_prevents_json_or_python(self):
     c = Config(system_prefix=join(CONFIGS_PATH, "three-of-em/"))
     assert "json-only" not in c
     assert "python_only" not in c
     assert "yml-only" in c
     assert c.shared == "yml-value"
Beispiel #10
0
 def env_vars_override_collection(self):
     os.environ["INVOKE_OUTER_INNER_HOORAY"] = "env"
     c = Config()
     c.load_collection({"outer": {"inner": {"hooray": "defaults"}}})
     c.load_shell_env()
     assert c.outer.inner.hooray == "env"
Beispiel #11
0
 def runtime_overrides_env_vars(self):
     os.environ["INVOKE_OUTER_INNER_HOORAY"] = "env"
     c = Config(runtime_path=join(CONFIGS_PATH, "json", "invoke.json"))
     c.load_runtime()
     c.load_shell_env()
     assert c.outer.inner.hooray == "json"
Beispiel #12
0
 def env_vars_override_systemwide(self):
     os.environ["INVOKE_OUTER_INNER_HOORAY"] = "env"
     c = Config(system_prefix=join(CONFIGS_PATH, "yaml/"))
     c.load_shell_env()
     assert c.outer.inner.hooray == "env"
Beispiel #13
0
 def env_vars_override_project(self):
     os.environ["INVOKE_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"
Beispiel #14
0
 def project_overrides_collection(self):
     c = Config(project_location=join(CONFIGS_PATH, "yaml"))
     c.load_project()
     c.load_collection({"outer": {"inner": {"hooray": "defaults"}}})
     assert c.outer.inner.hooray == "yaml"
Beispiel #15
0
 def default_system_prefix_is_etc(self, load_yaml):
     # TODO: make this work on Windows somehow without being a total
     # tautology? heh.
     Config()
     load_yaml.assert_any_call('/etc/invoke.yaml')
Beispiel #16
0
 def json_prevents_python(self):
     c = Config(system_prefix=join(CONFIGS_PATH, "json-and-python/"))
     assert "python_only" not in c
     assert "json-only" in c
     assert c.shared == "json-value"
Beispiel #17
0
 def configure_user_location_prefix(self, load_yaml):
     Config(user_prefix='whatever/')
     load_yaml.assert_any_call('whatever/invoke.yaml')
Beispiel #18
0
 def setup(self):
     config = Config({'foo': 'bar'})
     self.c = Context(config=config)
Beispiel #19
0
 def configure_project_location(self, load_yaml):
     Config(project_location='someproject').load_project()
     load_yaml.assert_any_call(join('someproject', 'invoke.yaml'))
Beispiel #20
0
 def preserves_env_data(self):
     os.environ['INVOKE_FOO'] = 'bar'
     c = Config(defaults={'foo': 'notbar'})
     c.load_shell_env()
     c2 = c.clone()
     eq_(c2.foo, 'bar')
Beispiel #21
0
 def accepts_defaults_dict_kwarg(self):
     c = Config(defaults={'super': 'low level'})
     eq_(c.super, 'low level')
Beispiel #22
0
 def is_not_required(self):
     c = Config(defaults={'meh': 'okay'})
     c2 = c.clone()
     eq_(c2.meh, 'okay')
Beispiel #23
0
 def overrides_dict_is_also_a_kwarg(self):
     c = Config(overrides={'run': {'hide': True}})
     eq_(c.run.hide, True)
Beispiel #24
0
 def can_be_pickled(self):
     c = Config(overrides={'foo': {'bar': {'biz': ['baz', 'buzz']}}})
     c2 = pickle.loads(pickle.dumps(c))
     eq_(c, c2)
     ok_(c is not c2)
     ok_(c.foo.bar.biz is not c2.foo.bar.biz)
Beispiel #25
0
def _load(kwarg, type_, **kwargs):
    path = join(CONFIGS_PATH, type_ + "/")
    kwargs[kwarg] = path
    return Config(**kwargs)
Beispiel #26
0
 def can_be_empty(self):
     eq_(Config().__class__, Config)  # derp
Beispiel #27
0
 def allows_dict_and_attr_access(self):
     # TODO: combine with tests for Context probably
     c = Config({'foo': 'bar'})
     eq_(c.foo, 'bar')
     eq_(c['foo'], 'bar')
Beispiel #28
0
 def configure_global_location_prefix(self, load_yaml):
     # This is a bit funky but more useful than just replicating the
     # same test farther down?
     Config(system_prefix='meh/')
     load_yaml.assert_any_call('meh/invoke.yaml')
Beispiel #29
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'
Beispiel #30
0
 def user_overrides_systemwide(self):
     c = Config(
         system_prefix=join(CONFIGS_PATH, "yaml/"),
         user_prefix=join(CONFIGS_PATH, "json/"),
     )
     assert c.outer.inner.hooray == "json"