def execute(self): if isinstance(self.input, list): for i in self.input: self.src = merge_configs(self.src, i) return self.src else: return merge_configs(self.src, self.input)
def _execute(self): if isinstance(self.input, list): for i in self.input: self.dict = merge_configs(self.dict, i) return self.dict else: return merge_configs(self.dict, self.input)
def _modify_dicts(self): if self.remove: if isinstance(self.remove, str): self._remove_from_contents(self.remove) if isinstance(self.remove, list): for i in self.remove: self._remove_from_contents(i) if self.filter: if isinstance(self.contents, dict): self.contents = { k: v for (k, v) in self.contents.items() if k in self.filter } if self.update: self.contents.update(self.update) if self.merge_dict: self.contents = merge_configs(self.contents, self.merge_dict) if self.append_items: if isinstance(self.append_items, str) or isinstance( self.append_items, dict): self._append_each_item(self.append_items) elif isinstance(self.append_items, list): for i in self.append_items: self._append_each_item(i)
def _execute(self): if 'remove' in self.operator_dict: if isinstance(self.operator_dict['remove'], str): self._remove_from_contents(self.operator_dict['remove']) if isinstance(self.operator_dict['remove'], list): for i in self.operator_dict['remove']: self._remove_from_contents(i) elif isinstance(self.operator_dict['remove'], dict): warnings.warn( "Warning: the `remove` parameter can't be a dict - ignored" ) if 'update' in self.operator_dict: if isinstance(self.operator_dict['update'], dict): self.operator_dict['input'].update( self.operator_dict['update']) else: raise ValueError("`update` param must be dictionary.") if 'merge_dict' in self.operator_dict: if isinstance(self.operator_dict['merge_dict'], dict): self.operator_dict['input'] = merge_configs( self.operator_dict['input'], self.operator_dict['merge_dict']) else: raise ValueError("`merge_dict` param must be dictionary.") return self.operator_dict['input']
def execute(self): if self.remove: if isinstance(self.remove, str): self._remove_from_contents(self.remove) if isinstance(self.remove, list): for i in self.remove: self._remove_from_contents(i) if self.update: self.input.update(self.update) if self.merge_dict: self.input = merge_configs(self.input, self.merge_dict) return self.input
def test_merge_configs(): """Verify default and user config merged in expected way.""" default = { 'cookiecutters_dir': '/home/example/some-path-to-templates', 'replay_dir': '/home/example/some-path-to-replay-files', 'default_context': {}, 'abbreviations': { 'gh': 'https://github.com/{0}.git', 'gl': 'https://gitlab.com/{0}.git', 'bb': 'https://bitbucket.org/{0}', }, } user_config = { 'default_context': { 'full_name': 'Raphael Pierzina', 'github_username': '******', }, 'abbreviations': { 'gl': 'https://gitlab.com/hackebrot/{0}.git', 'pytest-plugin': 'https://github.com/pytest-dev/pytest-plugin.git', }, } expected_config = { 'cookiecutters_dir': '/home/example/some-path-to-templates', 'replay_dir': '/home/example/some-path-to-replay-files', 'default_context': { 'full_name': 'Raphael Pierzina', 'github_username': '******', }, 'abbreviations': { 'gh': 'https://github.com/{0}.git', 'gl': 'https://gitlab.com/hackebrot/{0}.git', 'bb': 'https://bitbucket.org/{0}', 'pytest-plugin': 'https://github.com/pytest-dev/pytest-plugin.git', }, } assert config.merge_configs(default, user_config) == expected_config
def _modify_dicts(self): if self.remove: if isinstance(self.remove, str): self._remove_from_contents(self.remove) if isinstance(self.remove, list): for i in self.remove: self._remove_from_contents(i) elif isinstance(self.remove, dict): warnings.warn( "Warning: the `remove` parameter can't be a dict - ignored" ) if self.filter: self.contents = { k: v for (k, v) in self.contents.items() if k in self.filter } if self.update: if isinstance(self.update, dict): self.contents.update(self.update) else: raise ValueError("`update` param must be dictionary.") if self.merge_dict: if isinstance(self.merge_dict, dict): self.contents = merge_configs(self.contents, self.merge_dict) else: raise ValueError("`merge_dict` param must be dictionary.") if self.append_items: if isinstance(self.append_items, str) or isinstance( self.append_items, dict ): self._append_each_item(self.append_items) elif isinstance(self.append_items, list): for i in self.append_items: self._append_each_item(i)
def test_merge_configs(): default = { 'cookiecutters_dir': '/home/example/some-path-to-templates', 'replay_dir': '/home/example/some-path-to-replay-files', 'default_context': {}, 'abbreviations': { 'gh': 'https://github.com/{0}.git', 'gl': 'https://gitlab.com/{0}.git', 'bb': 'https://bitbucket.org/{0}', } } user_config = { 'default_context': { 'full_name': 'Raphael Pierzina', 'github_username': '******', }, 'abbreviations': { 'gl': 'https://gitlab.com/hackebrot/{0}.git', 'pytest-plugin': 'https://github.com/pytest-dev/pytest-plugin.git', } } expected_config = { 'cookiecutters_dir': '/home/example/some-path-to-templates', 'replay_dir': '/home/example/some-path-to-replay-files', 'default_context': { 'full_name': 'Raphael Pierzina', 'github_username': '******', }, 'abbreviations': { 'gh': 'https://github.com/{0}.git', 'gl': 'https://gitlab.com/hackebrot/{0}.git', 'bb': 'https://bitbucket.org/{0}', 'pytest-plugin': 'https://github.com/pytest-dev/pytest-plugin.git', } } assert config.merge_configs(default, user_config) == expected_config
def test_merge_configs(): default = { "cookiecutters_dir": "/home/example/some-path-to-templates", "replay_dir": "/home/example/some-path-to-replay-files", "default_context": {}, "abbreviations": { "gh": "https://github.com/{0}.git", "gl": "https://gitlab.com/{0}.git", "bb": "https://bitbucket.org/{0}", }, } user_config = { "default_context": { "full_name": "Raphael Pierzina", "github_username": "******", }, "abbreviations": { "gl": "https://gitlab.com/hackebrot/{0}.git", "pytest-plugin": "https://github.com/pytest-dev/pytest-plugin.git", }, } expected_config = { "cookiecutters_dir": "/home/example/some-path-to-templates", "replay_dir": "/home/example/some-path-to-replay-files", "default_context": { "full_name": "Raphael Pierzina", "github_username": "******", }, "abbreviations": { "gh": "https://github.com/{0}.git", "gl": "https://gitlab.com/hackebrot/{0}.git", "bb": "https://bitbucket.org/{0}", "pytest-plugin": "https://github.com/pytest-dev/pytest-plugin.git", }, } assert config.merge_configs(default, user_config) == expected_config