def encode(data_path, iframe_every=0):
    diffed = diffe.encode(data_path, iframe_every)
    ext = os.path.splitext(diffed)[1]
    bad_path = gz.encode(diffed)
    parts = os.path.splitext(bad_path)
    path = parts[0] + ext + parts[1]
    os.rename(bad_path, path)
    return path
def test_diffe_from_first():
    diffed_file = diffe.encode(DATA_PATH, iframe_every=0)
    new_files.append(diffed_file)
    with open(diffed_file, 'r') as fd:
        files = fd.read()
        files = files.split(utilities.RECORD_SEPARATOR)
        restored_text = files[0]
        for f in files[1:]:
            restored_text += utilities.RECORD_SEPARATOR
            restored_text += diff_patch(files[0], f)
        assert_equal(restored_text, orig_text)
def test_diffe_from_previous():
    diffed_file = diffe.encode(DATA_PATH, iframe_every=1)
    new_files.append(diffed_file)
    with open(diffed_file, 'r') as fd:
        files = fd.read()
        files = files.split(utilities.RECORD_SEPARATOR)
        restored_text = files[0]
        previous = restored_text
        for f in files[1:]:
            restored_text += utilities.RECORD_SEPARATOR
            current = diff_patch(previous, f)
            restored_text += current
            previous = current
        assert_equal(restored_text, orig_text)
def tedst_diff_iframe_every_three():
    diffed_file = diffe.encode(DATA_PATH, iframe_every=3)
    new_files.append(diffed_file)
    with open(diffed_file, 'r') as fd:
        files = fd.read()
        files = files.split(utilities.RECORD_SEPARATOR)
        restored_text = files[0]
        restored_text += utilities.RECORD_SEPARATOR
        restored_text += diff_patch(files[0], files[1])
        restored_text += utilities.RECORD_SEPARATOR
        restored_text += diff_patch(files[0], files[2])
        for i in xrange(3, len(files), 3):
            restored_text += utilities.RECORD_SEPARATOR
            restored_text += files[i]
            try:
                text = diff_patch(files[i], files[i+1])
                restored_text += utilities.RECORD_SEPARATOR
                restored_text += text
                text = diff_patch(files[i], files[i+2])
                restored_text += utilities.RECORD_SEPARATOR
                restored_text += text
            except IndexError:
                pass
        assert_equal(restored_text, orig_text)