2 # Copyright (c) 2001 Steven Knight
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
38 def execute(self, **kw):
44 def execute(self, **kw):
48 def Dictionary(self, *args):
53 class NodeTestCase(unittest.TestCase):
55 def test_BuildException(self):
56 """Test throwing an exception on build failure.
58 node = SCons.Node.Node()
59 node.builder_set(FailBuilder())
60 node.env_set(Environment())
63 except SCons.Errors.BuildError:
66 raise TestFailed, "did not catch expected BuildError"
69 """Test building a node
71 # Make sure it doesn't blow up if no builder is set.
72 node = SCons.Node.Node()
74 assert built_it == None
76 node = SCons.Node.Node()
77 node.builder_set(Builder())
78 node.env_set(Environment())
79 node.path = "xxx" # XXX FAKE SUBCLASS ATTRIBUTE
80 node.sources = "yyy" # XXX FAKE SUBCLASS ATTRIBUTE
84 def test_builder_set(self):
85 """Test setting a Node's Builder
87 node = SCons.Node.Node()
90 assert node.builder == b
92 def test_current(self):
93 node = SCons.Node.Node()
94 assert node.current() is None
96 def test_env_set(self):
97 """Test setting a Node's Environment
99 node = SCons.Node.Node()
104 def test_has_signature(self):
105 """Test whether or not a node has a signature
107 node = SCons.Node.Node()
108 assert not node.has_signature()
109 node.set_signature('xxx')
110 assert node.has_signature()
112 def test_set_signature(self):
113 """Test setting a Node's signature
115 node = SCons.Node.Node()
116 node.set_signature('yyy')
117 assert node.signature == 'yyy'
119 def test_get_signature(self):
120 """Test fetching a Node's signature
122 node = SCons.Node.Node()
123 node.set_signature('zzz')
124 assert node.get_signature() == 'zzz'
126 def test_add_dependency(self):
127 """Test adding dependencies to a Node's list.
129 node = SCons.Node.Node()
130 assert node.depends == []
132 zero = SCons.Node.Node()
134 node.add_dependency(zero)
140 one = SCons.Node.Node()
141 two = SCons.Node.Node()
142 three = SCons.Node.Node()
143 four = SCons.Node.Node()
145 node.add_dependency([one])
146 assert node.depends == [one]
147 node.add_dependency([two, three])
148 assert node.depends == [one, two, three]
149 node.add_dependency([three, four, one])
150 assert node.depends == [one, two, three, four]
152 assert zero.get_parents() == []
153 assert one.get_parents() == [node]
154 assert two.get_parents() == [node]
155 assert three.get_parents() == [node]
156 assert four.get_parents() == [node]
159 def test_add_source(self):
160 """Test adding sources to a Node's list.
162 node = SCons.Node.Node()
163 assert node.sources == []
165 zero = SCons.Node.Node()
167 node.add_source(zero)
173 one = SCons.Node.Node()
174 two = SCons.Node.Node()
175 three = SCons.Node.Node()
176 four = SCons.Node.Node()
178 node.add_source([one])
179 assert node.sources == [one]
180 node.add_source([two, three])
181 assert node.sources == [one, two, three]
182 node.add_source([three, four, one])
183 assert node.sources == [one, two, three, four]
185 assert zero.get_parents() == []
186 assert one.get_parents() == [node]
187 assert two.get_parents() == [node]
188 assert three.get_parents() == [node]
189 assert four.get_parents() == [node]
191 def test_children(self):
192 """Test fetching the "children" of a Node.
194 node = SCons.Node.Node()
195 one = SCons.Node.Node()
196 two = SCons.Node.Node()
197 three = SCons.Node.Node()
198 four = SCons.Node.Node()
199 five = SCons.Node.Node()
200 six = SCons.Node.Node()
202 node.add_source([one, two, three])
203 node.add_dependency([four, five, six])
204 kids = node.children()
205 assert len(kids) == 6
213 def test_add_parent(self):
214 """Test adding parents to a Node."""
215 node = SCons.Node.Node()
216 parent = SCons.Node.Node()
217 node._add_parent(parent)
218 assert node.get_parents() == [parent]
219 node._add_parent(parent)
220 assert node.get_parents() == [parent]
222 def test_state(self):
223 """Test setting and getting the state of a node
225 node = SCons.Node.Node()
226 assert node.get_state() == None
227 node.set_state(SCons.Node.executing)
228 assert node.get_state() == SCons.Node.executing
230 def test_walker(self):
231 """Test walking a Node tree.
234 class MyNode(SCons.Node.Node):
235 def __init__(self, name):
236 SCons.Node.Node.__init__(self)
241 nw = SCons.Node.Walker(n1)
242 assert not nw.is_done()
243 assert nw.next().name == "n1"
245 assert nw.next() == None
249 n1.add_source([n2, n3])
251 nw = SCons.Node.Walker(n1)
252 assert nw.next().name == "n2"
253 assert nw.next().name == "n3"
254 assert nw.next().name == "n1"
255 assert nw.next() == None
261 n2.add_source([n4, n5])
262 n3.add_dependency([n6, n7])
264 nw = SCons.Node.Walker(n1)
265 assert nw.next().name == "n4"
266 assert nw.next().name == "n5"
267 assert nw.next().name == "n2"
268 assert nw.next().name == "n6"
269 assert nw.next().name == "n7"
270 assert nw.next().name == "n3"
271 assert nw.next().name == "n1"
272 assert nw.next() == None
274 def test_children_are_executed(self):
275 n1 = SCons.Node.Node()
276 n2 = SCons.Node.Node()
277 n3 = SCons.Node.Node()
278 n4 = SCons.Node.Node()
281 n3.add_source([n1, n2])
283 assert not n4.children_are_executed()
284 assert not n3.children_are_executed()
285 assert n2.children_are_executed()
286 assert n1.children_are_executed()
288 n1.set_state(SCons.Node.executed)
289 assert not n4.children_are_executed()
290 assert not n3.children_are_executed()
291 assert n2.children_are_executed()
292 assert n1.children_are_executed()
294 n2.set_state(SCons.Node.executed)
295 assert not n4.children_are_executed()
296 assert n3.children_are_executed()
297 assert n2.children_are_executed()
298 assert n1.children_are_executed()
300 n3.set_state(SCons.Node.executed)
301 assert n4.children_are_executed()
302 assert n3.children_are_executed()
303 assert n2.children_are_executed()
304 assert n1.children_are_executed()
309 if __name__ == "__main__":
310 suite = unittest.makeSuite(NodeTestCase, 'test_')
311 if not unittest.TextTestRunner().run(suite).wasSuccessful():