Rev 3015: bzrlib.progress.DotsTaskDisplay outputs dots on ticks. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb
Robert Collins
robertc at robertcollins.net
Tue Nov 20 00:15:36 GMT 2007
At http://people.ubuntu.com/~robertc/baz2.0/nested-pb
------------------------------------------------------------
revno: 3015
revision-id:robertc at robertcollins.net-20071120001527-sf6mn66s3z9g5eaa
parent: robertc at robertcollins.net-20071120001114-fvsuk5pei0mjri8b
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 11:15:27 +1100
message:
bzrlib.progress.DotsTaskDisplay outputs dots on ticks.
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 00:11:14 +0000
+++ b/bzrlib/progress.py 2007-11-20 00:15:27 +0000
@@ -289,12 +289,18 @@
def __init__(self, task, stream):
TaskDisplay.__init__(self, task)
self._stream = stream
+ self._last_message = None
def task_changed(self):
# When the task changes, a dots display should output each message it
# sees once, then dots until a new message is shown. Messages are shown
# at the beginning of a line.
- self._stream.write(self._task.get_message() + ':')
+ message = self._task.get_message()
+ if message != self._last_message:
+ self._stream.write(message + ':')
+ self._last_message = message
+ else:
+ self._stream.write('.')
class SilentTaskDisplay(TaskDisplay):
=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py 2007-11-20 00:09:34 +0000
+++ b/bzrlib/tests/test_progress.py 2007-11-20 00:15:27 +0000
@@ -361,7 +361,7 @@
output = StringIO()
display = DotsTaskDisplay(task, output)
- def test_task_changed(self):
+ def test_task_changed_first_call(self):
task = CountedTask('message')
output = StringIO()
display = DotsTaskDisplay(task, output)
@@ -369,3 +369,16 @@
display.task_changed()
self.assertEqual('message:', output.getvalue())
+ def test_task_changed_task_has_ticked(self):
+ task = CountedTask('message')
+ output = StringIO()
+ display = DotsTaskDisplay(task, output)
+ task.tick()
+ # The first change will display the message only, even if the current
+ # position is non-zero.
+ display.task_changed()
+ self.assertEqual('message:', output.getvalue())
+ task.tick()
+ # But now it should add a dot.
+ display.task_changed()
+ self.assertEqual('message:.', output.getvalue())
More information about the bazaar-commits
mailing list