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_cookiecutter_git(monkeypatch):
monkeypatch.setattr(
'cookiecutter.prompt.read_user_variable',
lambda var, default: default
)
main.cookiecutter('https://github.com/audreyr/cookiecutter-pypackage.git')
clone_dir = os.path.join(
os.path.expanduser('~/.cookiecutters'),
'cookiecutter-pypackage'
)
assert os.path.exists(clone_dir)
assert os.path.isdir('boilerplate')
assert os.path.isfile('boilerplate/README.rst')
assert os.path.exists('boilerplate/setup.py')
def test_hook_with_extension(template, output_dir):
project_dir = main.cookiecutter(
template,
no_input=True,
output_dir=output_dir,
extra_context={
'project_slug': 'foobar',
'name': 'Cookiemonster',
},
)
readme_file = os.path.join(project_dir, 'README.rst')
with codecs.open(readme_file, encoding='utf8') as f:
readme = f.read().strip()
assert readme == 'Hello Cookiemonster!'
def test_raise_on_invalid_mode(invalid_kwargs):
with pytest.raises(exceptions.InvalidModeException):
main.cookiecutter('foo', replay=True, **invalid_kwargs)
def test_cookiecutter_mercurial(self):
if not PY3:
sys.stdin = StringIO('\n\n\n\n\n\n\n\n\n')
main.cookiecutter('https://bitbucket.org/pokoli/cookiecutter-trytonmodule')
logging.debug('Current dir is {0}'.format(os.getcwd()))
clone_dir = os.path.join(os.path.expanduser('~/.cookiecutters'), 'cookiecutter-trytonmodule')
self.assertTrue(os.path.exists(clone_dir))
self.assertTrue(os.path.isdir('module_name'))
self.assertTrue(os.path.isfile('module_name/README'))
self.assertTrue(os.path.exists('module_name/setup.py'))
def test_cookiecutter_no_input_return_project_dir():
"""Call `cookiecutter()` with `no_input=True`."""
project_dir = main.cookiecutter('tests/fake-repo-pre', no_input=True)
assert project_dir == os.path.abspath('fake-project')
def bake(request):
"""
Run cookiecutter with the given input_dir path.
"""
main.cookiecutter(request.param, no_input=True)
def test_cookiecutter_local_with_input(monkeypatch):
monkeypatch.setattr(
'cookiecutter.prompt.read_user_variable',
lambda var, default: default
)
main.cookiecutter('tests/fake-repo-pre/', no_input=False)
assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}')
assert not os.path.isdir('tests/fake-repo-pre/fake-project')
assert os.path.isdir('fake-project')
assert os.path.isfile('fake-project/README.rst')
assert not os.path.exists('fake-project/json/')
def test_abbreviation_expansion():
input_dir = main.expand_abbreviations(
'foo', {'abbreviations': {'foo': 'bar'}}
)
assert input_dir == 'bar'
# Check if the output directory exists
if os.path.exists(self.outdir):
if self.force:
logging.warning("Output directory '{}' exists - continuing as --force specified".format(self.outdir))
else:
logging.error("Output directory '{}' exists!".format(self.outdir))
logging.info("Use -f / --force to overwrite existing files")
sys.exit(1)
else:
os.makedirs(self.outdir)
# Build the template in a temporary directory
self.tmpdir = tempfile.mkdtemp()
template = os.path.join(os.path.dirname(os.path.realpath(nf_core.__file__)), 'pipeline-template/')
cookiecutter.main.cookiecutter(
template,
extra_context = {
'name': self.name,
'description': self.description,
'author': self.author,
'name_noslash': self.name_noslash,
'name_docker': self.name_docker,
'short_name': self.short_name,
'version': self.new_version,
'nf_core_version': nf_core.__version__
},
no_input = True,
overwrite_if_exists = self.force,
output_dir = self.tmpdir
)
:param template_dir: A string containing an absolute or relative path
to a directory where the templates are located. If the provided
directory is a relative path, it is resolved using a known location.
:param extra_context: A dict of values that are used to override
default or user specified values.
:param output_dir: An string with an absolute path to a directory where
the templates should be written to.
:param overwrite: An optional bool whether or not to overwrite existing
templates.
:return: None
"""
template_dir = self._resolve_template_dir(template_dir)
self._validate_template_dir(template_dir)
try:
cookiecutter.main.cookiecutter(
template_dir,
extra_context=extra_context,
output_dir=output_dir,
overwrite_if_exists=overwrite,
no_input=True,
)
except cookiecutter.exceptions.NonTemplatedInputDirException:
util.sysexit_with_message(
"The specified template directory ("
+ str(template_dir)
+ ") is in an invalid format"
)