def test_update_config(open_mock): # need to create it empty because in python2 it is read-only if defined # # https://docs.python.org/2/library/stringio.html#cStringIO.StringIO const_dict = StringIO() const_dict.write('{"foo": "bar"}') open_mock.return_value.__enter__.return_value = const_dict json_data = {'new': 'vals'} update_config(json_data) assert json.loads(const_dict.getvalue()) == {'new': 'vals'}
def _set_config(self, param_keys, value): """ Sets the config parameter to the specified value. If the config parameter does not already exist in the MLT config, then it's added. Writes the new config back to the mlt config file. """ # Find or add the specified config matched_config = self._find_config(param_keys, add_if_not_found=True) # Set the config value then write it back to the config file. matched_config[param_keys[-1]] = value config_helpers.update_config(self.config)
def _remove_config(self, param_keys): """ Finds, then removes the specified config parameter from the MLT config file. If the config parameter does not exist in the MLT config file, then an error is displayed. """ key_not_found = "Unable to find config '{}'. To see " \ "list of configs, use `mlt template_config list`.". \ format(self.args.get('<name>')) # Find the specified config, and display an error if it does not exist. matched_config = self._find_config(param_keys, add_if_not_found=False, key_not_found_error=key_not_found) # Delete the config parameter and then write it back to the config file if param_keys[-1] in matched_config: del matched_config[param_keys[-1]] else: error_handling.throw_error(key_not_found) config_helpers.update_config(self.config)