def do_convert(self, filename=None): if filename is None and exists(self.output + '.nofilename'): output = self.output + '.nofilename' else: output = self.output orig = read_file_data(self.input) data = datastream(self.transform.name()) res_data = self.transform.convert(orig, data, filename=filename) self.assertTrue(IDataStream.providedBy(res_data)) got = res_data.getData() self.assertIsInstance(got, self.allowed_types) try: expected = read_file_data(self.output) except IOError: expected = '' import sys print('No output file found.', file=sys.stderr) print('File {0} created, check it !'.format(self.output), file=sys.stderr) with open(output, 'w') as fd: fd.write(got) self.assertTrue(0) if self.normalize is not None: got = self.normalize(got) expected = self.normalize(expected) # show the first character ord table for debugging got_start = got.strip()[:20] expected_start = expected.strip()[:20] msg = 'IN {0}({1}) expected:\n{2}\nbut got:\n{3}'.format( self.transform.name(), self.input, "%s %s" % (expected_start, str([ord(x) for x in expected_start])), "%s %s" % (got_start, str([ord(x) for x in got_start])), ) # compare md5 sum of the whole file content self.assertEqual( got_start, expected_start, msg, ) self.assertEqual( self.subobjects, len(res_data.getSubObjects()), '%s\n\n!=\n\n%s\n\nIN %s(%s)' % ( self.subobjects, len(res_data.getSubObjects()), self.transform.name(), self.input, ))
def do_convert(self, filename=None): if filename is None and exists(self.output + '.nofilename'): output = self.output + '.nofilename' else: output = self.output with open(self.input) as fp: orig = fp.read() data = datastream(self.transform.name()) res_data = self.transform.convert(orig, data, filename=filename) self.assert_(IDataStream.providedBy(res_data)) got = res_data.getData() try: output = open(output) except IOError: import sys print >> sys.stderr, 'No output file found.' print >> sys.stderr, 'File %s created, check it !' % self.output output = open(output, 'w') output.write(got) output.close() self.assert_(0) expected = output.read() if self.normalize is not None: expected = self.normalize(expected) got = self.normalize(got) output.close() got_start = got.strip()[:20] expected_start = expected.strip()[:20] msg = 'IN {0}({1}) expected:\n{2}\nbut got:\n{3}'.format( self.transform.name(), self.input, str([ord(x) for x in expected_start]), str([ord(x) for x in got_start]), ) self.assertEqual( got_start, expected_start, msg ) self.assertEqual( self.subobjects, len(res_data.getSubObjects()), '%s\n\n!=\n\n%s\n\nIN %s(%s)' % ( self.subobjects, len(res_data.getSubObjects()), self.transform.name(), self.input ) )
def do_convert(self, filename=None): if filename is None and exists(self.output + ".nofilename"): output = self.output + ".nofilename" else: output = self.output input = open(self.input) orig = input.read() input.close() data = datastream(self.transform.name()) res_data = self.transform.convert(orig, data, filename=filename) self.assert_(IDataStream.providedBy(res_data)) got = res_data.getData() try: output = open(output) except IOError: import sys print >> sys.stderr, "No output file found." print >> sys.stderr, "File %s created, check it !" % self.output output = open(output, "w") output.write(got) output.close() self.assert_(0) expected = output.read() if self.normalize is not None: expected = self.normalize(expected) got = self.normalize(got) output.close() got_start = got.strip()[:20] expected_start = expected.strip()[:20] self.assertEquals( got_start, expected_start, "[%s]\n\n!=\n\n[%s]\n\nIN %s(%s)" % (got_start, expected_start, self.transform.name(), self.input), ) self.assertEquals( self.subobjects, len(res_data.getSubObjects()), "%s\n\n!=\n\n%s\n\nIN %s(%s)" % (self.subobjects, len(res_data.getSubObjects()), self.transform.name(), self.input), )
def do_convert(self, filename=None): if filename is None and exists(self.output + '.nofilename'): output = self.output + '.nofilename' else: output = self.output input = open(self.input) orig = input.read() input.close() data = datastream(self.transform.name()) res_data = self.transform.convert(orig, data, filename=filename) self.assert_(IDataStream.providedBy(res_data)) got = res_data.getData() try: output = open(output) except IOError: import sys print >> sys.stderr, 'No output file found.' print >> sys.stderr, 'File %s created, check it !' % self.output output = open(output, 'w') output.write(got) output.close() self.assert_(0) expected = output.read() if self.normalize is not None: expected = self.normalize(expected) got = self.normalize(got) output.close() got_start = got.strip()[:30] expected_start = expected.strip()[:30] self.assertEquals( got_start, expected_start, '[%s]\n\n!=\n\n[%s]\n\nIN %s(%s)' % (got_start, expected_start, self.transform.name(), self.input)) self.assertEquals( self.subobjects, len(res_data.getSubObjects()), '%s\n\n!=\n\n%s\n\nIN %s(%s)' % (self.subobjects, len( res_data.getSubObjects()), self.transform.name(), self.input))
def _unwrap(self, data): """unwrap data from an icache""" if IDataStream.providedBy(data): data = data.getData() return data