| Home | Trees | Indices | Help |
|---|
|
|
1 2 # The contents of this file are subject to the Mozilla Public License 3 # (MPL) Version 1.1 (the "License"); you may not use this file except 4 # in compliance with the License. You may obtain a copy of the License 5 # at http://www.mozilla.org/MPL/ 6 # 7 # Software distributed under the License is distributed on an "AS IS" 8 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 9 # the License for the specific language governing rights and 10 # limitations under the License. 11 # 12 # The Original Code is LEPL (http://www.acooke.org/lepl) 13 # The Initial Developer of the Original Code is Andrew Cooke. 14 # Portions created by the Initial Developer are Copyright (C) 2009-2010 15 # Andrew Cooke (andrew@acooke.org). All Rights Reserved. 16 # 17 # Alternatively, the contents of this file may be used under the terms 18 # of the LGPL license (the GNU Lesser General Public License, 19 # http://www.gnu.org/licenses/lgpl.html), in which case the provisions 20 # of the LGPL License are applicable instead of those above. 21 # 22 # If you wish to allow use of your version of this file only under the 23 # terms of the LGPL License and not to allow others to use your version 24 # of this file under the MPL, indicate your decision by deleting the 25 # provisions above and replace them with the notice and other provisions 26 # required by the LGPL License. If you do not delete the provisions 27 # above, a recipient may use your version of this file under either the 28 # MPL or the LGPL License. 29 30 ''' 31 Tests for the lepl.support.graph module. 32 ''' 33 34 from unittest import TestCase 35 36 37 from lepl.support.graph import ArgAsAttributeMixin, preorder, postorder, reset, \ 38 ConstructorWalker, Clone, make_proxy, LEAF, leaves 39 from lepl.support.node import Node 40 41 42 # pylint: disable-msg=C0103, C0111, C0301, W0702, C0324, C0102, C0321, W0141 43 # (dude this is just a test) 44 4547 48 # pylint: disable-msg=E1101 49 54 5768 6959 args = [str(self.label)] 60 args.extend(map(repr, self.nodes)) 61 return 'SimpleNode(%s)' % ','.join(args)6264 return self.nodes[index]6567 return len(self.nodes)71 return SimpleNode(1, 72 SimpleNode(11, 73 SimpleNode(111), 74 SimpleNode(112)), 75 SimpleNode(12))767886 87 97 9880 result = [node.label for node in preorder(graph(), SimpleNode, exclude=LEAF)] 81 assert result == [1, 11, 111, 112, 12], result82100162 # print(repr(g3)) 163 164102 g1 = graph() 103 g2 = ConstructorWalker(g1, SimpleNode)(Clone()) 104 assert repr(g1) == repr(g2) 105 assert g1 is not g2106 109111 depth = 0 112 result = '' 113 for c in text: 114 if c == '<': 115 depth += 1 116 elif c == '>': 117 depth -= 1 118 elif depth == 0: 119 result += c 120 return result121123 (s, n) = make_proxy() 124 g1 = SimpleNode(1, 125 SimpleNode(11, 126 SimpleNode(111), 127 SimpleNode(112), 128 n), 129 SimpleNode(12)) 130 s(g1) 131 g2 = ConstructorWalker(g1, SimpleNode)(Clone()) 132 self.assert_same(repr(g1), repr(g2))133135 (s1, n1) = make_proxy() 136 (s2, n2) = make_proxy() 137 g1 = SimpleNode(1, 138 SimpleNode(11, 139 SimpleNode(111, n2), 140 SimpleNode(112), 141 n1), 142 SimpleNode(12, n1)) 143 s1(g1) 144 s2(next(iter(g1))) 145 g2 = ConstructorWalker(g1, SimpleNode)(Clone()) 146 self.assert_same(repr(g1), repr(g2))147149 (s1, n1) = make_proxy() 150 (s2, n2) = make_proxy() 151 g1 = SimpleNode(1, 152 SimpleNode(11, 153 SimpleNode(111, n2), 154 SimpleNode(112), 155 n1), 156 SimpleNode(12, n1)) 157 s1(g1) 158 s2(next(iter(g1))) 159 g2 = ConstructorWalker(g1, SimpleNode)(Clone()) 160 g3 = ConstructorWalker(g2, SimpleNode)(Clone()) 161 self.assert_same(repr(g1), repr(g3))166181 182 189168 g = [1, [11, [111, 112], 12]] 169 result = [node for node in preorder(g, list) if isinstance(node, int)] 170 assert result == [1, 11, 111, 112, 12], result171173 ''' 174 At first I was surprised about this (compare with SimpleNode results above), 175 but these are leaf nodes, so postorder doesn't change anything (there's 176 no difference between "before visiting" and "after visiting" a leaf). 177 ''' 178 g = [1, [11, [111, 112], 12]] 179 result = [node for node in postorder(g, list) if isinstance(node, int)] 180 assert result == [1, 11, 111, 112, 12], result
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Jun 9 21:51:01 2012 | http://epydoc.sourceforge.net |