def _combine(self, env=os.environ, keep_string=None): """ Perform a prioritized recursive merge of config files. Returns a new dict. Prior to merging the config files are interpolated with environment variables. 1. Loads Molecule defaults. 2. Loads a base config (if provided) and merges ontop of defaults. 3. Loads the scenario's ``molecule file`` and merges ontop of previous merge. :return: dict """ defaults = self._get_defaults() base_config = self.args.get("base_config") if base_config and os.path.exists(base_config): with util.open_file(base_config) as stream: s = stream.read() self._preflight(s) interpolated_config = self._interpolate(s, env, keep_string) defaults = util.merge_dicts( defaults, util.safe_load(interpolated_config)) if self.molecule_file: with util.open_file(self.molecule_file) as stream: s = stream.read() self._preflight(s) interpolated_config = self._interpolate(s, env, keep_string) defaults = util.merge_dicts( defaults, util.safe_load(interpolated_config)) return defaults
def _combine(self): """ Perform a prioritized recursive merge of config files, and returns a new dict. Prior to merging the config files are interpolated with environment variables. 1. Loads Molecule defaults. 2. Loads a base config (if provided) and merges ontop of defaults. 3. Loads the scenario's `molecule file` and merges ontop of previous merge. :return: dict """ defaults = self._get_defaults() base_config = self.args.get('base_config') if base_config: if os.path.exists(base_config): with util.open_file(base_config) as stream: interpolated_config = self._interpolate(stream.read()) defaults = util.merge_dicts( defaults, util.safe_load(interpolated_config)) with util.open_file(self.molecule_file) as stream: interpolated_config = self._interpolate(stream.read()) defaults = util.merge_dicts(defaults, util.safe_load(interpolated_config)) return defaults
def _combine(self): """ Perform a prioritized recursive merge of the `molecule_file` with defaults, interpolate the result with environment variables, and returns a new dict. :return: dict """ i = interpolation.Interpolator(interpolation.TemplateWithDefaults, os.environ) base = self._get_defaults() with util.open_file(self.molecule_file) as stream: try: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, util.safe_load(interpolated_config)) except interpolation.InvalidInterpolation as e: msg = ("parsing config file '{}'.\n\n" '{}\n{}'.format(self.molecule_file, e.place, e.string)) util.sysexit_with_message(msg) schema.validate(base) return base
def test_write_file(temp_dir): dest_file = os.path.join(temp_dir.strpath, "test_util_write_file.tmp") contents = binascii.b2a_hex(os.urandom(15)).decode("utf-8") util.write_file(dest_file, contents) with util.open_file(dest_file) as stream: data = stream.read() x = "# Molecule managed\n\n{}".format(contents) assert x == data
def test_write_file(temp_dir): dest_file = os.path.join(temp_dir.strpath, 'test_util_write_file.tmp') contents = binascii.b2a_hex(os.urandom(15)).decode() util.write_file(dest_file, contents) with util.open_file(dest_file) as stream: data = stream.read() x = '# Molecule managed\n\n{}'.format(contents) assert x == data
def test_open_file(temp_dir): path = os.path.join(temp_dir.strpath, "foo") util.write_file(path, "foo: bar") with util.open_file(path) as stream: try: file_types = (file, io.IOBase) except NameError: file_types = io.IOBase assert isinstance(stream, file_types)
def test_open_file(temp_dir): path = os.path.join(temp_dir.strpath, 'foo') util.write_file(path, 'foo: bar') with util.open_file(path) as stream: try: file_types = (file, io.IOBase) except NameError: file_types = io.IOBase assert isinstance(stream, file_types)
def test_process_templates(temp_dir): template_dir = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, 'resources', 'templates') repo_name = str(uuid.uuid4()) context = {'repo_name': repo_name} init._process_templates(template_dir, context, temp_dir.strpath) expected_file = os.path.join(temp_dir.strpath, repo_name, 'template.yml') expected_contents = '---\n- value: foo' with util.open_file(expected_file) as stream: for line in stream.readlines(): assert line.strip() in expected_contents
def _combine(self): """ Perform a prioritized recursive merge of the `molecule_file` with defaults, interpolate the result with environment variables, and returns a new dict. :return: dict """ i = interpolation.Interpolator(interpolation.TemplateWithDefaults, os.environ) base = self._get_defaults() with util.open_file(self.molecule_file) as stream: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, util.safe_load(interpolated_config)) schema.validate(base) return base
returns a new dict. :return: dict """ <<<<<<< HEAD <<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py i = interpolation.Interpolator(interpolation.TemplateWithDefaults, os.environ) ======= ======= <<<<<<< HEAD:molecule/config.py >>>>>>> e91355cf081d9dcd78efe38cdcc6f0353a1aa3ac defaults = self._get_defaults() base_config = self.args.get('base_config') if base_config and os.path.exists(base_config): with util.open_file(base_config) as stream: s = stream.read() self._preflight(s) interpolated_config = self._interpolate(s, env, keep_string) defaults = util.merge_dicts( defaults, util.safe_load(interpolated_config)) <<<<<<< HEAD >>>>>>> 0fa82e7a3daa84ebd03d8af67403c6551113d3e4:molecule/config.py base = self._get_defaults() with util.open_file(self.molecule_file) as stream: <<<<<<< HEAD:Rake/molecule/__GEMS_.py/__GEMS_.py/apt-py.git/commandinit.yaml/init.yml/config.py try: interpolated_config = i.interpolate(stream.read()) base = self.merge_dicts(base, =======