def test_load_environment(self): local_root = tempfile.mkdtemp() config = Configuration("agent", "1.2.3") config.system_root = local_root self.add_cleanup_path(local_root) split = config.split_version() filename = config.name + config.file_extension paths = [ join(config.system_root, config.child_dir, split[2], filename), join(config.system_root, config.child_dir + os.sep, filename), ] for i, path in enumerate(paths): try: os.makedirs(dirname(path)) except OSError: pass data = dedent( """ env: key%s: %s key: %s """ % (i, i, i) ) with open(path, "w") as stream: stream.write(data) self.add_cleanup_path(stream.name) environment = {} config.load(environment=environment) self.assertEqual(environment, {"key0": 0, "key1": 1, "key": 1})
def test_files_filtered_with_files(self): local_root = tempfile.mkdtemp() config = Configuration("agent", "1.2.3") config.system_root = local_root self.add_cleanup_path(local_root) split = config.split_version() filename = config.name + config.file_extension paths = [ join(config.system_root, config.child_dir, split[2], filename), join(config.system_root, config.child_dir + os.sep, filename), ] for path in paths: try: os.makedirs(dirname(path)) except OSError: pass with open(path, "w") as stream: self.add_cleanup_path(stream.name) self.assertEqual(config.files(), paths)
def test_load_empty_file(self): local_root = tempfile.mkdtemp() config = Configuration("agent", "1.2.3") config.system_root = local_root self.add_cleanup_path(local_root) split = config.split_version() filename = config.name + config.file_extension paths = [ join(config.system_root, config.child_dir + os.sep, filename), join(config.system_root, config.child_dir, split[2], filename), ] for i, path in enumerate(paths): try: os.makedirs(dirname(path)) except OSError: pass with open(path, "w") as stream: stream.write("") self.add_cleanup_path(stream.name) config.load()