Rev 3017: Add clear() to the bzrlib.progress.TaskDisplay API. in http://people.ubuntu.com/~robertc/baz2.0/nested-pb
Robert Collins
robertc at robertcollins.net
Tue Nov 20 00:33:54 GMT 2007
At http://people.ubuntu.com/~robertc/baz2.0/nested-pb
------------------------------------------------------------
revno: 3017
revision-id:robertc at robertcollins.net-20071120003348-q444p8tld0spanlp
parent: robertc at robertcollins.net-20071120002404-fwpku689n1oz7rdw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 11:33:48 +1100
message:
Add clear() to the bzrlib.progress.TaskDisplay API.
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:24:04 +0000
+++ b/bzrlib/progress.py 2007-11-20 00:33:48 +0000
@@ -278,6 +278,10 @@
"""Create a TaskDisplay."""
self._task = task
+ def clear(self):
+ """Hide the display - the display is finished with for now."""
+ raise NotImplementedError(self.clear)
+
def task_changed(self):
"""Update the display due to a change in the task."""
raise NotImplementedError(self.task_changed)
@@ -289,6 +293,15 @@
def __init__(self, task, stream):
TaskDisplay.__init__(self, task)
self._stream = stream
+ self._init_state()
+
+ def clear(self):
+ if self._last_message is not None:
+ self._stream.write('\n')
+ self._init_state()
+
+ def _init_state(self):
+ """Clear the internal state used for controlling output."""
self._last_message = None
self._last_current = None
@@ -309,6 +322,9 @@
class SilentTaskDisplay(TaskDisplay):
"""A TaskDisplay that performs no output."""
+ def clear(self):
+ pass
+
def task_changed(self):
pass
=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py 2007-11-20 00:24:04 +0000
+++ b/bzrlib/tests/test_progress.py 2007-11-20 00:33:48 +0000
@@ -347,6 +347,12 @@
task = CountedTask('message')
display = SilentTaskDisplay(task)
+ def test_clear(self):
+ task = CountedTask('message')
+ display = SilentTaskDisplay(task)
+ # We cannot really tell if anything is output, but the API should work.
+ display.clear()
+
def test_task_changed(self):
task = CountedTask('message')
display = SilentTaskDisplay(task)
@@ -361,18 +367,39 @@
output = StringIO()
display = DotsTaskDisplay(task, output)
+ def get_display(self):
+ """Get a task, output and display to test with."""
+ task = CountedTask('message')
+ output = StringIO()
+ display = DotsTaskDisplay(task, output)
+ return task, output, display
+
+ def test_clear_no_output_does_nothing(self):
+ task, output, display = self.get_display()
+ display.clear()
+ self.assertEqual('', output.getvalue())
+
+ def test_clear_after_output_emits_nl(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.clear()
+ self.assertEqual('message:\n', output.getvalue())
+
+ def test_task_changed_after_clear_emits_message_again(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.clear()
+ display.task_changed()
+ self.assertEqual('message:\nmessage:', output.getvalue())
+
def test_task_changed_first_call(self):
- task = CountedTask('message')
- output = StringIO()
- display = DotsTaskDisplay(task, output)
+ task, output, display = self.get_display()
# The first change will display the message
display.task_changed()
self.assertEqual('message:', output.getvalue())
def test_task_changed_no_change(self):
- task = CountedTask('message')
- output = StringIO()
- display = DotsTaskDisplay(task, output)
+ task, output, display = self.get_display()
# The first change will display the message
display.task_changed()
self.assertEqual('message:', output.getvalue())
@@ -382,9 +409,7 @@
self.assertEqual('message:', output.getvalue())
def test_task_changed_task_has_ticked(self):
- task = CountedTask('message')
- output = StringIO()
- display = DotsTaskDisplay(task, output)
+ task, output, display = self.get_display()
task.tick()
# The first change will display the message only, even if the current
# position is non-zero.
More information about the bazaar-commits
mailing list