def test_default_base_dir(monkeypatch): def set_pwd(p): if p is None: monkeypatch.delenv('PWD') else: monkeypatch.setenv('PWD', str(p)) cwd = Path('.').resolve() # Default base dir (once resolved) will never be different from cwd assert default_base_dir().resolve() == cwd # should work when PWD is not set set_pwd(None) assert 'PWD' not in os.environ assert default_base_dir() == cwd # should work when PWD is not absolute path set_pwd('this/is/not/a/valid/path') assert default_base_dir() == cwd # should be cwd when PWD points to some other dir set_pwd(cwd / 'deeper') assert default_base_dir() == cwd set_pwd(cwd.parent) assert default_base_dir() == cwd # PWD == cwd set_pwd(cwd) assert default_base_dir() == cwd
def test_default_base_dir(): def set_pwd(p): os.environ['PWD'] = str(p) pwd_backup = os.environ.get('PWD', None) cwd = Path('.').resolve() # Default base dir (once resolved) will never be different from cwd assert default_base_dir().resolve() == cwd # should work when PWD is not set os.environ.pop('PWD', None) assert 'PWD' not in os.environ assert default_base_dir() == cwd # should work when PWD is not absolute path set_pwd('this/is/not/a/valid/path') assert default_base_dir() == cwd # should be cwd when PWD points to some other dir set_pwd(cwd / 'deeper') assert default_base_dir() == cwd set_pwd(cwd.parent) assert default_base_dir() == cwd # PWD == cwd set_pwd(cwd) assert default_base_dir() == cwd # TODO: # - create symlink to current directory in temp # - set PWD to that link # - make sure that returned path is the same as symlink and different from cwd # restore environment (should probably do it even test fails, eh) if pwd_backup: set_pwd(pwd_backup)