def compare_files(file_a, file_b): size_a = os.path.getsize(file_a) size_b = os.path.getsize(file_b) print file_a, file_b if size_a != size_b: raise ComparisonError("%s is not the same size as %s" % (file_a, file_b)) BUFFER_SIZE = 8196 offset = 0 with open(file_a) as f_a: with open(file_b) as f_b: for chunk_a, chunk_b in izip( imap(lambda i: f_a.read(BUFFER_SIZE), xrange(size_a // BUFFER_SIZE + 1)), imap(lambda i: f_b.read(BUFFER_SIZE), xrange(size_b // BUFFER_SIZE + 1))): chunk_size = len(chunk_a) if chunk_a != chunk_b: for i in xrange(chunk_size): if chunk_a[i] != chunk_b[i]: raise ComparisonError( "%s differs from %s at offset %d" % (file_a, file_b, offset + i)) offset += chunk_size
def _compare_tolerance(value_a, value_b): if abs(value_a - value_b) > tolerance: raise ComparisonError("%s is not %s (tolerance: %s)" % ( value_a, value_b, tolerance ))
def _compare_yuv_output(file_a, file_b): size_a = os.path.getsize(file_a) size_b = os.path.getsize(file_b) if size_a != size_b: raise ComparisonError("%s is not the same size as %s" % (file_a, file_b)) BUFFER_SIZE = 8196 offset = 0 with open(file_a) as f_a: with open(file_b) as f_b: for chunk_a, chunk_b in izip( imap(lambda i: f_a.read(BUFFER_SIZE), xrange(size_a // BUFFER_SIZE + 1)), imap(lambda i: f_b.read(BUFFER_SIZE), xrange(size_b // BUFFER_SIZE + 1))): chunk_size = len(chunk_a) if chunk_a != chunk_b: for i in xrange(chunk_size): if chunk_a[i] != chunk_b[i]: # calculate the macroblock, plane and frame from the offset offs = offset + i y_plane_area = width * height u_plane_area = y_plane_area + y_plane_area * 0.25 v_plane_area = u_plane_area + y_plane_area * 0.25 pixel = offs % v_plane_area frame = offs // v_plane_area if pixel < y_plane_area: plane = "Y" pixel_x = pixel % width pixel_y = pixel // width macroblock = (ceil(pixel_x / 16.0), ceil(pixel_y / 16.0)) elif pixel < u_plane_area: plane = "U" pixel -= y_plane_area pixel_x = pixel % width pixel_y = pixel // width macroblock = (ceil(pixel_x / 8.0), ceil(pixel_y / 8.0)) else: plane = "V" pixel -= u_plane_area pixel_x = pixel % width pixel_y = pixel // width macroblock = (ceil(pixel_x / 8.0), ceil(pixel_y / 8.0)) macroblock = tuple( [int(x) for x in macroblock]) raise ComparisonError("%s differs from %s at frame %d, " \ "macroblock %s on the %s plane (offset %d)" % ( file_a, file_b, frame, macroblock, plane, offs) ) offset += chunk_size
def compare_direct(value_a, value_b): if value_a != value_b: raise ComparisonError("%s is not %s" % (value_a, value_b))