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"
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')
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'})
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
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()
def default_user_prefix_is_homedir_plus_dot(self, load_yaml): Config() load_yaml.assert_any_call(expanduser('~/.invoke.yaml'))
def configure_runtime_path(self, load_yaml): Config(runtime_path='some/path.yaml').load_runtime() load_yaml.assert_any_call('some/path.yaml')
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"
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"
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"
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"
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"
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"
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"
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')
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"
def configure_user_location_prefix(self, load_yaml): Config(user_prefix='whatever/') load_yaml.assert_any_call('whatever/invoke.yaml')
def setup(self): config = Config({'foo': 'bar'}) self.c = Context(config=config)
def configure_project_location(self, load_yaml): Config(project_location='someproject').load_project() load_yaml.assert_any_call(join('someproject', 'invoke.yaml'))
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')
def accepts_defaults_dict_kwarg(self): c = Config(defaults={'super': 'low level'}) eq_(c.super, 'low level')
def is_not_required(self): c = Config(defaults={'meh': 'okay'}) c2 = c.clone() eq_(c2.meh, 'okay')
def overrides_dict_is_also_a_kwarg(self): c = Config(overrides={'run': {'hide': True}}) eq_(c.run.hide, True)
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)
def _load(kwarg, type_, **kwargs): path = join(CONFIGS_PATH, type_ + "/") kwargs[kwarg] = path return Config(**kwargs)
def can_be_empty(self): eq_(Config().__class__, Config) # derp
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')
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')
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 user_overrides_systemwide(self): c = Config( system_prefix=join(CONFIGS_PATH, "yaml/"), user_prefix=join(CONFIGS_PATH, "json/"), ) assert c.outer.inner.hooray == "json"