| @@ 39-55 (lines=17) @@ | ||
| 36 | f.write("f.close()\n") |
|
| 37 | ||
| 38 | if sys.platform.startswith('win'): |
|
| 39 | post = 'post_gen_project.bat' |
|
| 40 | with open(os.path.join(hook_dir, post), 'w') as f: |
|
| 41 | f.write("@echo off\n") |
|
| 42 | f.write("\n") |
|
| 43 | f.write("echo post generation hook\n") |
|
| 44 | f.write("echo. >shell_post.txt\n") |
|
| 45 | else: |
|
| 46 | post = 'post_gen_project.sh' |
|
| 47 | filename = os.path.join(hook_dir, post) |
|
| 48 | with open(filename, 'w') as f: |
|
| 49 | f.write("#!/bin/bash\n") |
|
| 50 | f.write("\n") |
|
| 51 | f.write("echo 'post generation hook';\n") |
|
| 52 | f.write("touch 'shell_post.txt'\n") |
|
| 53 | # Set the execute bit |
|
| 54 | os.chmod(filename, os.stat(filename).st_mode | stat.S_IXUSR) |
|
| 55 | ||
| 56 | return post |
|
| 57 | ||
| 58 | ||
| @@ 132-146 (lines=15) @@ | ||
| 129 | def test_run_script_cwd(self): |
|
| 130 | """Change directory before running hook""" |
|
| 131 | hooks.run_script( |
|
| 132 | os.path.join(self.hooks_path, self.post_hook), |
|
| 133 | 'tests' |
|
| 134 | ) |
|
| 135 | assert os.path.isfile('tests/shell_post.txt') |
|
| 136 | assert 'tests' not in os.getcwd() |
|
| 137 | ||
| 138 | def test_run_script_with_context(self): |
|
| 139 | """Execute a hook script, passing a context""" |
|
| 140 | ||
| 141 | hook_path = os.path.join(self.hooks_path, 'post_gen_project.sh') |
|
| 142 | ||
| 143 | if sys.platform.startswith('win'): |
|
| 144 | post = 'post_gen_project.bat' |
|
| 145 | with open(os.path.join(self.hooks_path, post), 'w') as f: |
|
| 146 | f.write("@echo off\n") |
|
| 147 | f.write("\n") |
|
| 148 | f.write("echo post generation hook\n") |
|
| 149 | f.write("echo. >{{cookiecutter.file}}\n") |
|