def test_activate_help(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: if not platform.startswith("win"): commands = (shell_vars['command_setup'] + """ "{syspath}{cmd_path}activate" Zanzibar """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') assert_in("activate must be sourced", stderr) assert_in("Usage: source activate ENV", stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" --help """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if platform.startswith("win") and shell in ["cmd.exe", "powershell"]: assert_in("Usage: activate ENV", stderr) else: assert_in("Usage: source activate ENV", stderr) commands = (shell_vars['command_setup'] + """ {syspath}{cmd_path}deactivate """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') assert_in("deactivate must be sourced", stderr) assert_in("Usage: source deactivate", stderr) commands = (shell_vars['command_setup'] + """ {source} {syspath}{cmd_path}deactivate --help """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if platform == 'win' and shell in ["cmd.exe", "powershell"]: assert_in("Usage: deactivate", stderr) else: assert_in("Usage: source deactivate", stderr)
def test_activate_help(): for shell in shells: with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: if not platform.startswith("win"): commands = (command_setup + """ {syspath}{binpath}activate Zanzibar """).format(envs=envs, **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') assert_in("activate must be sourced", stderr) assert_in("Usage: source activate ENV", stderr) commands = (command_setup + """ {source} {syspath}{binpath}activate --help """).format(envs=envs, **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if platform.startswith("win"): assert_in("Usage: activate ENV", stderr) else: assert_in("Usage: source activate ENV", stderr) commands = (command_setup + """ {syspath}{binpath}deactivate """).format(envs=envs, **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') assert_in("deactivate must be sourced", stderr) assert_in("Usage: source deactivate", stderr) commands = (command_setup + """ {source} {syspath}{binpath}deactivate --help """).format(envs=envs, **_format_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if platform == 'win': assert_in("Usage: deactivate", stderr) else: assert_in("Usage: source deactivate", stderr)
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_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))
join(env_root, env_name, 'bin'), ] return paths PYTHONPATH = os.path.dirname(os.path.dirname(__file__)) BASE_PATH = os.getenv("PATH") # Make sure the subprocess activate calls this python syspath = pathsep.join(_envpaths(root_dir)) echo = "echo" escape_curly = lambda x: x.replace("{", "{{").replace("}", "}}") if platform.startswith("win"): shells = ['cmd.exe'] ps_var = "PROMPT" var_format = "%{var}%" binpath = "\\Scripts\\" # mind the trailing slash. source_setup = "call" nul = '1>NUL 2>&1' set_var = 'set ' shell_suffix = ".bat" printps1 = '{echo} {var}'.format( echo=echo if os.getenv(ps_var) else "echo.", var=var_format.format(var=ps_var)) else: # Only run these tests for commands that are installed. shells = ['bash', 'zsh']
paths = [join(env_root, env_name).rstrip("/"), join(env_root, env_name, 'bin'), ] return paths PYTHONPATH = os.path.dirname(os.path.dirname(__file__)) BASE_PATH = os.getenv("PATH") # Make sure the subprocess activate calls this python syspath = pathsep.join(_envpaths(root_dir)) echo = "echo" escape_curly = lambda x: x.replace("{", "{{").replace("}", "}}") if platform.startswith("win"): shells = ['cmd.exe'] ps_var = "PROMPT" var_format = "%{var}%" binpath = "\\Scripts\\" # mind the trailing slash. source_setup = "call" nul = '1>NUL 2>&1' set_var = 'set ' shell_suffix = ".bat" printps1 = '{echo} {var}'.format(echo=echo if os.getenv(ps_var) else "echo.", var=var_format.format(var=ps_var)) else: # Only run these tests for commands that are installed. shells = ['bash', 'zsh'] ps_var = "PS1" var_format = "${var}"