Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fin_remove_fake_project_dir():
if os.path.isdir('fake-project'):
utils.rmtree('fake-project')
request.addfinalizer(fin_remove_fake_project_dir)
def fin_remove_additional_folders():
if os.path.exists('inputpizzä'):
utils.rmtree('inputpizzä')
if os.path.exists('inputgreen'):
utils.rmtree('inputgreen')
if os.path.exists('inputbinary_files'):
utils.rmtree('inputbinary_files')
if os.path.exists('tests/custom_output_dir'):
utils.rmtree('tests/custom_output_dir')
if os.path.exists('inputpermissions'):
utils.rmtree('inputpermissions')
request.addfinalizer(fin_remove_additional_folders)
def tearDown(self):
with utils.work_in(config.DEFAULT_CONFIG['cookiecutters_dir']):
if os.path.isdir('cookiecutter-pypackage'):
utils.rmtree('cookiecutter-pypackage')
if os.path.isdir('boilerplate'):
utils.rmtree('boilerplate')
super(TestGitBranch, self).tearDown()
def bake_in_temp_dir(cookies, *args, **kwargs):
"""
Delete the temporal directory that is created when executing the tests
:param cookies: pytest_cookies.Cookies, cookie to be baked and its
temporalfiles will be removed
"""
result = cookies.bake(*args, **kwargs)
try:
yield result
finally:
rmtree(str(result.project))
def finalizer_remove_output_folder():
if os.path.exists('output_folder'):
utils.rmtree('output_folder')
request.addfinalizer(finalizer_remove_output_folder)
def remove_cookiecutter_dirs():
if os.path.isdir('cookiecutter-pypackage'):
utils.rmtree('cookiecutter-pypackage')
if os.path.isdir('cookiecutter-trytonmodule'):
utils.rmtree('cookiecutter-trytonmodule')
request.addfinalizer(remove_cookiecutter_dirs)
def fin_remove_additional_dirs():
if os.path.isdir('fake-project'):
utils.rmtree('fake-project')
if os.path.isdir('fake-project-extra'):
utils.rmtree('fake-project-extra')
if os.path.isdir('fake-project-templated'):
utils.rmtree('fake-project-templated')
if os.path.isdir('fake-project-dict'):
utils.rmtree('fake-project-dict')
if os.path.isdir('fake-tmp'):
utils.rmtree('fake-tmp')
request.addfinalizer(fin_remove_additional_dirs)
"""
Delete the temporal directory that is created when executing the tests.
https://github.com/audreyr/cookiecutter-pypackage/blob/master/tests/test_bake_project.py#L33
:param cookies: pytest_cookies.Cookies, cookie to be baked and its temporal files will be removed
"""
with git_disable_gpgsign():
extra_context = kwargs.pop("extra_context", {})
extra_context["_testing"] = True
result = cookies.bake(*args, extra_context=extra_context, **kwargs)
try:
yield result
finally:
if result.project:
rmtree(str(result.project))
delete_project_on_failure):
"""Run hook from repo directory, clean project directory if hook fails.
:param repo_dir: Project template input directory.
:param hook_name: The hook to execute.
:param project_dir: The directory to execute the script from.
:param context: Cookiecutter project context.
:param delete_project_on_failure: Delete the project directory on hook
failure?
"""
with work_in(repo_dir):
try:
run_hook(hook_name, project_dir, context)
except FailedHookException:
if delete_project_on_failure:
rmtree(project_dir)
logger.error(
"Stopping generation because {} hook "
"script didn't exit successfully".format(hook_name)
)
raise