def test_chdir(self): def check_special_envvar(): if sys.platform != 'win32': return pwd = os.getcwd() import ctypes buf = ctypes.create_string_buffer(1000) len = ctypes.windll.kernel32.GetEnvironmentVariableA( '=%c:' % pwd[0], buf, 1000) if (len == 0) and "WINGDB_PYTHON" in os.environ: # the ctypes call seems not to work in the Wing debugger return assert str(buf.value).lower() == pwd.lower() # ctypes returns the drive letter in uppercase, # os.getcwd does not, # but there may be uppercase in os.getcwd path pwd = os.getcwd() try: check_special_envvar() rposix.chdir('..') assert os.getcwd() == os.path.dirname(pwd) check_special_envvar() finally: os.chdir(pwd)
def get_valid_cwd(): """ We check if the current working directory is valid or not. Typically happens when you checkout a different branch on git that doesn't have this directory. We return the original cwd because the shell still considers that to be the working directory, so returning our guess will confuse people """ cwd = os.environ[_as_bytes('PWD')] parts = cwd.split(os.sep) up = cwd while parts and not os.path.exists(up): parts.pop() up = os.sep.join(parts) chdir(up) return cwd
def test_chdir(self): def check_special_envvar(): if sys.platform != 'win32': return pwd = os.getcwd() import ctypes buf = ctypes.create_string_buffer(1000) len = ctypes.windll.kernel32.GetEnvironmentVariableA('=%c:' % pwd[0], buf, 1000) if (len == 0) and "WINGDB_PYTHON" in os.environ: # the ctypes call seems not to work in the Wing debugger return assert str(buf.value).lower() == pwd.lower() # ctypes returns the drive letter in uppercase, # os.getcwd does not, # but there may be uppercase in os.getcwd path pwd = os.getcwd() try: check_special_envvar() rposix.chdir('..') assert os.getcwd() == os.path.dirname(pwd) check_special_envvar() finally: os.chdir(pwd)
def f(): rposix.mkdir(self.path, 0777) rposix.chdir(self.path)