def test_resource_exists_relpath(self): relpath = os.path.relpath(self.file) with open_fs_resource(relpath) as resource: assert resource.exists() assert (str( Path(resource.getsyspath()).relative_to( Path(".").absolute())) == relpath)
def test_copy_to(self): abspath = os.path.abspath(self.file) with open_fs_resource(abspath) as f: f.copy_to(abspath + ".bak") assert Path(abspath + ".bak").exists() f.copy_to(Path(abspath + ".bak2")) assert Path(abspath + ".bak2").exists() f.copy_to(FSResource.new(abspath + ".bak3")) assert Path(abspath + ".bak3").exists()
def _run_task(self): restore_path = self.options.get("restore_file") if restore_path: restore_file = open_fs_resource(restore_path) else: restore_file = self._default_restore_resource() with restore_file as f: self._do_trigger_handlers(f)
def test_open_for_write(self): abspath = Path(self.tempdir.name) / "blah" with open_fs_resource(abspath) as fs: fs.mkdir() newfile = fs / "newfile" with newfile.open("w") as f: f.write("xyzzy") with newfile.open("r") as f: assert f.read() == "xyzzy"
def test_mkdir_rmdir(self): abspath = Path(self.tempdir.name) / "doesnotexist" assert not abspath.exists() with open_fs_resource(abspath) as f: f.mkdir() assert abspath.exists() f.mkdir(exist_ok=True) f.rmdir() abspath = abspath / "foo" / "bar" / "baz" assert not abspath.exists() with open_fs_resource(abspath) as f: f.mkdir(parents=True) f.mkdir(parents=True, exist_ok=True) f.mkdir(parents=False, exist_ok=True) assert abspath.exists() with pytest.raises(errors.DirectoryExists): f.mkdir(parents=False, exist_ok=False) f.rmdir()
def get_orginfo_cache_dir(self, cachename): "Returns a context managed FSResource object" assert self.keychain, "Keychain should be set" if self.global_org: cache_dir = self.keychain.global_config_dir else: cache_dir = self.keychain.cache_dir uniqifier = self.get_domain() + "__" + str(self.username).replace( "@", "__") cache_dir = cache_dir / "orginfo" / uniqifier / cachename cache_dir.mkdir(parents=True, exist_ok=True) return open_fs_resource(cache_dir)
def test_resource_does_not_exist(self): abspath = os.path.abspath(self.file) with open_fs_resource(abspath + "xyzzy") as resource: assert not resource.exists() assert abspath + "xyzzy" in resource
def test_resource_exists_abspath(self): abspath = os.path.abspath(self.file) with open_fs_resource(abspath) as resource: assert resource.exists() assert str(resource.getsyspath()) == abspath
def test_load_from_fs_resource(self): p = Path(cumulusci.__file__).parent / "cumulusci.yml" with open_fs_resource(p) as p2: with load_from_source(p2) as (filename, data): assert "tasks:" in data.read()
def test_resource_exists_url_relpath(self): relpath = os.path.relpath(self.file) url = f"file://{relpath}" with open_fs_resource(url) as resource: assert resource.exists() assert relpath in resource
def test_windows_path(self): abspath = "c:\\foo\\bar" with open_fs_resource(abspath) as f: if sys.platform == "win32": assert "c:\\foo\\bar" == str(f.getsyspath()), str( f.getsyspath())
def test_load_from_file_system(self): abspath = os.path.abspath(self.file) fs = open_fs("/") with open_fs_resource(abspath, fs) as f: assert abspath in str(f)
def test_clone_fsresource(self): abspath = os.path.abspath(self.file) with open_fs_resource(Path(abspath)) as resource: with open_fs_resource(resource) as resource2: assert abspath in str(resource2)
def test_join_paths(self): parent = Path(self.file).parent with open_fs_resource(parent) as resource: this_file = resource / self.file.name assert this_file.exists()
def test_resource_as_str(self): abspath = os.path.abspath(self.file) with open_fs_resource(Path(abspath)) as resource: assert "file://" in repr(resource)
def test_resource_exists_pathlib_abspath(self): abspath = os.path.abspath(self.file) with open_fs_resource(Path(abspath)) as resource: assert resource.exists() assert abspath in resource
def test_resource_test_resource_doesnt_exist_pathlib_relpath(self): relpath = os.path.relpath(self.file) with open_fs_resource(Path(relpath + "xyzzy")) as resource: assert not resource.exists() assert relpath + "xyzzy" in resource
def open_cache(self, cache_name): "A context managed PyFilesystem-based cache which could theoretically be on any filesystem." with open_fs_resource(self.cache_dir) as cache_dir: cache = cache_dir / cache_name cache.mkdir(exist_ok=True) yield cache