Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_user_config_nonexistent(self):
""" Get config from a nonexistent ~/.cookiecutterrc file """
self.assertEqual(config.get_user_config(), config.DEFAULT_CONFIG)
def test_get_config():
"""
Opening and reading config file
"""
conf = config.get_config('tests/test-config/valid-config.yaml')
expected_conf = {
'cookiecutters_dir': '/home/example/some-path-to-templates',
'replay_dir': '/home/example/some-path-to-replay-files',
'default_context': {
'full_name': 'Firstname Lastname',
'email': 'firstname.lastname@gmail.com',
'github_username': 'example'
},
'abbreviations': {
'gh': 'https://github.com/{0}.git',
'bb': 'https://bitbucket.org/{0}',
}
}
assert conf == expected_conf
def test_get_config(self):
""" Opening and reading config file """
conf = config.get_config('tests/test-config/valid-config.yaml')
expected_conf = {
'cookiecutters_dir': '/home/example/some-path-to-templates',
'default_context': {
"full_name": "Firstname Lastname",
"email": "firstname.lastname@gmail.com",
"github_username": "example"
}
}
self.assertEqual(conf, expected_conf)
def test_repo_dir_for_alias():
"""
Should be path inside of cookiecutter's dir.
"""
cc_home = cc_config.DEFAULT_CONFIG['cookiecutters_dir']
expected_dir = os.path.join(cc_home, 'fake-repo')
actual_dir = resolve_repo_dir('gh:associatedpress/fake-repo')
assert expected_dir == actual_dir
def test_invalid_config(self):
"""
An invalid config file should raise an `InvalidConfiguration` exception.
"""
self.assertRaises(InvalidConfiguration, config.get_config,
"tests/test-config/invalid-config.yaml")
def test_repo_dir_for_url():
"""
Should be path inside of cookiecutter's dir.
"""
cc_home = cc_config.DEFAULT_CONFIG['cookiecutters_dir']
expected_dir = os.path.join(cc_home, 'fake-repo')
actual_dir = resolve_repo_dir('https://github.com/associatedpress/fake-repo.git')
assert expected_dir == actual_dir
def gather_inputs():
config = cookiecutter.config.get_user_config()
ctx = config.get('default_context')
full_name = ctx.get('full_name')
if not full_name:
full_name = input('What is your full name? ')
game_type = None
while game_type not in ['hilo', 'pacman', 'pong']:
game_type = input('Game type? [hilo, pacman, pong]? ')
package_name = input("What do you call your game? ")
package_name = to_package_style(package_name)
working_dir = input('Full path where to create the project [must exist]? ')
while not os.path.exists(working_dir):
print("Oh, that doesn't exist, try again...")
def take_action(self, parsed_args):
cc_home = cc_config.DEFAULT_CONFIG['cookiecutters_dir']
cookiecutters = Cookiecutters(cc_home)
templates = cookiecutters.info(status=parsed_args.status)
self.log.info("\nLocal Cookiecutter templates ({}):\n".format(cc_home))
if len(templates) == 0:
self.log.info(NO_TEMPLATES_ERROR_WITH_HELP_MSG)
else:
if parsed_args.status:
tbl = formatter.status(templates)
else:
tbl = formatter.list(templates)
self.log.info(tbl)
self.log.info('\n')
self.log.info(TEMPLATE_USAGE_MSG)
self.log.info(TEMPLATE_UPDATE_MSG)
def take_action(self, parsed_args):
if parsed_args.interactive and parsed_args.template == '':
cc_home = cc_config.DEFAULT_CONFIG['cookiecutters_dir']
cc = Cookiecutters(cc_home)
templates = cc.list_templates()
template = read_user_choice('project template', templates)
else:
# Create project skeleton
template = self.get_template(parsed_args)
if template:
self.log.info("Creating project from template: {}".format(template))
cookiecutter(
template,
overwrite_if_exists=True,
no_input=parsed_args.no_input
)
repo_dir = resolve_repo_dir(template)
# Update default template if it's empty or specifically requested
if self.default_template == '' or parsed_args.make_default: