Code Duplication    Length = 73-76 lines in 2 locations

tests/test_activate.py 2 locations

@@ 299-374 (lines=76) @@
296
                    assert builder['activate_scripts'] == ()
297
                    assert builder['deactivate_scripts'] == ()
298
299
    @pytest.mark.skipif(on_win, reason="cygpath isn't always on PATH")
300
    def test_build_stack_shlvl_1(self):
301
        with tempdir() as td:
302
            mkdir_p(join(td, 'conda-meta'))
303
            activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d'))
304
            activate_d_1 = join(activate_d_dir, 'see-me.sh')
305
            activate_d_2 = join(activate_d_dir, 'dont-see-me.bat')
306
            touch(join(activate_d_1))
307
            touch(join(activate_d_2))
308
309
            old_prefix = '/old/prefix'
310
            activator = PosixActivator()
311
            old_path = activator.pathsep_join(activator._add_prefix_to_path(old_prefix))
312
313
            with env_vars({
314
                'CONDA_SHLVL': '1',
315
                'CONDA_PREFIX': old_prefix,
316
                'PATH': old_path,
317
                'CONDA_ENV_PROMPT': '({default_env})',
318
            }, reset_context):
319
                activator = PosixActivator()
320
                builder = activator.build_stack(td)
321
                new_path = activator.pathsep_join(activator._add_prefix_to_path(td))
322
                conda_prompt_modifier = "(%s)" % td
323
                ps1 = conda_prompt_modifier + os.environ.get('PS1', '')
324
325
                assert builder['unset_vars'] == ()
326
327
                assert td in new_path
328
                assert old_prefix in new_path
329
330
                set_vars = {
331
                    'PS1': ps1,
332
                }
333
                export_vars = {
334
                    'PATH': new_path,
335
                    'CONDA_PREFIX': td,
336
                    'CONDA_PREFIX_1': old_prefix,
337
                    'CONDA_SHLVL': 2,
338
                    'CONDA_DEFAULT_ENV': td,
339
                    'CONDA_PROMPT_MODIFIER': conda_prompt_modifier,
340
                    'CONDA_STACKED_2': 'true',
341
                }
342
                assert builder['set_vars'] == set_vars
343
                assert builder['export_vars'] == export_vars
344
                assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),)
345
                assert builder['deactivate_scripts'] == ()
346
347
                with env_vars({
348
                    'PATH': new_path,
349
                    'CONDA_PREFIX': td,
350
                    'CONDA_PREFIX_1': old_prefix,
351
                    'CONDA_SHLVL': 2,
352
                    'CONDA_DEFAULT_ENV': td,
353
                    'CONDA_PROMPT_MODIFIER': conda_prompt_modifier,
354
                    'CONDA_STACKED_2': 'true',
355
                }):
356
                    activator = PosixActivator()
357
                    builder = activator.build_deactivate()
358
359
                    assert builder['unset_vars'] == (
360
                        'CONDA_PREFIX_1',
361
                        'CONDA_STACKED_2',
362
                    )
363
                    assert builder['set_vars'] == {
364
                        'PS1': '(/old/prefix)',
365
                    }
366
                    assert builder['export_vars'] == {
367
                        'CONDA_DEFAULT_ENV': old_prefix,
368
                        'CONDA_PREFIX': old_prefix,
369
                        'CONDA_PROMPT_MODIFIER': '(%s)' % old_prefix,
370
                        'CONDA_SHLVL': 1,
371
                        'PATH': old_path,
372
                    }
373
                    assert builder['activate_scripts'] == ()
374
                    assert builder['deactivate_scripts'] == ()
375
376
    def test_activate_same_environment(self):
377
        with tempdir() as td:
@@ 225-297 (lines=73) @@
222
                    assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),)
223
                    assert builder['deactivate_scripts'] == ()
224
225
    @pytest.mark.skipif(on_win, reason="cygpath isn't always on PATH")
226
    def test_build_activate_shlvl_1(self):
227
        with tempdir() as td:
228
            mkdir_p(join(td, 'conda-meta'))
229
            activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d'))
230
            activate_d_1 = join(activate_d_dir, 'see-me.sh')
231
            activate_d_2 = join(activate_d_dir, 'dont-see-me.bat')
232
            touch(join(activate_d_1))
233
            touch(join(activate_d_2))
234
235
            old_prefix = '/old/prefix'
236
            activator = PosixActivator()
237
            old_path = activator.pathsep_join(activator._add_prefix_to_path(old_prefix))
238
239
            with env_vars({
240
                'CONDA_SHLVL': '1',
241
                'CONDA_PREFIX': old_prefix,
242
                'PATH': old_path,
243
                'CONDA_ENV_PROMPT': '({default_env})',
244
            }, reset_context):
245
                activator = PosixActivator()
246
                builder = activator.build_activate(td)
247
                new_path = activator.pathsep_join(activator._replace_prefix_in_path(old_prefix, td))
248
                conda_prompt_modifier = "(%s)" % td
249
                ps1 = conda_prompt_modifier + os.environ.get('PS1', '')
250
251
                assert td in new_path
252
                assert old_prefix not in new_path
253
254
                assert builder['unset_vars'] == ()
255
256
                set_vars = {
257
                    'PS1': ps1,
258
                }
259
                export_vars = {
260
                    'PATH': new_path,
261
                    'CONDA_PREFIX': td,
262
                    'CONDA_PREFIX_1': old_prefix,
263
                    'CONDA_SHLVL': 2,
264
                    'CONDA_DEFAULT_ENV': td,
265
                    'CONDA_PROMPT_MODIFIER': conda_prompt_modifier,
266
                }
267
                assert builder['set_vars'] == set_vars
268
                assert builder['export_vars'] == export_vars
269
                assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),)
270
                assert builder['deactivate_scripts'] == ()
271
272
                with env_vars({
273
                    'PATH': new_path,
274
                    'CONDA_PREFIX': td,
275
                    'CONDA_PREFIX_1': old_prefix,
276
                    'CONDA_SHLVL': 2,
277
                    'CONDA_DEFAULT_ENV': td,
278
                    'CONDA_PROMPT_MODIFIER': conda_prompt_modifier,
279
                }):
280
                    activator = PosixActivator()
281
                    builder = activator.build_deactivate()
282
283
                    assert builder['unset_vars'] == (
284
                        'CONDA_PREFIX_1',
285
                    )
286
                    assert builder['set_vars'] == {
287
                        'PS1': '(/old/prefix)',
288
                    }
289
                    assert builder['export_vars'] == {
290
                        'CONDA_DEFAULT_ENV': old_prefix,
291
                        'CONDA_PREFIX': old_prefix,
292
                        'CONDA_PROMPT_MODIFIER': '(%s)' % old_prefix,
293
                        'CONDA_SHLVL': 1,
294
                        'PATH': old_path,
295
                    }
296
                    assert builder['activate_scripts'] == ()
297
                    assert builder['deactivate_scripts'] == ()
298
299
    @pytest.mark.skipif(on_win, reason="cygpath isn't always on PATH")
300
    def test_build_stack_shlvl_1(self):