def test_activate_root(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix="envs", dir=dirname(__file__)) as envs: commands = ( shell_vars["command_setup"] + """ {source} "{syspath}{binpath}activate" root {printpath} """ ).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_in(shells[shell]["pathsep"].join(_envpaths(root_dir, shelldict=shells[shell])), stdout, stderr) commands = ( shell_vars["command_setup"] + """ {source} "{syspath}{binpath}activate" root {source} "{syspath}{binpath}deactivate" {printpath} """ ).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars["base_path"], stderr)
def test_activate_relative_path(shell): """ current directory should be searched for environments """ shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs = gen_test_env_paths(envs, shell) env_dir = os.path.basename(env_dirs[0]) work_dir = os.path.dirname(env_dir) commands = (shell_vars['command_setup'] + """ cd {work_dir} {source} "{syspath}{binpath}activate" "{env_dir}" {printdefaultenv} """).format(work_dir=envs, envs=envs, env_dir=env_dir, **shell_vars) cwd = os.getcwd() # this is not effective for running bash on windows. It starts # in your home dir no matter what. That's what the cd is for above. os.chdir(envs) try: stdout, stderr = run_in(commands, shell, cwd=envs) except: raise finally: os.chdir(cwd) assert_equals(stdout.rstrip(), env_dir, stderr)
def test_activate_has_extra_env_vars(shell): """Test that environment variables in activate.d show up when activated""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs=gen_test_env_paths(envs, shell) for path in ["activate", "deactivate"]: dir = os.path.join(shells[shell]['path_from'](env_dirs[0]), "etc", "conda", "%s.d" % path) os.makedirs(dir) file = os.path.join(dir, "test" + shells[shell]["env_script_suffix"]) setting = "test" if path == "activate" else "" with open(file, 'w') as f: f.write(shells[shell]["set_var"] + "TEST_VAR=%s\n" % setting) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {echo} {var} """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'test', stderr) # Make sure the variable is reset after deactivation commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{binpath}deactivate" {echo} {var}. """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) # period here is because when var is blank, windows prints out the current echo setting. assert_equals(stdout, u'.', stderr)
def test_activate_deactivate(shell): if shell == 'bash.exe': pytest.skip("usage of cygpath in win_path_to_unix messes this test up") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: # debug TODO: remove if shell == 'bash.exe': commands = (shell_vars['command_setup'] + """ env | sort {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} env | sort set -x {source} "{syspath}{binpath}deactivate" env | sort {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) sys.stdout.write(stdout) sys.stderr.write(stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{binpath}deactivate" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert not stderr stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars['base_path'])
def test_activate_has_extra_env_vars(shell): """Test that environment variables in activate.d show up when activated""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs=gen_test_env_paths(envs, shell) act_path = shells[shell]["path_from"](join(env_dirs[0], "etc", "conda", "activate.d")) deact_path = shells[shell]["path_from"](join(env_dirs[0], "etc", "conda", "deactivate.d")) os.makedirs(act_path) os.makedirs(deact_path) with open(join(act_path, "test" + shells[shell]["env_script_suffix"]), "w") as f: f.write(shells[shell]["set_var"] + "TEST_VAR=test\n") commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {echo} {var} """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'test', stderr) # Make sure the variable is reset after deactivation with open(join(deact_path, "test" + shells[shell]["env_script_suffix"]), "w") as f: f.write(shells[shell]["set_var"] + "TEST_VAR=\n") commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{cmd_path}deactivate" {echo} {var} """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'', stderr)
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_non_ascii_char_in_path(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='Ånvs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{binpath}deactivate" {printdefaultenv}. """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'.', stderr)
def test_activate_deactivate(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" "{env_dirs[0]}" {nul} {source} "{syspath}{cmd_path}deactivate" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u"%s" % shell_vars['base_path'])
def test_activate_bad_directory(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" "{env_dirs[2]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_not_in(shells[shell]["path_to"](_envpaths(envs, 'test3')[0]), stdout) assert_equals(stderr, u'Error: could not find environment: {envpaths3}'.format(envpaths3=_envpaths(envs, 'test3')[0]))
def test_wrong_args(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" two args {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stderr, u'Error: did not expect more than one argument.') assert_equals(stdout, shell_vars['base_path'], stderr)
def test_deactivate_from_env(shell): """Tests whether the deactivate bat file or link in the activated environment works OK""" 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]}" {source} "{env_dirs[0]}{binpath}deactivate" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'', stderr)
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_non_ascii_char_in_path(shell): if shell.lower() not in ["cmd.exe", "powershell"]: pytest.xfail("subprocess with python 2.7 is broken with unicode") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='Ånvs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{cmd_path}deactivate" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'', stderr)
def test_wrong_args(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" two args {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_in("activate does not accept more than one argument", stderr) assert_equals(stdout, shell_vars['base_path'], stderr)
def test_activate_deactivate(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}deactivate" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars['base_path'])
def test_activate_from_env(shell): """Tests whether the activate bat file or link in the activated environment works OK""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs=gen_test_env_paths(envs, shell) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{binpath}activate" "{env_dirs[1]}" {printdefaultenv} """).format(envs=envs, env_dirs=env_dirs, **shell_vars) stdout, stderr = run_in(commands, shell) # rstrip on output is because the printing to console picks up an extra space assert_equals(stdout.rstrip(), env_dirs[1], stderr)
def test_activate_does_not_leak_echo_setting(shell): """Test that activate's setting of echo to off does not disrupt later echo calls""" if not on_win or shell != "cmd.exe": pytest.skip("test only relevant for cmd.exe on win") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ @echo on @call "{syspath}{binpath}activate.bat" "{env_dirs[0]}" @echo """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'ECHO is on.', stderr)
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)
def test_info(): conda_info_out, conda_info_err = run_conda_command('info') assert_equals(conda_info_err, '') for name in [ 'platform', 'conda version', 'root environment', 'default environment', 'envs directories', 'package cache', 'channel URLs', 'config file', 'is foreign system' ]: assert_in(name, conda_info_out) conda_info_e_out, conda_info_e_err = run_conda_command('info', '-e') assert_in('root', conda_info_e_out) assert_equals(conda_info_e_err, '') conda_info_s_out, conda_info_s_err = run_conda_command('info', '-s') assert_equals(conda_info_s_err, '') for name in [ 'sys.version', 'sys.prefix', 'sys.executable', 'conda location', 'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH' ]: assert_in(name, conda_info_s_out) if config.platform == 'linux': assert_in('LD_LIBRARY_PATH', conda_info_s_out) if config.platform == 'osx': assert_in('DYLD_LIBRARY_PATH', conda_info_s_out) conda_info_all_out, conda_info_all_err = run_conda_command('info', '--all') assert_equals(conda_info_all_err, '') assert_in(conda_info_out, conda_info_all_out) assert_in(conda_info_e_out, conda_info_all_out) assert_in(conda_info_s_out, conda_info_all_out)
def test_info(): conda_info_out, conda_info_err, rc = run_command(Commands.INFO) assert_equals(conda_info_err, '') for name in [ 'platform', 'conda version', 'envs directories', 'package cache', 'channel URLs', 'config file', 'offline mode' ]: assert_in(name, conda_info_out) conda_info_e_out, conda_info_e_err, rc = run_command(Commands.INFO, '-e') assert_in('base', conda_info_e_out) assert_equals(conda_info_e_err, '') conda_info_s_out, conda_info_s_err, rc = run_command(Commands.INFO, '-s') assert_equals(conda_info_s_err, '') for name in [ 'sys.version', 'sys.prefix', 'sys.executable', 'conda location', 'conda-build', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH' ]: assert_in(name, conda_info_s_out) if context.platform == 'linux': assert_in('LD_LIBRARY_PATH', conda_info_s_out) if context.platform == 'osx': assert_in('DYLD_LIBRARY_PATH', conda_info_s_out) conda_info_all_out, conda_info_all_err, rc = run_command( Commands.INFO, '--all') assert_equals(conda_info_all_err, '') assert_in(conda_info_out, conda_info_all_out) assert_in(conda_info_e_out, conda_info_all_out) assert_in(conda_info_s_out, conda_info_all_out)
def test_activate_relative_path(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: start_dir = os.getcwd() env_dirs = gen_test_env_paths(envs, shell) os.chdir(envs) env_dir = os.path.basename(env_dirs[0]) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dir}" {printdefaultenv} """).format(envs=envs, env_dir=env_dir, **shell_vars) stdout, stderr = run_in(commands, shell) os.chdir(start_dir) assert_equals(stdout, u'{env_dirs[0]}'.format(envs=envs, env_dirs=env_dirs), stderr)
def test_info(): conda_info_out, conda_info_err, rc = run_command(Commands.INFO) assert_equals(conda_info_err, '') for name in [ 'platform', 'conda version', 'envs directories', 'package cache', 'channel URLs', 'config file', 'offline mode' ]: assert_in(name, conda_info_out) conda_info_e_out, conda_info_e_err, rc = run_command(Commands.INFO, '-e') assert_in('base', conda_info_e_out) assert_equals(conda_info_e_err, '') conda_info_s_out, conda_info_s_err, rc = run_command(Commands.INFO, '-s') assert_equals(conda_info_s_err, '') for name in [ 'sys.version', 'sys.prefix', 'sys.executable', 'conda location', 'conda-build', 'PATH' ]: assert_in(name, conda_info_s_out) conda_info_all_out, conda_info_all_err, rc = run_command( Commands.INFO, '--all') assert_equals(conda_info_all_err, '') assert_in(conda_info_out, conda_info_all_out) assert_in(conda_info_e_out, conda_info_all_out) assert_in(conda_info_s_out, conda_info_all_out)
def test_info(): conda_info_out, conda_info_err = run_conda_command('info') assert_equals(conda_info_err, '') for name in ['platform', 'conda version', 'root environment', 'default environment', 'envs directories', 'package cache', 'channel URLs', 'config file', 'is foreign system']: assert_in(name, conda_info_out) conda_info_e_out, conda_info_e_err = run_conda_command('info', '-e') assert_in('root', conda_info_e_out) assert_equals(conda_info_e_err, '') conda_info_s_out, conda_info_s_err = run_conda_command('info', '-s') assert_equals(conda_info_s_err, '') for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location', 'conda-build', 'CIO_TEST', 'CONDA_DEFAULT_ENV', 'PATH', 'PYTHONPATH']: assert_in(name, conda_info_s_out) if config.platform == 'linux': assert_in('LD_LIBRARY_PATH', conda_info_s_out) if config.platform == 'osx': assert_in('DYLD_LIBRARY_PATH', conda_info_s_out) conda_info_all_out, conda_info_all_err = run_conda_command('info', '--all') assert_equals(conda_info_all_err, '') assert_in(conda_info_out, conda_info_all_out) assert_in(conda_info_e_out, conda_info_all_out) assert_in(conda_info_s_out, conda_info_all_out)
def test_wrong_args(shell): if shell == 'bash.exe': pytest.skip("usage of cygpath in win_path_to_unix messes this test up") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" two args {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_in("activate does not accept more than one argument", stderr) assert_equals(stdout, shell_vars['base_path'], stderr)
def test_path_translation(): test_cygwin_path = "test dummy text /usr/bin:/cygdrive/z/documents (x86)/code/conda/tests/envskhkzts/test1:/cygdrive/z/documents/code/conda/tests/envskhkzts/test1/cmd more dummy text" test_unix_path = "test dummy text /usr/bin:/z/documents (x86)/code/conda/tests/envskhkzts/test1:/z/documents/code/conda/tests/envskhkzts/test1/cmd more dummy text" test_win_path = "test dummy text /usr/bin;z:\\documents (x86)\\code\\conda\\tests\\envskhkzts\\test1;z:\\documents\\code\\conda\\tests\\envskhkzts\\test1\\cmd more dummy text" assert_equals(test_win_path, unix_path_to_win(test_unix_path)) assert_equals(test_unix_path, win_path_to_unix(test_win_path)) assert_equals(test_cygwin_path, win_path_to_cygwin(test_win_path)) assert_equals(test_win_path, cygwin_path_to_win(test_cygwin_path))
def test_activate_deactivate(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}deactivate" {printpath} """ ).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars["base_path"])
def test_wrong_args(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix="envs", dir=dirname(__file__)) as envs: commands = ( shell_vars["command_setup"] + """ {source} "{syspath}{binpath}activate" two args {printpath} """ ).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stderr, u"Error: did not expect more than one argument.\n (got two args)") assert_equals(stdout, shell_vars["base_path"], stderr)
def test_activate_bad_directory(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs = gen_test_env_paths(envs, shell) # Strange semicolons are here to defeat MSYS' automatic path conversion. # See http://www.mingw.org/wiki/Posix_path_conversion commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[2]}" {printpath} """).format(envs=envs, env_dirs=env_dirs, **shell_vars) stdout, stderr = run_in(commands, shell) # another semicolon here for comparison reasons with one above. assert_equals(stderr, u'could not find environment: {envpaths3}'.format( envpaths3=shells[shell]['path_from'](env_dirs[2]))) assert_not_in(env_dirs[2], stdout)
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_bad_directory(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs = gen_test_env_paths(envs, shell) # Strange semicolons are here to defeat MSYS' automatic path conversion. # See http://www.mingw.org/wiki/Posix_path_conversion commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[2]}" {printpath} """).format(envs=envs, env_dirs=env_dirs, **shell_vars) stdout, stderr = run_in(commands, shell) # another semicolon here for comparison reasons with one above. assert_equals( stderr, u'could not find environment: {envpaths3}'.format( envpaths3=shells[shell]['path_from'](env_dirs[2]))) assert_not_in(env_dirs[2], stdout)
def test_activate_deactivate(shell): # if shell == "bash.exe" and datetime.now() < datetime(2017, 5, 1): # pytest.xfail("fix this soon") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{binpath}deactivate" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars['base_path'])
def test_activate_bad_directory(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" "{env_dirs[2]}" {printpath} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_not_in(shells[shell]["path_to"](_envpaths(envs, 'test3')[0]), stdout) assert_equals( stderr, u'Error: could not find environment: {envpaths3}'.format( envpaths3=_envpaths(envs, 'test3')[0]))
def test_activate_relative_path(shell): """ current directory should be searched for environments """ shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs = gen_test_env_paths(envs, shell) env_dir = os.path.basename(env_dirs[0]) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dir}" {printdefaultenv} """).format(envs=envs, env_dir=env_dir, **shell_vars) cwd = os.getcwd() os.chdir(envs) try: stdout, stderr = run_in(commands, shell, cwd=envs) finally: os.chdir(cwd) assert_equals(stdout.rstrip(), env_dirs[0], stderr)
def test_activate_root(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" root {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_in(shells[shell]["path_to"](pathsep.join(_envpaths(root_dir))), stdout) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" root {source} "{syspath}{cmd_path}deactivate" {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u"%s" % shell_vars['base_path'], stderr)
def test_activate_root(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_in(shells[shell]['pathsep'].join(_envpaths(root_dir, shelldict=shells[shell])), stdout, stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {source} "{syspath}{binpath}deactivate" {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u"%s" % shell_vars['base_path'], stderr)
def test_activate_non_ascii_char_in_path(shell): if on_win and datetime.now() < datetime(2017, 6, 1) and shell == "bash.exe": pytest.xfail("save for later") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='Ånvs', dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{binpath}deactivate" {printdefaultenv}. """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) if shell == 'cmd.exe': assert_equals(stdout, u'', stderr) else: assert_equals(stdout, u'.', stderr)
def test_activate_root_simple(shell): if shell == 'bash.exe': pytest.skip("usage of cygpath in win_path_to_unix messes this test up") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_in( shells[shell]['pathsep'].join( _envpaths(context.root_prefix, shell=shell)), stdout, stderr) assert not stderr # debug TODO: remove if shell == 'bash.exe': commands = (shell_vars['command_setup'] + """ env | sort {source} "{syspath}{binpath}activate" root env | sort echo {source} "{syspath}{binpath}deactivate" {source} "{syspath}{binpath}deactivate" env | sort {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) sys.stdout.write(stdout) sys.stderr.write(stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {source} "{syspath}{binpath}deactivate" {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert not stderr stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u'%s' % shell_vars['base_path'])
def test_activate_help(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix="envs", dir=dirname(__file__)) as envs: if shell not in ["powershell.exe", "cmd.exe"]: commands = ( shell_vars["command_setup"] + """ "{syspath}{binpath}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}{binpath}activate" --help """ ).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, "") if shell in ["cmd.exe", "powershell"]: # assert_in("Usage: activate ENV", stderr) pass else: # assert_in("Usage: source activate ENV", stderr) commands = ( shell_vars["command_setup"] + """ {syspath}{binpath}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}{binpath}deactivate --help """ ).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, "")
def test_activate_root_simple(shell): if shell == 'bash.exe': pytest.skip("usage of cygpath in win_path_to_unix messes this test up") shell_vars = _format_vars(shell) with TemporaryDirectory(prefix=ENVS_PREFIX, dir=dirname(__file__)) as envs: commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_in(shells[shell]['pathsep'].join(_envpaths(context.root_prefix, shell=shell)), stdout, stderr) assert not stderr # debug TODO: remove if shell == 'bash.exe': commands = (shell_vars['command_setup'] + """ env | sort {source} "{syspath}{binpath}activate" root env | sort echo {source} "{syspath}{binpath}deactivate" {source} "{syspath}{binpath}deactivate" env | sort {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) sys.stdout.write(stdout) sys.stderr.write(stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {source} "{syspath}{binpath}deactivate" {printpath} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert not stderr stdout = strip_leading_library_bin(stdout, shells[shell]) assert_equals(stdout, u'%s' % shell_vars['base_path'])
def test_activate_has_extra_env_vars(shell): """Test that environment variables in activate.d show up when activated""" shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs = gen_test_env_paths(envs, shell) act_path = shells[shell]["path_from"](join(env_dirs[0], "etc", "conda", "activate.d")) deact_path = shells[shell]["path_from"](join(env_dirs[0], "etc", "conda", "deactivate.d")) os.makedirs(act_path) os.makedirs(deact_path) with open(join(act_path, "test" + shells[shell]["env_script_suffix"]), "w") as f: f.write(shells[shell]["set_var"] + "TEST_VAR=test\n") commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {echo} {var} """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'test', stderr) # Make sure the variable is reset after deactivation with open( join(deact_path, "test" + shells[shell]["env_script_suffix"]), "w") as f: f.write(shells[shell]["set_var"] + "TEST_VAR=\n") commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {source} "{env_dirs[0]}{cmd_path}deactivate" {echo} {var} """).format(envs=envs, env_dirs=env_dirs, var=shells[shell]["var_format"].format("TEST_VAR"), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u'', stderr)
def test_activate_help(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: if shell not in ['powershell.exe', 'cmd.exe']: commands = (shell_vars['command_setup'] + """ "{syspath}{binpath}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}{binpath}activate" --help """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if 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}{binpath}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}{binpath}deactivate --help """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '') if shell in ["cmd.exe", "powershell"]: assert_in("Usage: deactivate", stderr) else: assert_in("Usage: source deactivate", stderr)
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_info(): conda_info_out, conda_info_err, rc = run_command(Commands.INFO) assert_equals(conda_info_err, '') for name in ['platform', 'conda version', 'envs directories', 'package cache', 'channel URLs', 'config file', 'offline mode']: assert_in(name, conda_info_out) conda_info_e_out, conda_info_e_err, rc = run_command(Commands.INFO, '-e') assert_in('base', conda_info_e_out) assert_equals(conda_info_e_err, '') conda_info_s_out, conda_info_s_err, rc = run_command(Commands.INFO, '-s') assert_equals(conda_info_s_err, '') for name in ['sys.version', 'sys.prefix', 'sys.executable', 'conda location', 'conda-build', 'PATH']: assert_in(name, conda_info_s_out) conda_info_all_out, conda_info_all_err, rc = run_command(Commands.INFO, '--all') assert_equals(conda_info_all_err, '') assert_in(conda_info_out, conda_info_all_out) assert_in(conda_info_e_out, conda_info_all_out) assert_in(conda_info_s_out, conda_info_all_out)
def test_CONDA_DEFAULT_ENV(shell): shell_vars = _format_vars(shell) with TemporaryDirectory(prefix='envs', dir=dirname(__file__)) as envs: env_dirs=gen_test_env_paths(envs, shell) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {printdefaultenv} """).format(envs=envs, env_dirs=env_dirs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout.rstrip(), env_dirs[0], stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{binpath}activate" "{env_dirs[1]}" {printdefaultenv} """).format(envs=envs, env_dirs=env_dirs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout.rstrip(), env_dirs[1], stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[2]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{binpath}activate" "{env_dirs[2]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout.rstrip(), env_dirs[0], stderr) commands = (shell_vars['command_setup'] + """ {source} {syspath}{binpath}deactivate {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" "{env_dirs[0]}" {nul} {source} "{env_dirs[0]}{binpath}deactivate" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" two args {printdefaultenv} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {nul} {printdefaultenv} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout.rstrip(), 'root', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{binpath}activate" root {nul} {source} "{env_dirs[0]}{binpath}deactivate" {nul} {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr)
def test_CONDA_DEFAULT_ENV(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" "{env_dirs[0]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals( stdout, u'{env_dirs[0]}'.format(envs=envs, env_dirs=gen_test_env_paths(envs, shell)), stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{cmd_path}activate" "{env_dirs[1]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals( stdout, u'{env_dirs[1]}'.format(env_dirs=gen_test_env_paths(envs, shell)), stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[2]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {nul} {source} "{syspath}{cmd_path}activate" "{env_dirs[2]}" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals( stdout, '{env_dirs[0]}'.format(env_dirs=gen_test_env_paths(envs, shell)), stderr) commands = (shell_vars['command_setup'] + """ {source} {syspath}{cmd_path}deactivate {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" "{env_dirs[0]}" {nul} {source} "{env_dirs[0]}{cmd_path}deactivate" {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" two args {printdefaultenv} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" root {nul} {printdefaultenv} """).format(envs=envs, **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, u"%s" % sys.prefix, stderr) commands = (shell_vars['command_setup'] + """ {source} "{syspath}{cmd_path}activate" root {nul} {source} "{env_dirs[0]}{cmd_path}deactivate" {nul} {printdefaultenv} """).format(envs=envs, env_dirs=gen_test_env_paths(envs, shell), **shell_vars) stdout, stderr = run_in(commands, shell) assert_equals(stdout, '', stderr)