__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import SCons.compat
+
import copy
import sys
import unittest
def disambiguate(self):
return self
+ def push_to_cache(self):
+ pass
+
def retrieve_from_cache(self):
global cache_text
if self.cached:
def built(self):
global built_text
- built_text = built_text + " really"
+ if not self.cached:
+ built_text = built_text + " really"
def has_builder(self):
return not self.builder is None
class Executor:
def prepare(self):
pass
+ def get_action_targets(self):
+ return self.targets
+ def get_all_targets(self):
+ return self.targets
+ def get_all_children(self):
+ result = []
+ for node in self.targets:
+ result.extend(node.children())
+ return result
+ def get_all_prerequisites(self):
+ return []
+ def get_action_side_effects(self):
+ return []
self.executor = Executor()
- self.executor.targets = self.targets
+ self.executor.targets = self.targets
return self.executor
class OtherError(Exception):
t.prepare()
t.execute()
t = tm.next_task()
- assert t == None
+ assert t is None
n1 = Node("n1")
n2 = Node("n2")
t.executed()
t.postprocess()
- assert tm.next_task() == None
+ assert tm.next_task() is None
built_text = "up to date: "
top_node = n3
t.executed()
t.postprocess()
- assert tm.next_task() == None
+ assert tm.next_task() is None
n1 = Node("n1")
t5.executed()
t5.postprocess()
- assert tm.next_task() == None
+ assert tm.next_task() is None
n4 = Node("n4")
n4.set_state(SCons.Node.executed)
tm = SCons.Taskmaster.Taskmaster([n4])
- assert tm.next_task() == None
+ assert tm.next_task() is None
n1 = Node("n1")
n2 = Node("n2", [n1])
t.executed()
t.postprocess()
t = tm.next_task()
- assert tm.next_task() == None
+ assert tm.next_task() is None
n1 = Node("n1")
assert target == n3, target
t.executed()
t.postprocess()
- assert tm.next_task() == None
+ assert tm.next_task() is None
n1 = Node("n1")
n2 = Node("n2")
assert t.get_target() == n4
t.executed()
t.postprocess()
- assert tm.next_task() == None
+ assert tm.next_task() is None
assert scan_called == 4, scan_called
tm = SCons.Taskmaster.Taskmaster([n5])
t = tm.next_task()
assert t.get_target() == n5, t.get_target()
t.executed()
- assert tm.next_task() == None
+ assert tm.next_task() is None
assert scan_called == 5, scan_called
n1 = Node("n1")
"""
class MyTask(SCons.Taskmaster.Task):
def make_ready(self):
- raise MyException, "from make_ready()"
+ raise MyException("from make_ready()")
n1 = Node("n1")
tm = SCons.Taskmaster.Taskmaster(targets = [n1], tasker = MyTask)
"""
class StopNode(Node):
def children(self):
- raise SCons.Errors.StopError, "stop!"
+ raise SCons.Errors.StopError("stop!")
class ExitNode(Node):
def children(self):
sys.exit(77)
t = tm.next_task()
assert t.targets == [n1], t.targets
t.fail_stop()
- assert t.targets == [n3], map(str, t.targets)
+ assert t.targets == [n3], list(map(str, t.targets))
assert t.top == 1, t.top
def test_stop(self):
# set it up by having something that approximates a real Builder
# return this list--but that's more work than is probably
# warranted right now.
- t.targets = [n1, n2]
+ n1.get_executor().targets = [n1, n2]
t.prepare()
assert n1.prepared
assert n2.prepared
t = tm.next_task()
# More bogus reaching in and setting the targets.
n3.set_state(SCons.Node.up_to_date)
- t.targets = [n3, n4]
+ n3.get_executor().targets = [n3, n4]
t.prepare()
assert n3.prepared
assert n4.prepared
tm = SCons.Taskmaster.Taskmaster([n6, n7])
t = tm.next_task()
# More bogus reaching in and setting the targets.
- t.targets = [n6, n7]
+ n6.get_executor().targets = [n6, n7]
t.prepare()
assert n6.prepared
assert n7.prepared
# Make sure we call an Executor's prepare() method.
class ExceptionExecutor:
def prepare(self):
- raise Exception, "Executor.prepare() exception"
+ raise Exception("Executor.prepare() exception")
+ def get_all_targets(self):
+ return self.nodes
+ def get_all_children(self):
+ result = []
+ for node in self.nodes:
+ result.extend(node.children())
+ return result
+ def get_all_prerequisites(self):
+ return []
+ def get_action_side_effects(self):
+ return []
n11 = Node("n11")
n11.executor = ExceptionExecutor()
+ n11.executor.nodes = [n11]
tm = SCons.Taskmaster.Taskmaster([n11])
t = tm.next_task()
try:
except Exception, e:
assert str(e) == "Executor.prepare() exception", e
else:
- raise AssertionError, "did not catch expected exception"
+ raise AssertionError("did not catch expected exception")
def test_execute(self):
"""Test executing a task
except SCons.Errors.UserError:
pass
else:
- raise TestFailed, "did not catch expected UserError"
+ raise TestFailed("did not catch expected UserError")
def raise_BuildError():
raise SCons.Errors.BuildError
except SCons.Errors.BuildError:
pass
else:
- raise TestFailed, "did not catch expected BuildError"
+ raise TestFailed("did not catch expected BuildError")
# On a generic (non-BuildError) exception from a Builder,
# the target should throw a BuildError exception with the
t = tm.next_task()
try:
t.execute()
- except SCons.Errors.TaskmasterException, e:
+ except SCons.Errors.BuildError, e:
assert e.node == n4, e.node
- assert e.errstr == "Exception", e.errstr
+ assert e.errstr == "OtherError : ", e.errstr
assert len(e.exc_info) == 3, e.exc_info
exc_traceback = sys.exc_info()[2]
- assert type(e.exc_info[2]) == type(exc_traceback), e.exc_info[2]
+ assert isinstance(e.exc_info[2], type(exc_traceback)), e.exc_info[2]
else:
- raise TestFailed, "did not catch expected BuildError"
+ raise TestFailed("did not catch expected BuildError")
built_text = None
cache_text = []
def test_trace(self):
"""Test Taskmaster tracing
"""
- import StringIO
+ import io
- trace = StringIO.StringIO()
+ trace = io.StringIO()
n1 = Node("n1")
n2 = Node("n2")
n3 = Node("n3", [n1, n2])
Taskmaster: Considering node <no_state 0 'n1'> and its children:
Taskmaster: Evaluating <pending 0 'n1'>
+Task.make_ready_current(): node <pending 0 'n1'>
+Task.prepare(): node <executing 0 'n1'>
+Task.execute(): node <executing 0 'n1'>
+Task.postprocess(): node <executing 0 'n1'>
+
Taskmaster: Looking for a node to evaluate
Taskmaster: Considering node <executed 0 'n1'> and its children:
Taskmaster: already handled (executed)
Taskmaster: Considering node <no_state 0 'n3'> and its children:
Taskmaster: <executed 0 'n1'>
Taskmaster: <no_state 0 'n2'>
-Taskmaster: adjusting ref count: <pending 1 'n3'>
+Taskmaster: adjusted ref count: <pending 1 'n3'>, child 'n2'
Taskmaster: Considering node <no_state 0 'n2'> and its children:
Taskmaster: Evaluating <pending 0 'n2'>
+Task.make_ready_current(): node <pending 0 'n2'>
+Task.prepare(): node <executing 0 'n2'>
+Task.execute(): node <executing 0 'n2'>
+Task.postprocess(): node <executing 0 'n2'>
+Task.postprocess(): removing <executing 0 'n2'>
+Task.postprocess(): adjusted parent ref count <pending 0 'n3'>
+
Taskmaster: Looking for a node to evaluate
Taskmaster: Considering node <pending 0 'n3'> and its children:
Taskmaster: <executed 0 'n1'>
Taskmaster: <executed 0 'n2'>
Taskmaster: Evaluating <pending 0 'n3'>
+Task.make_ready_current(): node <pending 0 'n3'>
+Task.prepare(): node <executing 0 'n3'>
+Task.execute(): node <executing 0 'n3'>
+Task.postprocess(): node <executing 0 'n3'>
+
Taskmaster: Looking for a node to evaluate
Taskmaster: No candidate anymore.
suite = unittest.makeSuite(TaskmasterTestCase, 'test_')
if not unittest.TextTestRunner().run(suite).wasSuccessful():
sys.exit(1)
+
+# Local Variables:
+# tab-width:4
+# indent-tabs-mode:nil
+# End:
+# vim: set expandtab tabstop=4 shiftwidth=4: