def parse_from_yaml(cls, source: Union[str, Path, IO]): "Parse from a path, url, path-like or file-like" with load_from_source(source) as (path, file): data = safe_load(file) return cls.parse_obj(data, path).__root__
def test_load_from_path_string(self): import cumulusci p = Path(cumulusci.__file__).parent / "cumulusci.yml" with load_from_source(str(p)) as (filename, data): assert "tasks:" in data.read()
def _extract_names(source): with load_from_source(source) as (name, data): names = re.findall(r"[^\w_]([\w_]+__c)[^\w_]", data.read()) return set(names)
def test_load_from_url(self): html = "<!DOCTYPE HTML ..." responses.add("GET", "http://www.salesforce.com", body=html) with load_from_source("http://www.salesforce.com") as (filename, data): assert data.read() == html
def test_writable_file_throws(self): with temporary_dir(): with open("writable", "wt") as t: with pytest.raises(UnsupportedOperation): with load_from_source(t) as (filename, data): pass
def test_binary_becomes_string(self): with load_from_source(BytesIO(b"foo")) as (path, file): data = file.read() assert isinstance(data, str) assert data == "foo"
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_load_from_open_file(self): p = Path(cumulusci.__file__).parent / "cumulusci.yml" with open(p) as f: with load_from_source(f) as (filename, data): assert "tasks:" in data.read() assert str(p) == filename