X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=src%2Fengine%2FSCons%2FTaskmasterTests.py;h=3dd22e3e9137f6bda3f93cfbe3f35e817fb8bbac;hb=6a218d30e5fa1a14835a31129881b4288db7dc1d;hp=932458179f0550f8859b16b2468b3401cb4c7f74;hpb=63c273db3764fa7a3de3ba56b02c3a25672b4e4d;p=scons.git diff --git a/src/engine/SCons/TaskmasterTests.py b/src/engine/SCons/TaskmasterTests.py index 93245817..3dd22e3e 100644 --- a/src/engine/SCons/TaskmasterTests.py +++ b/src/engine/SCons/TaskmasterTests.py @@ -23,6 +23,8 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import SCons.compat + import copy import sys import unittest @@ -69,6 +71,9 @@ class Node: def disambiguate(self): return self + def push_to_cache(self): + pass + def retrieve_from_cache(self): global cache_text if self.cached: @@ -87,7 +92,8 @@ class Node: 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 @@ -166,8 +172,21 @@ class Node: 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): @@ -190,7 +209,7 @@ class TaskmasterTestCase(unittest.TestCase): t.prepare() t.execute() t = tm.next_task() - assert t == None + assert t is None n1 = Node("n1") n2 = Node("n2") @@ -219,7 +238,7 @@ class TaskmasterTestCase(unittest.TestCase): t.executed() t.postprocess() - assert tm.next_task() == None + assert tm.next_task() is None built_text = "up to date: " top_node = n3 @@ -264,7 +283,7 @@ class TaskmasterTestCase(unittest.TestCase): t.executed() t.postprocess() - assert tm.next_task() == None + assert tm.next_task() is None n1 = Node("n1") @@ -299,13 +318,13 @@ class TaskmasterTestCase(unittest.TestCase): 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]) @@ -314,7 +333,7 @@ class TaskmasterTestCase(unittest.TestCase): t.executed() t.postprocess() t = tm.next_task() - assert tm.next_task() == None + assert tm.next_task() is None n1 = Node("n1") @@ -336,7 +355,7 @@ class TaskmasterTestCase(unittest.TestCase): 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") @@ -362,14 +381,14 @@ class TaskmasterTestCase(unittest.TestCase): 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") @@ -520,7 +539,7 @@ class TaskmasterTestCase(unittest.TestCase): """ 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) @@ -596,7 +615,7 @@ class TaskmasterTestCase(unittest.TestCase): """ 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) @@ -643,7 +662,7 @@ class TaskmasterTestCase(unittest.TestCase): 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): @@ -752,7 +771,7 @@ class TaskmasterTestCase(unittest.TestCase): # 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 @@ -763,7 +782,7 @@ class TaskmasterTestCase(unittest.TestCase): 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 @@ -803,7 +822,7 @@ class TaskmasterTestCase(unittest.TestCase): 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 @@ -814,10 +833,22 @@ class TaskmasterTestCase(unittest.TestCase): # 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: @@ -825,7 +856,7 @@ class TaskmasterTestCase(unittest.TestCase): 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 @@ -850,7 +881,7 @@ class TaskmasterTestCase(unittest.TestCase): 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 @@ -863,7 +894,7 @@ class TaskmasterTestCase(unittest.TestCase): 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 @@ -876,14 +907,14 @@ class TaskmasterTestCase(unittest.TestCase): 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 = [] @@ -1025,9 +1056,9 @@ class TaskmasterTestCase(unittest.TestCase): 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]) @@ -1056,22 +1087,39 @@ Taskmaster: Looking for a node to evaluate Taskmaster: Considering node and its children: Taskmaster: Evaluating +Task.make_ready_current(): node +Task.prepare(): node +Task.execute(): node +Task.postprocess(): node + Taskmaster: Looking for a node to evaluate Taskmaster: Considering node and its children: Taskmaster: already handled (executed) Taskmaster: Considering node and its children: Taskmaster: Taskmaster: -Taskmaster: adjusting ref count: +Taskmaster: adjusted ref count: , child 'n2' Taskmaster: Considering node and its children: Taskmaster: Evaluating +Task.make_ready_current(): node +Task.prepare(): node +Task.execute(): node +Task.postprocess(): node +Task.postprocess(): removing +Task.postprocess(): adjusted parent ref count + Taskmaster: Looking for a node to evaluate Taskmaster: Considering node and its children: Taskmaster: Taskmaster: Taskmaster: Evaluating +Task.make_ready_current(): node +Task.prepare(): node +Task.execute(): node +Task.postprocess(): node + Taskmaster: Looking for a node to evaluate Taskmaster: No candidate anymore. @@ -1084,3 +1132,9 @@ if __name__ == "__main__": 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: