|
@@ 39-55 (lines=17) @@
|
| 36 |
|
f.write("f = open('python_pre.txt', 'w')\n") |
| 37 |
|
f.write("f.close()\n") |
| 38 |
|
|
| 39 |
|
if sys.platform.startswith('win'): |
| 40 |
|
post = 'post_gen_project.bat' |
| 41 |
|
with open(os.path.join(hook_dir, post), 'w') as f: |
| 42 |
|
f.write("@echo off\n") |
| 43 |
|
f.write("\n") |
| 44 |
|
f.write("echo post generation hook\n") |
| 45 |
|
f.write("echo. >shell_post.txt\n") |
| 46 |
|
else: |
| 47 |
|
post = 'post_gen_project.sh' |
| 48 |
|
filename = os.path.join(hook_dir, post) |
| 49 |
|
with open(filename, 'w') as f: |
| 50 |
|
f.write("#!/bin/bash\n") |
| 51 |
|
f.write("\n") |
| 52 |
|
f.write("echo 'post generation hook';\n") |
| 53 |
|
f.write("touch 'shell_post.txt'\n") |
| 54 |
|
# Set the execute bit |
| 55 |
|
os.chmod(filename, os.stat(filename).st_mode | stat.S_IXUSR) |
| 56 |
|
|
| 57 |
|
return post |
| 58 |
|
|
|
@@ 132-146 (lines=15) @@
|
| 129 |
|
|
| 130 |
|
def test_run_hook(self): |
| 131 |
|
"""Execute hook from specified template in specified output |
| 132 |
|
directory. |
| 133 |
|
""" |
| 134 |
|
tests_dir = os.path.join(self.repo_path, 'input{{hooks}}') |
| 135 |
|
with utils.work_in(self.repo_path): |
| 136 |
|
hooks.run_hook('pre_gen_project', tests_dir, {}) |
| 137 |
|
assert os.path.isfile(os.path.join(tests_dir, 'python_pre.txt')) |
| 138 |
|
|
| 139 |
|
hooks.run_hook('post_gen_project', tests_dir, {}) |
| 140 |
|
assert os.path.isfile(os.path.join(tests_dir, 'shell_post.txt')) |
| 141 |
|
|
| 142 |
|
def test_run_failing_hook(self): |
| 143 |
|
hook_path = os.path.join(self.hooks_path, 'pre_gen_project.py') |
| 144 |
|
tests_dir = os.path.join(self.repo_path, 'input{{hooks}}') |
| 145 |
|
|
| 146 |
|
with open(hook_path, 'w') as f: |
| 147 |
|
f.write("#!/usr/bin/env python\n") |
| 148 |
|
f.write("import sys; sys.exit(1)\n") |
| 149 |
|
|