예제 #1
0
def compare_xmls(observed, expected):
    formatter = formatting.DiffFormatter()
    # FYI: https://xmldiff.readthedocs.io/en/stable
    #
    # diff_options: A dictionary containing options that will be passed into the Differ(): F: A value between 0 and 1
    # that determines how similar two XML nodes must be to match as the same in both trees. Defaults to 0.5.
    #
    # A higher value requires a smaller difference between two nodes for them to match. Set the value high,
    # and you will see more nodes inserted and deleted instead of being updated. Set the value low, and you will get
    # more updates instead of inserts and deletes.
    #
    # uniqueattrs: A list of XML node attributes that will uniquely identify a node. See Unique Attributes for more
    # info.
    #
    # Defaults to ['{http://www.w3.org/XML/1998/namespace}id'].
    #
    # ratio_mode:
    #
    # The ratio_mode determines how accurately the similarity between two nodes is calculated. The choices are
    # 'accurate', 'fast' and 'faster'. Defaults to 'fast'.
    #
    # Using 'faster' often results in less optimal edits scripts, in other words, you will have more actions to
    # achieve the same result. Using 'accurate' will be significantly slower, especially if your nodes have long
    # texts or many attributes.
    diff = main.diff_files(observed,
                           expected,
                           diff_options={
                               'F': 0.5,
                               'ratio_mode': 'accurate',
                               'uniqueattrs': [('RuleEvaluation', 'Name')]
                           },
                           formatter=formatter)
    return diff
예제 #2
0
파일: type.py 프로젝트: yan-lang/ycc-grader
 def grade_single(self, stu_out, gold_out) -> BaseReport:
     formatter = formatting.DiffFormatter()
     diff = main.diff_files(stu_out,
                            gold_out,
                            formatter=formatter,
                            diff_options={'F': 0.5})
     return TypeCheckReport(os.path.basename(stu_out), diff)
예제 #3
0
def compare_trees(tree1, tree2):
    """Generates an xmldiff from two lxml trees."""
    opts = {'ratio_mode': 'accurate', 'F': 0.8}
    formatter = formatting.DiffFormatter(normalize=formatting.WS_BOTH,
                                         pretty_print=True)
    diff = diff_trees(tree1, tree2, diff_options=opts, formatter=formatter)

    return patch.DiffParser().parse(diff)
예제 #4
0
 def _expect_designspace(self, doc, expected_path):
     actual_path = self.write_to_tmp_path(doc, "generated.designspace")
     actual_diff = main.diff_files(
         actual_path, expected_path, formatter=formatting.DiffFormatter()
     )
     if len(actual_diff) != 0:
         expected_name = os.path.basename(expected_path)
         sys.stderr.write("%s discrepancies (per xmldiff):\n" % (expected_name))
         for line in actual_diff.split("\n"):
             sys.stderr.write("  %s" % (line))
         self.fail("*.designspace file is different from expected")
예제 #5
0
    def grade_single(self, stu_out, gold_out) -> BaseReport:
        formatter = formatting.DiffFormatter()
        diff_text = main.diff_files(stu_out, gold_out, formatter=formatter, diff_options={'F': 0.5})

        # Compute similarity

        # InsertNode, DeleteNode, MoveNode,
        # InsertAttrib, DeleteAttrib, RenameAttrib, UpdateAttrib,
        # UpdateTextIn, UpdateTextAfter

        diff = main.diff_files(stu_out, gold_out, diff_options={'F': 0.5})

        return ParserReport(os.path.basename(stu_out), diff_text, 0)
예제 #6
0
파일: __init__.py 프로젝트: tylere/pykml
def compare_xml(tree1, tree2):
    """Compare two XML trees."""
    tree_diff = main.diff_trees(
        left=tree1,
        right=tree2,
        formatter=formatting.DiffFormatter(pretty_print=True))
    if len(tree_diff) == 0:
        return True
    else:
        print('==== Start Differences ====')
        print(tree_diff)
        print('===== End Differences =====')
        return False
예제 #7
0
def test_designspace_generation_italic_same_family_name(tmpdir, ufo_module):
    ufo_Lt = ufo_module.Font()
    ufo_Lt.info.familyName = "CoolFoundry Examplary Serif"
    ufo_Lt.info.styleName = "Light Italic"
    ufo_Lt.info.openTypeOS2WeightClass = 300
    ufo_Lt.info.italicAngle = -11

    ufo_Rg = ufo_module.Font()
    ufo_Rg.info.familyName = "CoolFoundry Examplary Serif"
    ufo_Rg.info.styleName = "Regular Italic"
    ufo_Rg.info.openTypeOS2WeightClass = 400
    ufo_Rg.info.italicAngle = -11

    ufo_Md = ufo_module.Font()
    ufo_Md.info.familyName = "CoolFoundry Examplary Serif"
    ufo_Md.info.styleName = "Medium Italic"
    ufo_Md.info.openTypeOS2WeightClass = 500
    ufo_Md.info.italicAngle = -11

    ufo_Bd = ufo_module.Font()
    ufo_Bd.info.familyName = "CoolFoundry Examplary Serif"
    ufo_Bd.info.styleName = "Bold Italic"
    ufo_Bd.info.openTypeOS2WeightClass = 700
    ufo_Bd.info.italicAngle = -11

    ufo_ExBd = ufo_module.Font()
    ufo_ExBd.info.familyName = "CoolFoundry Examplary Serif"
    ufo_ExBd.info.styleName = "XBold Italic"
    ufo_ExBd.info.openTypeOS2WeightClass = 800
    ufo_ExBd.info.italicAngle = -11

    font = to_glyphs([ufo_Lt, ufo_Rg, ufo_Md, ufo_Bd, ufo_ExBd])
    designspace = to_designspace(font, ufo_module=ufo_module)

    path = os.path.join(str(tmpdir), "actual.designspace")
    designspace.write(path)

    expected_path = os.path.join(
        os.path.dirname(__file__), "..", "data", "DesignspaceGenTestItalic.designspace"
    )

    assert (
        len(main.diff_files(path, expected_path, formatter=formatting.DiffFormatter()))
        == 0
    )
예제 #8
0
 def _format_test(self, action, expected):
     formatter = formatting.DiffFormatter()
     result = formatter.format([action], None)
     self.assertEqual(result, expected)
예제 #9
0
def compare_xml(observed, expected):
    formatter = formatting.DiffFormatter()
    diff = main.diff_files(observed, expected, formatter=formatter)
    return diff
예제 #10
0

from xmldiff import main
main.diff_texts("./case3.html",
               "./case4.html")

from xmldiff import formatting
formatter = formatting.DiffFormatter()
print(main.diff_files("../tests/test_data/insert-node.left.html",
                       "../tests/test_data/insert-node.right.html",
                       formatter=formatter))