예제 #1
0
    def testtreescript(self):
        d1 = parse(xml_file1)
#        strip_whitespace(d1)
        d2 = parse(xml_file2)
#        strip_whitespace(d2)

        matcher = DomTreeMatcher(d1, d2)
        before = matcher._tree1._dom.toprettyxml(' ')
        wanted = matcher._tree2._dom.toprettyxml(' ')
        scrpt = '\n'.join(map(str, matcher.get_opcodes()))
#        matcher._match()
#        for m1, m2 in matcher._mapping:
#            if m1.nodeType == m1.COMMENT_NODE:
#                print m1, m2
        got = matcher._tree1._dom.toprettyxml(' ')
#        print len(s)
#        print len(s)
        print '*'*80
        s = matcher.get_opcodes()
#        s2 = matcher.get_opcodes()
        diagnostics = """
Second run returned a script (%d)
Started with:
%s
%s
Expected:
%s
%s
Got:
%s
%s
Script:
%s
%s
Second run:
%s
%s""" % (len(s), '-'*80, before, '-'*80, 
         wanted, '-'*80, got, '-'*80, scrpt, '-'*80, '\n'.join(map(str, s)))

        print wanted == got
        diagnostics = '\n'.join(map(str, s))
        self.assertEqual(len(s), 0,
                         "Script is not accurate. \n%s" % diagnostics)
        print scrpt
예제 #2
0
    def testtreescript(self):
        matcher = DomTreeMatcher(parseString(T1), parseString(T2))
        s = matcher.get_opcodes()
        
        #for o in s: print o
        
        self.assertEqual(len(s), len(EXPECTED_OPS), 
                         "Script has unexpected length.\n%s" %
                         '\n'.join(map(str, s)))

        for op, expected in zip(s, EXPECTED_OPS):
            self.assertEqual((op.op_type, op.args), 
                             (expected.op_type, expected.args),
                             "Op types don't match. "
                             "Expected %s, got %s" % (expected, op))
    
        
        self.assertEqual(len(matcher.get_opcodes()), 0,
                         "Script is not accurate")