Rev 3018: Add note() 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:43:34 GMT 2007
At http://people.ubuntu.com/~robertc/baz2.0/nested-pb
------------------------------------------------------------
revno: 3018
revision-id:robertc at robertcollins.net-20071120004328-qn0tgv4op1d0qzck
parent: robertc at robertcollins.net-20071120003348-q444p8tld0spanlp
committer: Robert Collins <robertc at robertcollins.net>
branch nick: pb.simplify
timestamp: Tue 2007-11-20 11:43:28 +1100
message:
Add note() 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:33:48 +0000
+++ b/bzrlib/progress.py 2007-11-20 00:43:28 +0000
@@ -282,6 +282,10 @@
"""Hide the display - the display is finished with for now."""
raise NotImplementedError(self.clear)
+ def note(self, fmt, *args, **kwargs):
+ """Display a note without disrupting the display."""
+ raise NotImplementedError(self.note)
+
def task_changed(self):
"""Update the display due to a change in the task."""
raise NotImplementedError(self.task_changed)
@@ -305,6 +309,10 @@
self._last_message = None
self._last_current = None
+ def note(self, fmt, *args, **kwargs):
+ self.clear()
+ self._stream.write((fmt + '\n') % args)
+
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
@@ -325,6 +333,9 @@
def clear(self):
pass
+ def note(self, fmt, *args, **kwargs):
+ pass
+
def task_changed(self):
pass
=== modified file 'bzrlib/tests/test_progress.py'
--- a/bzrlib/tests/test_progress.py 2007-11-20 00:33:48 +0000
+++ b/bzrlib/tests/test_progress.py 2007-11-20 00:43:28 +0000
@@ -353,6 +353,13 @@
# We cannot really tell if anything is output, but the API should work.
display.clear()
+ def test_note(self):
+ task = CountedTask('message')
+ display = SilentTaskDisplay(task)
+ # We cannot really tell if anything is output, but the API should work.
+ display.note("A format string")
+ display.note("A format string %s", "with args")
+
def test_task_changed(self):
task = CountedTask('message')
display = SilentTaskDisplay(task)
@@ -374,6 +381,13 @@
display = DotsTaskDisplay(task, output)
return task, output, display
+ def test_clear_after_clear_does_nothing(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.clear()
+ display.clear()
+ self.assertEqual('message:\n', output.getvalue())
+
def test_clear_no_output_does_nothing(self):
task, output, display = self.get_display()
display.clear()
@@ -385,6 +399,29 @@
display.clear()
self.assertEqual('message:\n', output.getvalue())
+ def test_note_before_changes_outputs_note(self):
+ task, output, display = self.get_display()
+ display.note('Humans read this.')
+ self.assertEqual('Humans read this.\n', output.getvalue())
+
+ def test_note_after_clear_is_contiguous(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.clear()
+ display.note('Humans read this.')
+ self.assertEqual('message:\nHumans read this.\n', output.getvalue())
+
+ def test_note_after_message_auto_clears(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.note('Humans read this.')
+ self.assertEqual('message:\nHumans read this.\n', output.getvalue())
+
+ def test_note_with_format_variables(self):
+ task, output, display = self.get_display()
+ display.note('Something %s%d.', "to format", 1)
+ self.assertEqual('Something to format1.\n', output.getvalue())
+
def test_task_changed_after_clear_emits_message_again(self):
task, output, display = self.get_display()
display.task_changed()
@@ -392,6 +429,13 @@
display.task_changed()
self.assertEqual('message:\nmessage:', output.getvalue())
+ def test_task_changed_after_note_emits_message_again(self):
+ task, output, display = self.get_display()
+ display.task_changed()
+ display.note('For the user')
+ display.task_changed()
+ self.assertEqual('message:\nFor the user\nmessage:', output.getvalue())
+
def test_task_changed_first_call(self):
task, output, display = self.get_display()
# The first change will display the message
More information about the bazaar-commits
mailing list