def test_activate_symlinking(shell): """Symlinks or bat file redirects are created at activation time. Make sure that the files/links exist, and that they point where they should.""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths1} to PATH'\ .format(syspath=pathlist_to_str(_envpaths(root_dir)), envpaths1=pathlist_to_str(_envpaths(envs, 'test1')))) where = 'Scripts' if sys.platform == 'win32' else 'bin' for env in gen_test_env_paths(envs, shell)[:2]: scripts = { where: ["conda"], 'cmd': ["activate", "deactivate"], } for where, files in scripts.items(): for f in files: if sys.platform == "win32": file_path = shells[shell]["slash_convert"][1].join( [env, where, f + shells[shell]["shell_suffix"]]) # must translate path to windows representation for Python's sake file_path = shells[shell]["path_from"](file_path) assert (os.path.lexists(file_path)) else: file_path = join(env, where, f) assert (os.path.lexists(file_path)) s = os.lstat(file_path) assert (stat.S_ISLNK(s.st_mode)) assert (os.readlink(file_path) == '{root_path}'.format( root_path=join(sys.prefix, where, f))) if platform != 'win': # Test activate when there are no write permissions in the # env. prefix_bin_path = join(gen_test_env_paths(envs, shell)[2], 'bin') commands = (shell_vars['command_setup'] + """ mkdir -p {prefix_bin_path} chmod 000 {prefix_bin_path} {source} activate "{env_dirs[2]}" """).format(prefix_bin_path=prefix_bin_path, envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_in("do not have write access", stderr) # restore permissions so the dir will get cleaned up run_in( "chmod 777 {prefix_bin_path}".format( prefix_bin_path=prefix_bin_path), shell)
def test_activate_env_from_env_with_root_activate(): for shell in shells: with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (command_setup + """ {source} {syspath}{binpath}activate "{env_dirs[0]}" {nul} {source} {syspath}{binpath}activate "{env_dirs[1]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'discarding {envpaths1} from PATH\nprepending {envpaths2} to PATH'\ .format(envpaths1=pathlist_to_str(_envpaths(envs, 'test1')), envpaths2=pathlist_to_str(_envpaths(envs, 'test2')))) assert_equals(stdout, pathsep.join(_envpaths(envs, 'test2') + [BASE_PATH, ]))
def test_activate_symlinking(shell): """Symlinks or bat file redirects are created at activation time. Make sure that the files/links exist, and that they point where they should.""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths1} to PATH'\ .format(syspath=pathlist_to_str(_envpaths(root_dir)), envpaths1=pathlist_to_str(_envpaths(envs, 'test1')))) where = 'Scripts' if sys.platform == 'win32' else 'bin' for env in gen_test_env_paths(envs, shell)[:2]: scripts = {where: ["conda"], 'cmd': ["activate", "deactivate"], } for where, files in scripts.items(): for f in files: if sys.platform == "win32": file_path = shells[shell]["slash_convert"][1].join([env, where, f + shells[shell]["shell_suffix"]]) # must translate path to windows representation for Python's sake file_path = shells[shell]["path_from"](file_path) assert(os.path.lexists(file_path)) else: file_path = join(env, where, f) assert(os.path.lexists(file_path)) s = os.lstat(file_path) assert(stat.S_ISLNK(s.st_mode)) assert(os.readlink(file_path) == '{root_path}'.format(root_path=join(sys.prefix, where, f))) if platform != 'win': # Test activate when there are no write permissions in the # env. prefix_bin_path = join(gen_test_env_paths(envs, shell)[2], 'bin') commands = (shell_vars['command_setup'] + """ mkdir -p {prefix_bin_path} chmod 000 {prefix_bin_path} {source} activate "{env_dirs[2]}" """).format(prefix_bin_path=prefix_bin_path, envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_in("do not have write access", stderr) # restore permissions so the dir will get cleaned up run_in("chmod 777 {prefix_bin_path}".format(prefix_bin_path=prefix_bin_path), shell)
def test_activate_symlinking(): for shell in shells: with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (command_setup + """ {source} {syspath}{binpath}activate "{env_dirs[0]}" """).format(envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths1} to PATH'\ .format(syspath=pathlist_to_str(_envpaths(root_dir)), envpaths1=pathlist_to_str(_envpaths(envs, 'test1')))) for env in gen_test_env_paths(envs)[:2]: for f in ['conda', 'activate', 'deactivate']: if platform.startswith('win'): file_path = join(env, "Scripts", f + ".bat") assert os.path.exists(file_path) with open(file_path) as batfile: assert root_dir in "".join(batfile.readlines()) else: file_path = join(env, "bin", f) assert os.path.lexists(file_path) assert os.path.exists(file_path) s = os.lstat(file_path) assert stat.S_ISLNK(s.st_mode) assert os.readlink(file_path) == '{root_path}'.format( root_path=join(sys.prefix, "bin", f)) if platform != 'win': # Test activate when there are no write permissions in the # env. prefix_bin_path = gen_test_env_paths(envs)[2] + binpath commands = (command_setup + """ mkdir -p {prefix_bin_path} chmod 000 {prefix_bin_path} {source} activate "{env_dirs[2]}" """).format(prefix_bin_path=prefix_bin_path, envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_in("do not have write access", stderr) # restore permissions so the dir will get cleaned up run_in("chmod 777 {prefix_bin_path}".format( prefix_bin_path=prefix_bin_path))
def test_activate_env_from_env_with_root_activate(): for shell in shells: with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (command_setup + """ {source} {syspath}{binpath}activate "{env_dirs[0]}" {nul} {source} {syspath}{binpath}activate "{env_dirs[1]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'discarding {envpaths1} from PATH\nprepending {envpaths2} to PATH'\ .format(envpaths1=pathlist_to_str(_envpaths(envs, 'test1')), envpaths2=pathlist_to_str(_envpaths(envs, 'test2')))) assert_equals( stdout, pathsep.join(_envpaths(envs, 'test2') + [ BASE_PATH, ]))
def test_activate_symlinking(): for shell in shells: with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (command_setup + """ {source} {syspath}{binpath}activate "{env_dirs[0]}" """).format(envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths1} to PATH'\ .format(syspath=pathlist_to_str(_envpaths(root_dir)), envpaths1=pathlist_to_str(_envpaths(envs, 'test1')))) for env in gen_test_env_paths(envs)[:2]: for f in ['conda', 'activate', 'deactivate']: if platform.startswith('win'): file_path = join(env, "Scripts", f + ".bat") assert os.path.exists(file_path) with open(file_path) as batfile: assert root_dir in "".join(batfile.readlines()) else: file_path = join(env, "bin", f) assert os.path.lexists(file_path) assert os.path.exists(file_path) s = os.lstat(file_path) assert stat.S_ISLNK(s.st_mode) assert os.readlink(file_path) == '{root_path}'.format(root_path=join(sys.prefix, "bin", f)) if platform != 'win': # Test activate when there are no write permissions in the # env. prefix_bin_path = gen_test_env_paths(envs)[2] + binpath commands = (command_setup + """ mkdir -p {prefix_bin_path} chmod 000 {prefix_bin_path} {source} activate "{env_dirs[2]}" """).format(prefix_bin_path=prefix_bin_path, envs=envs, env_dirs=gen_test_env_paths(envs), **_format_vars) stdout, stderr = run_in(commands, shell) assert_in("do not have write access", stderr) # restore permissions so the dir will get cleaned up run_in("chmod 777 {prefix_bin_path}".format(prefix_bin_path=prefix_bin_path))
def test_activate_test1(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate{shell_suffix}" "{env_dirs[0]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths} to PATH'\ .format(envpaths=pathlist_to_str(_envpaths(envs, 'test1'), False)), shell) assert_in(pathsep.join(_envpaths(envs, 'test1')), shells[shell]["path_from"](stdout), shell)
def test_activate_env_from_env_with_root_activate(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{binpath}activate" "{env_dirs[1]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'prepending {envpaths2} to PATH'\ .format(envpaths2=pathlist_to_str(_envpaths(envs, 'test 2', shelldict=shells[shell])))) assert_in(shells[shell]['pathsep'].join(_envpaths(envs, 'test 2', shelldict=shells[shell])), stdout)