Code Duplication    Length = 27-28 lines in 2 locations

tests/test_generate_hooks.py 2 locations

@@ 122-148 (lines=27) @@
119
    assert message in str(excinfo.value)
120
121
122
@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
123
def test_run_failing_hook_removes_output_directory():
124
    repo_path = os.path.abspath('tests/test-hooks/')
125
    hooks_path = os.path.abspath('tests/test-hooks/hooks')
126
127
    hook_dir = os.path.join(repo_path, 'hooks')
128
    template = os.path.join(repo_path, 'input{{cookiecutter.hooks}}')
129
    os.mkdir(repo_path)
130
    os.mkdir(hook_dir)
131
    os.mkdir(template)
132
133
    hook_path = os.path.join(hooks_path, 'pre_gen_project.py')
134
135
    with open(hook_path, 'w') as f:
136
        f.write("#!/usr/bin/env python\n")
137
        f.write("import sys; sys.exit(1)\n")
138
139
    with pytest.raises(FailedHookException) as excinfo:
140
        generate.generate_files(
141
            context={
142
                'cookiecutter': {'hooks': 'hooks'}
143
            },
144
            repo_dir='tests/test-hooks/',
145
            overwrite_if_exists=True
146
        )
147
148
    assert 'Hook script failed' in str(excinfo.value)
149
    assert not os.path.exists('inputhooks')
150
151
@@ 152-179 (lines=28) @@
149
    assert not os.path.exists('inputhooks')
150
151
152
@pytest.mark.usefixtures('clean_system', 'remove_additional_folders')
153
def test_run_failing_hook_preserves_existing_output_directory():
154
    repo_path = os.path.abspath('tests/test-hooks/')
155
    hooks_path = os.path.abspath('tests/test-hooks/hooks')
156
157
    hook_dir = os.path.join(repo_path, 'hooks')
158
    template = os.path.join(repo_path, 'input{{cookiecutter.hooks}}')
159
    os.mkdir(repo_path)
160
    os.mkdir(hook_dir)
161
    os.mkdir(template)
162
163
    hook_path = os.path.join(hooks_path, 'pre_gen_project.py')
164
165
    with open(hook_path, 'w') as f:
166
        f.write("#!/usr/bin/env python\n")
167
        f.write("import sys; sys.exit(1)\n")
168
169
    os.mkdir('inputhooks')
170
    with pytest.raises(FailedHookException) as excinfo:
171
        generate.generate_files(
172
            context={
173
                'cookiecutter': {'hooks': 'hooks'}
174
            },
175
            repo_dir='tests/test-hooks/',
176
            overwrite_if_exists=True
177
        )
178
179
    assert 'Hook script failed' in str(excinfo.value)
180
    assert os.path.exists('inputhooks')
181
182