def test_uncpushd_push_to_same_share(xession, shares_setup): if shares_setup is None: return xession.env = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xession.env["PWD"].casefold() dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 2 dirstack.popd([]) assert os.path.isdir( TEMP_DRIVE[0] + "\\" ), "Temp drive not unmapped till last reference removed" dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def test_uncpushd_push_to_same_share(xonsh_builtins, shares_setup): if shares_setup is None: return xonsh_builtins.__xonsh__.env = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh__.env["PWD"].casefold() dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 2 dirstack.popd([]) assert os.path.isdir( TEMP_DRIVE[0] + "\\" ), "Temp drive not unmapped till last reference removed" dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def venvs(venv_home, create_venv): """Create virtualenv with names venv0, venv1""" from xonsh.dirstack import popd, pushd pushd([str(venv_home)]) yield [create_venv(f"venv{idx}") for idx in range(2)] popd([])
def test_uncpushd_push_to_same_share(xonsh_builtins): xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 2 dirstack.popd([]) assert os.path.isdir(TEMP_DRIVE[0] + '\\'), "Temp drived not unmapped till last reference removed" dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def test_autovox(xession, tmpdir, vox, a_venv, load_xontrib, registered): """ Tests that autovox works """ from xonsh.dirstack import pushd, popd # Makes sure that event handlers are registered load_xontrib("autovox") env_name = a_venv.basename env_path = str(a_venv) # init properly assert vox.parser def policy(path, **_): if str(path) == env_path: return env_name if registered: xession.builtins.events.autovox_policy(policy) pushd([env_path]) value = env_name if registered else None assert vox.vox.active() == value popd([])
def test_uncpushd_push_to_same_share(xonsh_builtins, shares_setup): if shares_setup is None: return xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 2 dirstack.popd([]) assert os.path.isdir( TEMP_DRIVE[0] + '\\'), "Temp drive not unmapped till last reference removed" dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold( ), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def test_pushdpopd(xession): """Simple non-UNC push/pop to verify we didn't break nonUNC case.""" xession.env = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xession.env["PWD"].casefold() dirstack.pushd([HERE]) wd = os.getcwd() assert wd.casefold() == HERE.casefold() dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir"
def test_uncpushd_simple_push_pop(xonsh_builtins, shares_setup): xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == '\\' dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def test_pushdpopd(xonsh_builtins): """Simple non-UNC push/pop to verify we didn't break nonUNC case. """ xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([HERE]) wd = os.getcwd() assert wd.casefold() == HERE.casefold() dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir"
def test_uncpushd_simple_push_pop(xession, shares_setup): if shares_setup is None: return xession.env = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xession.env["PWD"].casefold() dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == TEMP_DRIVE[0] assert os.path.splitdrive(wd)[1].casefold() == "\\" dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold(), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def test_uncpushd_simple_push_pop(xonsh_builtins, shares_setup): xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) wd = os.getcwd() assert os.path.splitdrive(wd)[0].casefold() == 'z:' assert os.path.splitdrive(wd)[1].casefold() == '\\' dirstack.popd([]) assert owd.casefold() == os.getcwd().casefold( ), "popd returned cwd to expected dir" assert len(_unc_tempDrives) == 0
def venvs(venv_home): """create bin paths in the tmpdir""" from xonsh.dirstack import pushd, popd pushd([str(venv_home)]) paths = [] for idx in range(2): bin_path = venv_home / f"venv{idx}" / "bin" paths.append(bin_path) (bin_path / "python").write("", ensure=True) (bin_path / "python.exe").write("", ensure=True) for file in bin_path.listdir(): st = os.stat(str(file)) os.chmod(str(file), st.st_mode | stat.S_IEXEC) yield paths popd([])
def venvs(venv_home): """Create virtualenv with names venv0, venv1""" from xonsh.dirstack import pushd, popd pushd([str(venv_home)]) paths = [] for idx in range(2): env_path = venv_home / f"venv{idx}" bin_path = env_path / "bin" paths.append(env_path) (bin_path / "python").write("", ensure=True) (bin_path / "python.exe").write("", ensure=True) for file in bin_path.listdir(): st = os.stat(str(file)) os.chmod(str(file), st.st_mode | stat.S_IEXEC) yield paths popd([])
def test_uncpushd_push_other_push_same(xession, shares_setup): """push to a, then to b. verify drive letter is TEMP_DRIVE[2], skipping already used TEMP_DRIVE[1] Then push to a again. Pop (check b unmapped and a still mapped), pop, pop (check a is unmapped)""" if shares_setup is None: return xession.env.update(dict(CDPATH=PARENT, PWD=HERE)) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xession.env["PWD"].casefold() dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) assert os.getcwd().casefold() == TEMP_DRIVE[0] + "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r"\\localhost\uncpushd_test_PARENT"]) os.getcwd() assert os.getcwd().casefold() == TEMP_DRIVE[2] + "\\" assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 dirstack.pushd([r"\\localhost\uncpushd_test_HERE"]) assert os.getcwd().casefold() == TEMP_DRIVE[0] + "\\" assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 3 dirstack.popd([]) assert os.getcwd().casefold() == TEMP_DRIVE[2] + "\\" assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 assert os.path.isdir(TEMP_DRIVE[2] + "\\") assert os.path.isdir(TEMP_DRIVE[0] + "\\") dirstack.popd([]) assert os.getcwd().casefold() == TEMP_DRIVE[0] + "\\" assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 assert not os.path.isdir(TEMP_DRIVE[2] + "\\") assert os.path.isdir(TEMP_DRIVE[0] + "\\") dirstack.popd([]) assert os.getcwd().casefold() == owd.casefold() assert len(_unc_tempDrives) == 0 assert len(DIRSTACK) == 0 assert not os.path.isdir(TEMP_DRIVE[2] + "\\") assert not os.path.isdir(TEMP_DRIVE[0] + "\\")
def test_uncpushd_push_other_push_same(xonsh_builtins, shares_setup): """push to a, then to b. verify drive letter is TEMP_DRIVE[2], skipping already used TEMP_DRIVE[1] Then push to a again. Pop (check b unmapped and a still mapped), pop, pop (check a is unmapped)""" if shares_setup is None: return xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) assert os.getcwd().casefold() == TEMP_DRIVE[0] + '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r'\\localhost\uncpushd_test_PARENT']) wd = os.getcwd() assert os.getcwd().casefold() == TEMP_DRIVE[2] + '\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) assert os.getcwd().casefold() == TEMP_DRIVE[0] + '\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 3 dirstack.popd([]) assert os.getcwd().casefold() == TEMP_DRIVE[2] + '\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 assert os.path.isdir(TEMP_DRIVE[2] + '\\') assert os.path.isdir(TEMP_DRIVE[0] + '\\') dirstack.popd([]) assert os.getcwd().casefold() == TEMP_DRIVE[0] + '\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 assert not os.path.isdir(TEMP_DRIVE[2] + '\\') assert os.path.isdir(TEMP_DRIVE[0] + '\\') dirstack.popd([]) assert os.getcwd().casefold() == owd.casefold() assert len(_unc_tempDrives) == 0 assert len(DIRSTACK) == 0 assert not os.path.isdir(TEMP_DRIVE[2] + '\\') assert not os.path.isdir(TEMP_DRIVE[0] + '\\')
def test_uncpushd_push_other_push_same(xonsh_builtins): """push to a, then to b. verify is w:, skipping already used y: Then push to a again. Pop (check b unmapped and a still mapped), pop, pop (check a is unmapped)""" xonsh_builtins.__xonsh_env__ = Env(CDPATH=PARENT, PWD=HERE) dirstack.cd([PARENT]) owd = os.getcwd() assert owd.casefold() == xonsh_builtins.__xonsh_env__['PWD'].casefold() dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) assert os.getcwd().casefold() == 'z:\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 dirstack.pushd([r'\\localhost\uncpushd_test_PARENT']) wd = os.getcwd() assert os.getcwd().casefold() == 'x:\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 dirstack.pushd([r'\\localhost\uncpushd_test_HERE']) assert os.getcwd().casefold() == 'z:\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 3 dirstack.popd([]) assert os.getcwd().casefold() == 'x:\\' assert len(_unc_tempDrives) == 2 assert len(DIRSTACK) == 2 assert os.path.isdir('x:\\') assert os.path.isdir('z:\\') dirstack.popd([]) assert os.getcwd().casefold() == 'z:\\' assert len(_unc_tempDrives) == 1 assert len(DIRSTACK) == 1 assert not os.path.isdir('x:\\') assert os.path.isdir('z:\\') dirstack.popd([]) assert os.getcwd().casefold() == owd.casefold() assert len(_unc_tempDrives) == 0 assert len(DIRSTACK) == 0 assert not os.path.isdir('x:\\') assert not os.path.isdir('z:\\')