Skip to content

Commit 761e91c

Browse files
committed
test for directories
1 parent 4382b80 commit 761e91c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cwltool/provenance.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,9 @@ def declare_artefact(self, value):
636636

637637
# FIXME: .listing might not be populated yet - hopefully
638638
# a later call to this method will sort that
639+
is_empty = True
639640
for f in value.get("listing", []):
641+
is_empty = False
640642
# Declare child-artifacts
641643
entity = self.declare_artefact(f)
642644
self.document.membership(coll, entity)
@@ -686,7 +688,7 @@ def declare_artefact(self, value):
686688
ore_doc.serialize(provenance_file, format="rdf", rdf_format="turtle")
687689
self.research_object.add_annotation(dir_id, [ore_doc_fn], ORE["isDescribedBy"].uri)
688690

689-
if not coll_attribs:
691+
if is_empty:
690692
# Empty directory
691693
coll.add_asserted_type(PROV["EmptyCollection"])
692694
coll.add_asserted_type(PROV["EmptyDictionary"])

tests/test_provenance.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,37 @@ def check_prov(self, nested=False, single_tool=False, directory=False):
361361
directories = set(g.subjects(RDF.type, RO.Folder))
362362
self.assertTrue(directories)
363363

364+
for d in directories:
365+
self.assertTrue((d,RDF.type,PROV.Dictionary) in g)
366+
self.assertTrue((d,RDF.type,PROV.Collection) in g)
367+
self.assertTrue((d,RDF.type,PROV.Entity) in g)
368+
369+
files = set()
370+
for entry in g.objects(d, PROV.hadDictionaryMember):
371+
self.assertTrue((entry,RDF.type,PROV.KeyEntityPair) in g)
372+
# We don't check what that filename is here
373+
self.assertTrue(set(g.objects(entry,PROV.pairKey)))
374+
375+
# RO:Folder aspect
376+
self.assertTrue(set(g.objects(entry,RO.entryName)))
377+
self.assertTrue((d,ORE.aggregates,entry) in g)
378+
self.assertTrue((entry,RDF.type,RO.FolderEntry) in g)
379+
self.assertTrue((entry,RDF.type,ORE.Proxy) in g)
380+
self.assertTrue((entry,ORE.proxyIn,d) in g)
381+
self.assertTrue((entry,ORE.proxyIn,d) in g)
382+
383+
# Which file?
384+
entities = set(g.objects(entry, PROV.pairEntity))
385+
self.assertTrue(entities)
386+
f = entities.pop()
387+
files.add(f)
388+
self.assertTrue((entry,ORE.proxyFor,f) in g)
389+
self.assertTrue((f,RDF.type,PROV.Entity) in g)
390+
391+
if not files:
392+
self.assertTrue((d,RDF.type,PROV.EmptyCollection) in g)
393+
self.assertTrue((d,RDF.type,PROV.EmptyDictionary) in g)
394+
364395

365396
class TestConvertPath(unittest.TestCase):
366397
def test_nt_to_posix(self):

0 commit comments

Comments
 (0)