eeejay / specular

A XML-RPC service used for examining web pages accessibility

This URL has Read+Write access

specular / tests_treediff / simple_tree.py
100644 58 lines (47 sloc) 1.848 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
 
import unittest
from treediff import TreeMatcher
from treediff.script_store import ScriptOp
 
T1 = ['D', None, [
            ['P', None, [
                            ['S', 'a', []],
                            ['S', 'b', []],
                            ['S', 'c', []]]],
            ['P', None, [
                            ['S', 'd', []],
                            ['S', 'e', []]]],
            ['P', None, [
                            ['S', 'f', []]]]]]
 
T2 = ['D', None, [
            ['P', None, [
                            ['S', 'a', []],
                            ['S', 'c', []]]],
            ['P', None, [
                            ['S', 'f', []]]],
            ['P', None, [
                            ['S', 'd', []],
                            ['S', 'e', []],
                            ['S', 'g', []]]]]]
 
EXPECTED_OPS = [
    ScriptOp(ScriptOp.MOVE,
             'D:[1]/P:None', 'D:None', 4),
    ScriptOp(ScriptOp.INSERT,
             'D:[2]/P:[2]/S:g', 'S', 'g', 'D:[2]/P:None', 3),
    ScriptOp(ScriptOp.DELETE,
             'D:[0]/P:[1]/S:b')]
 
class TestSimpleTree(unittest.TestCase):
    def testtreediff(self):
        matcher = TreeMatcher(T1, T2)
        s = matcher.get_opcodes()
        
        #for o in s: print o
            
        self.assertEqual(len(s), len(EXPECTED_OPS),
                         "Script has unexpected length.")
 
        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")
 
if __name__ == '__main__':
    unittest.main()