コード例 #1
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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))
コード例 #6
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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)
コード例 #7
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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()))
コード例 #8
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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()))
コード例 #9
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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')
コード例 #10
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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')
コード例 #11
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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)
コード例 #13
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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')
コード例 #14
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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())
コード例 #15
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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')
コード例 #16
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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())
コード例 #17
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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)
コード例 #19
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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())
コード例 #20
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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)
コード例 #21
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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'])
コード例 #25
0
ファイル: formatfactory.py プロジェクト: ktavabi/niprov
 def create(self, formatName):
     if formatName == 'json':
         return JsonFormat(self.dependencies)
     if formatName == 'xml':
         return XmlFormat(self.dependencies)
     if formatName == 'narrated':
         return NarratedFormat()
     if formatName == 'simple':
         return SimpleFormat()
     if formatName == 'dict':
         return DictFormat()
     if formatName == 'object':
         return ObjectFormat()
     if formatName == 'picture':
         return PictureCache(self.dependencies)
     raise ValueError('Unknown format: ' + str(formatName))
コード例 #26
0
ファイル: test_formatxml.py プロジェクト: ktavabi/niprov
 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'))
コード例 #27
0
ファイル: test_formatxml.py プロジェクト: ilogue/niprov
 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'))