Code Duplication    Length = 36-37 lines in 2 locations

tests/test_win_utils.py 2 locations

@@ 203-239 (lines=37) @@
200
    os.rmdir(copied_tree_root)
201
202
203
@pytest.mark.skipif(not WIN_BEFORE_PY32)
204
def test_copytree_error_copystat(mocker, link_target_symlink):
205
    source, target = link_target_symlink
206
207
    subdir1 = os.path.join(target, 'sub1')
208
    subdir2 = os.path.join(target, 'sub2')
209
    temp_file = os.path.join(subdir1, 'a.txt')
210
211
    os.makedirs(subdir1)
212
    os.makedirs(subdir2)
213
    with open(temp_file, 'w') as f:
214
        f.write('test file')
215
216
    new_link = str(subdir1) + "_link"
217
    win_utils.symlink(subdir1, new_link)
218
219
    copied_tree_root = tempfile.mkdtemp(suffix='_copy_trees')
220
221
    # raise errors on copystat
222
    mocked_copy2 = mocker.patch(
223
        'cookiecutter.win_utils.copystat',
224
        side_effect=OSError('asdf')
225
    )
226
    mocked_copy2.side_effect.winerror = None
227
228
    # don't copy symlinks
229
    no_syms_root = os.path.join(copied_tree_root, 'no_syms')
230
    with pytest.raises(shutil.Error):
231
        win_utils.copytree(target, no_syms_root)
232
233
    shutil.rmtree(no_syms_root)
234
235
    os.remove(temp_file)
236
    os.rmdir(subdir1)
237
    os.rmdir(subdir2)
238
    os.rmdir(new_link)
239
    os.rmdir(copied_tree_root)
240
@@ 165-200 (lines=36) @@
162
    os.rmdir(copied_tree_root)
163
164
165
@pytest.mark.skipif(not WIN_BEFORE_PY32)
166
def test_copytree_error_copy2(mocker, link_target_symlink):
167
    source, target = link_target_symlink
168
169
    subdir1 = os.path.join(target, 'sub1')
170
    subdir2 = os.path.join(target, 'sub2')
171
    temp_file = os.path.join(subdir1, 'a.txt')
172
173
    os.makedirs(subdir1)
174
    os.makedirs(subdir2)
175
    with open(temp_file, 'w') as f:
176
        f.write('test file')
177
178
    new_link = str(subdir1) + "_link"
179
    win_utils.symlink(subdir1, new_link)
180
181
    copied_tree_root = tempfile.mkdtemp(suffix='_copy_trees')
182
183
    # raise errors on copy
184
    mocker.patch(
185
        'cookiecutter.win_utils.copy2',
186
        side_effect=OSError('asdf')
187
    )
188
189
    # don't copy symlinks
190
    no_syms_root = os.path.join(copied_tree_root, 'no_syms')
191
    with pytest.raises(shutil.Error):
192
        win_utils.copytree(target, no_syms_root)
193
194
    shutil.rmtree(no_syms_root)
195
196
    os.remove(temp_file)
197
    os.rmdir(subdir1)
198
    os.rmdir(subdir2)
199
    os.rmdir(new_link)
200
    os.rmdir(copied_tree_root)
201
202
203
@pytest.mark.skipif(not WIN_BEFORE_PY32)