Rev 3032: bzrlib.progress.TaskStack.get_message shows messages from children too. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb
Robert Collins
robertc at robertcollins.net
Tue Nov 20 22:50:37 GMT 2007
At http://people.ubuntu.com/~robertc/baz2.0/nested-pb
------------------------------------------------------------
revno: 3032
revision-id:robertc at robertcollins.net-20071120225024-3x716f66hbw4q4c6
parent: robertc at robertcollins.net-20071120223910-o578f5kb0g6ppoqv
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Wed 2007-11-21 09:50:24 +1100
message:
bzrlib.progress.TaskStack.get_message shows messages from children too.
modified:
bzrlib/progress.py progress.py-20050610070202-df9faaab791964c0
bzrlib/tests/test_progress.py test_progress.py-20060308160359-978c397bc79b7fda
=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py 2007-11-20 22:39:10 +0000
+++ b/bzrlib/progress.py 2007-11-20 22:50:24 +0000
@@ -186,6 +186,22 @@
KnownLengthTask.__init__(self, message, total)
self.tasks = []
+ def get_message(self):
+ """Get the message of this TaskStack.
+
+ A TaskStack's message is the message of itself and of the top of the
+ stack of sub-tasks.
+
+ :return: A string e.g. 'pulling:finding revisions'.
+ """
+ # NB: This likely wants a cached self._current_message and to be
+ # calculated on push/pop of tasks.
+ if not self.tasks:
+ extra_message = ""
+ else:
+ extra_message = ":" + self.tasks[-1].get_message()
+ return KnownLengthTask.get_message(self) + extra_message
+
def push_task(self, task):
"""Add task as a sub-task of this stack."""
self.tasks.append(task)
=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py 2007-11-20 22:39:10 +0000
+++ b/bzrlib/tests/test_progress.py 2007-11-20 22:50:24 +0000
@@ -480,6 +480,21 @@
stack.pop_task(task)
self.assertEqual([], stack.tasks)
+ def test_get_message_shows_self_and_top(self):
+ message = 'pulling'
+ stack = TaskStack(message, 1)
+ task = CountedTask("finding revisions")
+ task_2 = KnownLengthTask("reading index", 5)
+ self.assertEqual("pulling", stack.get_message())
+ stack.push_task(task)
+ self.assertEqual("pulling:finding revisions", stack.get_message())
+ stack.push_task(task_2)
+ self.assertEqual("pulling:reading index", stack.get_message())
+ stack.pop_task(task_2)
+ self.assertEqual("pulling:finding revisions", stack.get_message())
+ stack.pop_task(task)
+ self.assertEqual("pulling", stack.get_message())
+
class TestSilentTaskDisplay(TestCase):
More information about the bazaar-commits
mailing list