def testMkv(self): """ Test the functionality of the ebmlite library by converting a known good MKV file (a derivative of EBML) back and forth, then compare the results. """ schemaFile = './ebmlite/schemata/matroska.xml' ebmlFile1 = './tests/video-1.mkv' ebmlFile2 = './tests/video-1-copy.mkv' xmlFile1 = './tests/video-1.xml' xmlFile2 = './tests/video-1-copy.xml' schema = core.loadSchema(schemaFile) # Start with toXml ebmlDoc1 = schema.load(ebmlFile1, headers=True) ebmlRoot = util.toXml(ebmlDoc1) xmlString1 = ET.tostring(ebmlRoot, encoding='UTF-8') # Save xml with open(xmlFile1, 'wt') as f: f.write(xmlString1.decode()) # Convert xml2ebml with open(ebmlFile2, 'wb') as out: util.xml2ebml(xmlFile1, out, schema) # write the second xml file ebmlDoc2 = schema.load(ebmlFile2, headers=True) mkvRoot2 = util.toXml(ebmlDoc2) xmlString2 = ET.tostring(mkvRoot2, encoding='UTF-8') # self.assertEqual(xmlString1, xmlString2, "xml strings aren't matching up") with open(xmlFile2, 'wt') as f: f.write(xmlString2.decode()) # Load back the XML files in order to compare the two xmlDoc1 = util.loadXml(xmlFile1, schema) xmlDoc2 = util.loadXml(xmlFile2, schema) # Compare each element from the XML xmlEls1 = [xmlDoc1] xmlEls2 = [xmlDoc2] while len(xmlEls1) > 0: self.assertEqual(xmlEls1[0], xmlEls2[0], 'Element ' + repr(xmlEls1[0]) + ' was not converted properly') for x in list(xmlEls1.pop(0).children.values()): if issubclass(x, core.Element): xmlEls1.append(x) for x in list(xmlEls2.pop(0).children.values()): if issubclass(x, core.Element): xmlEls2.append(x)
def testIde(self): """ Test the functionality of the ebmlite library by converting a known good IDE file (a derivative of EBML) back and forth, then compare the results. """ schemaFile = './ebmlite/schemata/mide_ide.xml' ebmlFile1 = './tests/SSX46714-doesnot.IDE' ebmlFile2 = './tests/SSX46714-new.IDE' xmlFile1 = './tests/ssx-1.xml' xmlFile2 = './tests/ssx-2.xml' schema = core.loadSchema(schemaFile) # Start with toXml ebmlDoc1 = schema.load(ebmlFile1, headers=True) ebmlRoot = util.toXml(ebmlDoc1) xmlString1 = ET.tostring(ebmlRoot, encoding='UTF-8') # Save xml with open(xmlFile1, 'wt') as f: f.write(xmlString1.replace('><', '>\r\n<')) # Convert xml2ebml with open(ebmlFile2, 'wb') as out: util.xml2ebml(xmlFile1, out, schema) # write the second xml file ebmlDoc2 = schema.load(ebmlFile2, headers=True) mkvRoot2 = util.toXml(ebmlDoc2) xmlString2 = ET.tostring(mkvRoot2, encoding='UTF-8') with open(xmlFile2, 'wt') as f: f.write(xmlString2.replace('><', '>\r\n<')) # Load back the XML files in order to compare the two xmlDoc1 = util.loadXml(xmlFile1, schema) xmlDoc2 = util.loadXml(xmlFile2, schema) # Compare each element from the XML xmlEls1 = [xmlDoc1] xmlEls2 = [xmlDoc2] while len(xmlEls1) > 0: self.assertEqual( xmlEls1[0], xmlEls2[0], 'Element ' + repr(xmlEls1[0]) + ' was not converted properly') for x in xmlEls1.pop(0).children.values(): if issubclass(x, core.Element): xmlEls1.append(x) for x in xmlEls2.pop(0).children.values(): if issubclass(x, core.Element): xmlEls2.append(x)