Exemple #1
0
def DistanceTest(tester, leftFile, rightFile, diffFile, htmlFile, markParagraphs):
    """ General distance test function """
    options = OOO()
    SourceFiles.Clear()
    left = XmlRfcParser(leftFile, quiet=True, cache_path=None, no_network=True). \
        parse(strip_cdata=False, remove_comments=False)
    left = BuildDiffTree(left.tree, options)
    if markParagraphs:
        left = AddParagraphs(left)
    SourceFiles.LeftDone()
    right = XmlRfcParser(rightFile, quiet=True, cache_path=None, no_network=True). \
        parse(strip_cdata=False, remove_comments=False)
    right = BuildDiffTree(right.tree, options)
    if markParagraphs:
        right = AddParagraphs(right)

    editSet = distance(left, right, DiffRoot.get_children,
                       DiffRoot.InsertCost, DiffRoot.DeleteCost, DiffRoot.UpdateCost)
    with open(diffFile, 'r') as f:
        lines2 = f.readlines()

    d = difflib.Differ()

    # check that the edit set is the same
    lines2 = [line.strip() for line in lines2]
    lines1 = [edit.toString() for edit in editSet]
    result = list(d.compare(lines1, lines2))

    hasError = False
    for ll in result:
        if ll[0:2] == '+ ' or ll[0:2] == '- ':
            hasError = True
            break
    if hasError:
        print("\n".join(result))
        tester.assertFalse(hasError, "edit map differs")

    # check that the HTML output is the same
    left.applyEdits(editSet)
    x = left.ToString()
    x = x.splitlines()
    x = [line.rstrip() for line in x]
    with open(htmlFile, 'rb') as f:
        lines2 = f.read().decode('utf-8').splitlines()
    lines2 = [line.rstrip() for line in lines2]

    result = list(d.compare(x, lines2))

    hasError = False
    for l in result:
        if l[0:2] == '+ ' or l[0:2] == '- ':
            hasError = True
            break
    if hasError:
        print("\n".join(result))
        tester.assertFalse(hasError, "html differs")
Exemple #2
0
def DistanceTest(tester, leftFile, rightFile, diffFile, htmlFile):
    """ General distance test function """
    options = OOO()
    diffCount = 0
    left = XmlRfcParser(leftFile, quiet=True, cache_path=None,
                        no_network=True).parse()
    left = BuildDiffTree(left.tree, options)
    right = XmlRfcParser(rightFile,
                         quiet=True,
                         cache_path=None,
                         no_network=True).parse()
    right = BuildDiffTree(right.tree, options)

    editSet = distance(left, right, DiffRoot.get_children, DiffRoot.InsertCost,
                       DiffRoot.DeleteCost, DiffRoot.UpdateCost)
    with open(diffFile, 'r') as f:
        lines2 = f.readlines()

    d = difflib.Differ()

    # check that the edit set is the same
    lines2 = [line.strip() for line in lines2]
    lines1 = [edit.toString() for edit in editSet]
    result = list(d.compare(lines1, lines2))

    hasError = False
    for ll in result:
        if ll[0:2] == '+ ' or ll[0:2] == '- ':
            hasError = True
            break
    if hasError:
        print("\n".join(result))
        tester.assertFalse(hasError, "edit map differs")

    # check that the HTML output is the same
    left.applyEdits(editSet)
    x = left.ToString()
    x = x.splitlines()
    with open(htmlFile, 'r') as f:
        lines2 = f.readlines()
    lines2 = [line.strip() for line in lines2]

    result = list(d.compare(x, lines2))

    hasError = False
    for l in result:
        if l[0:2] == '+ ' or l[0:2] == '- ':
            hasError = True
            break
    if hasError:
        print("\n".join(result))
        tester.assertFalse(hasError, "html differs")
Exemple #3
0
def DistanceTest(leftFile, rightFile, options):
    try:
        left = XmlRfcParser(leftFile, quiet=True).parse()
        left = BuildDiffTree(left.tree, options)
        left = AddParagraphs(left)
        right = XmlRfcParser(rightFile, quiet=True).parse()
        right = BuildDiffTree(right.tree, options)
        right = AddParagraphs(right)

        editSet = distance(left, right, DiffRoot.get_children,
                           DiffRoot.InsertCost, DiffRoot.DeleteCost,
                           DiffRoot.UpdateCost)

        c = left.applyEdits(editSet)

        if c > 0:
            log.error("Fail applying edits for '{0}' and '{1}', # edits = {2}".
                      format(leftFile, rightFile, c))
    except Exception as e:
        log.exception(
            "Fail applying edits for '{0}' and '{1}'".format(
                leftFile, rightFile), e)