示例#1
0
 def test_Entity_has_id(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     self.assertHasAttributeWithValue(entity, 'id', 'niprov:file0')
示例#2
0
 def test_serialize_file_entity_has_fileSize_prop(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['size'] = 56789
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     self.assertOneChildWithTagAndText(entity, 'nfo:fileSize', str(56789))
示例#3
0
 def test_serialize_file_entity_has_fileUrl_prop(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     self.assertOneChildWithTagAndText(entity, 'nfo:fileUrl', 
         str(aFile.location.toUrl()))
示例#4
0
 def test_serialize_item_returns_string_with_xml_header(self):
     prolog = '<?xml version="1.0" encoding="UTF-8"?>'
     doc = '<prov:document'
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     out = form.serializeSingle(self.aFile())
     self.assertIn(prolog, out)
     self.assertIn(doc, out)
示例#5
0
 def test_file_with_transformation_has_activity_w_corresponding_id(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['transformation'] = 'enchantment'
     doc = self.parseDoc(form.serializeSingle(aFile))
     ent, entId = self.assertOneChildWithTagThatHasAnId(doc, 'prov:entity')
     act, actId = self.assertOneChildWithTagThatHasAnId(doc, 'prov:activity')
     self.assertEqual(entId+'.xform', actId)
示例#6
0
 def test_FileHash_id_follows_sensible_format(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['hash'] = 'abraca777'
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     fileId = entity.attributes['id'].value
     self.assertOneChildWithTagAndText(entity, 'nfo:hasHash', fileId+'.hash')
示例#7
0
 def test_serialize_file_entity_has_fileLastModified_prop(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['created'] = datetime.datetime.now()
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     self.assertOneChildWithTagAndText(entity, 'nfo:fileLastModified', 
         aFile.provenance['created'].isoformat())
示例#8
0
 def test_file_with_transformation_has_activity_w_label(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['transformation'] = 'enchantment'
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     activity = doc.getElementsByTagName("prov:activity")[0]
     self.assertOneChildWithTagAndText(activity, 'dct:title', 'enchantment')
示例#9
0
 def test_has_namespaces(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     out = form.serializeSingle(self.aFile())
     prov = 'http://www.w3.org/ns/prov#'
     self.assertNamespaceDefined('prov', prov, out)
     nfo = 'http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#'
     self.assertNamespaceDefined('nfo', nfo, out)
     dct = 'http://purl.org/dc/terms/'
     self.assertNamespaceDefined('dct', dct, out)
示例#10
0
 def test_file_with_transformation_has_wasGeneratedBy_with_time(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['transformation'] = 'enchantment'
     aFile.provenance['created'] = datetime.datetime.now()
     doc = self.parseDoc(form.serializeSingle(aFile))
     wasGen = self.assertOneChildWithTagName(doc, "prov:wasGeneratedBy")
     self.assertOneChildWithTagAndText(wasGen, 'prov:time', 
         aFile.provenance['created'].isoformat())
示例#11
0
 def test_file_with_transformation_has_wasGeneratedBy_element(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['transformation'] = 'enchantment'
     doc = self.parseDoc(form.serializeSingle(aFile))
     ent, entId = self.assertOneChildWithTagThatHasAnId(doc, 'prov:entity')
     act, actId = self.assertOneChildWithTagThatHasAnId(doc, 'prov:activity')
     wasGen = self.assertOneChildWithTagName(doc, "prov:wasGeneratedBy")
     refEnt = self.assertOneChildWithTagName(wasGen, "prov:entity")
     refAct = self.assertOneChildWithTagName(wasGen, "prov:activity")
     self.assertHasAttributeWithValue(refEnt, 'prov:ref', entId)
     self.assertHasAttributeWithValue(refAct, 'prov:ref', actId)
示例#12
0
 def test_serialize_file_entity_has_hash(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     aFile = self.aFile()
     aFile.provenance['hash'] = 'abraca777'
     doc = self.parseDoc(form.serializeSingle(aFile))
     entity = doc.getElementsByTagName("prov:entity")[0]
     hasHash = self.assertOneChildWithTagName(entity, 'nfo:hasHash')
     hashref = self.getElementContent(hasHash)
     allHashes = doc.getElementsByTagName("nfo:FileHash")
     hashesWithId = [e for e in allHashes if e.attributes['id'].value==hashref]
     self.assertEqual(1, len(hashesWithId))
     hashEl = hashesWithId[0]
     self.assertOneChildWithTagAndText(hashEl, 'nfo:hashAlgorithm', 'MD5')
     self.assertOneChildWithTagAndText(hashEl, 'nfo:hashValue', 
         aFile.provenance['hash'])
示例#13
0
 def test_serialize_list_creates_entity_for_each_file(self):
     from niprov.formatxml import XmlFormat
     form = XmlFormat(self.dependencies)
     out = form.serializeList([self.aFile(), self.aFile(), self.aFile()])
     self.assertEqual(3, out.count('<prov:entity'))