for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
# -*- coding: utf-8 -*-
import pytest
import textwrap
from cookiecutter import hooks
@pytest.yield_fixture
def dir_with_hooks(tmpdir):
"""Yield a directory that contains hook backup files."""
hooks_dir = tmpdir.mkdir('hooks')
pre_hook_content = textwrap.dedent(
u"""
#!/usr/bin/env python
print('pre_gen_project.py~')
"""
)
pre_gen_hook_file = hooks_dir / 'pre_gen_project.py~'
pre_gen_hook_file.write_text(pre_hook_content, encoding='utf8')
post_hook_content = textwrap.dedent(
print('post_gen_project.py~')
post_gen_hook_file = hooks_dir / 'post_gen_project.py~'
post_gen_hook_file.write_text(post_hook_content, encoding='utf8')
# Make sure to yield the parent directory as `find_hooks()`
# looks into `hooks/` in the current working directory
yield str(tmpdir)
pre_gen_hook_file.remove()
post_gen_hook_file.remove()
def test_find_hook_ignores_backup_files(monkeypatch, dir_with_hooks):
monkeypatch.chdir(dir_with_hooks)
assert hooks.find_hook('pre_gen_project') is None
assert hooks.find_hook('post_gen_project') is None