Пример #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_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')
Пример #3
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))
Пример #4
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()))
Пример #5
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()))
Пример #6
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))
Пример #7
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)
Пример #8
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)
Пример #9
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)
Пример #10
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')
Пример #11
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())
Пример #12
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')
Пример #13
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')
Пример #14
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)
Пример #15
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())
Пример #16
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)
Пример #17
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)
Пример #18
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())
Пример #19
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')
Пример #20
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())
Пример #21
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)
Пример #22
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)
Пример #23
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'])
Пример #24
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'])