def _arcp2file(self, uri): parsed = arcp.parse_arcp(uri) # arcp URIs, ensure they are local to our RO self.assertEquals(parsed.uuid, arcp.parse_arcp(self.find_arcp()).uuid) path = parsed.path[1:] # Strip first / # Convert to local path, in case it uses \ on Windows lpath = provenance._convert_path(path, posixpath, os.path) return os.path.join(self.folder, lpath)
def _arcp2file(base_path, uri): parsed = arcp.parse_arcp(uri) # arcp URIs, ensure they are local to our RO assert parsed.uuid == arcp.parse_arcp(find_arcp(base_path)).uuid,\ 'arcp URI must be local to the research object' path = parsed.path[1:] # Strip first / # Convert to local path, in case it uses \ on Windows lpath = provenance._convert_path(path, posixpath, os.path) return os.path.join(base_path, lpath)
def _arcp2file(base_path, uri): parsed = arcp.parse_arcp(uri) # arcp URIs, ensure they are local to our RO assert parsed.uuid == arcp.parse_arcp(find_arcp(base_path)).uuid,\ 'arcp URI must be local to the research object' path = parsed.path[1:] # Strip first / # Convert to local path, in case it uses \ on Windows lpath = provenance._convert_path(path, posixpath, os.path) return os.path.join(base_path, lpath)
def check_ro(self): manifest_file = os.path.join(self.folder, "metadata", "manifest.json") self.assertTrue(os.path.isfile(manifest_file), "Can't find " + manifest_file) arcp_root = self.find_arcp() base = urllib.parse.urljoin(arcp_root, "metadata/manifest.json") g = Graph() with open(manifest_file, "rb") as f: # Note: This will use https://w3id.org/bundle/context g.parse(file=f, format="json-ld", publicID=base) print("Parsed manifest:\n\n") g.serialize(sys.stdout, format="nt") ro = None for ro in g.subjects(ORE.isDescribedBy, URIRef(base)): break self.assertTrue(ro, "Can't find RO with ore:isDescribedBy") profile = None for dc in g.objects(ro, DCTERMS.conformsTo): profile = dc break self.assertTrue(profile, "Can't find profile with dct:conformsTo") self.assertEquals(profile, URIRef("https://w3id.org/cwl/prov/0.3.0"), "Unexpected cwlprov version " + profile) paths = [] externals = [] for aggregate in g.objects(ro, ORE.aggregates): print(aggregate) if not arcp.is_arcp_uri(aggregate): externals.append(aggregate) # Won't check external URIs existence here # TODO: Check they are not relative! continue # arcp URIs - assume they are local to our RO path = arcp.parse_arcp(aggregate).path[1:] # Strip first / paths.append(path) # Convert to local path, in case it uses \ on Windows lpath = provenance._convert_path(path, posixpath, os.path) lfile = os.path.join(self.folder, lpath) self.assertTrue(os.path.isfile(lfile), "Can't find aggregated " + lfile) self.assertTrue(paths, "Didn't find any arcp aggregates") self.assertTrue(externals, "Didn't find any data URIs") for ext in ["provn", "xml", "json", "jsonld", "nt", "ttl"]: f = "metadata/provenance/primary.cwlprov.%s" % ext self.assertTrue(f in paths, "provenance file missing " + f) for f in ["workflow/primary-job.json", "workflow/packed.cwl"]: self.assertTrue(f in paths, "workflow file missing " + f)
def test_failing_path_conversion(path, from_type, to_type): with pytest.raises(ValueError): provenance._convert_path(path, from_type, to_type)
def test_path_conversion(path, expected, from_type, to_type): assert provenance._convert_path(path, from_type, to_type) == expected
def test_nt_to_posix_absolute_fails(self): with self.assertRaises(ValueError): provenance._convert_path(r"D:\absolute\path", ntpath, posixpath)
def test_posix_to_nt_absolute_fails(self): with self.assertRaises(ValueError): provenance._convert_path("/absolute/path", posixpath, ntpath)
def test_nt_to_nt(self): self.assertEquals(r"a\b\c", provenance._convert_path(r"a\b\c", ntpath, ntpath))
def test_posix_to_posix(self): self.assertEquals("a/b/c", provenance._convert_path("a/b/c", posixpath, posixpath))
def test_posix_to_nt(self): self.assertEquals(r"a\b\c", provenance._convert_path("a/b/c", posixpath, ntpath))
def test_failing_path_conversion(path, from_type, to_type): with pytest.raises(ValueError): provenance._convert_path(path, from_type, to_type)
def test_path_conversion(path, expected, from_type, to_type): assert provenance._convert_path(path, from_type, to_type) == expected