Rev 5423: (mbp) split out ProgressRecordingUIFactory (Martin Pool) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Tue Sep 14 12:09:41 BST 2010
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 5423 [merge]
revision-id: pqm at pqm.ubuntu.com-20100914110939-hvk7xfh39y9hq76a
parent: pqm at pqm.ubuntu.com-20100913123052-cxsnsnc6bca12cq8
parent: mbp at sourcefrog.net-20100914081422-h55w4pm7fuj8z1dl
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-09-14 12:09:39 +0100
message:
(mbp) split out ProgressRecordingUIFactory (Martin Pool)
added:
bzrlib/tests/testui.py testsupport.py-20100914040736-dpw8sndzy6dxk8s1-1
modified:
bzrlib/progress.py progress.py-20050610070202-df9faaab791964c0
bzrlib/tests/per_workingtree/test_commit.py test_commit.py-20060421013633-1610ec2331c8190f
bzrlib/tests/test_ui.py test_ui.py-20051130162854-458e667a7414af09
=== modified file 'bzrlib/progress.py'
--- a/bzrlib/progress.py 2010-07-17 16:39:20 +0000
+++ b/bzrlib/progress.py 2010-09-14 04:13:48 +0000
@@ -166,48 +166,6 @@
self.ui_factory.clear_term()
-# NOTE: This is also deprecated; you should provide a ProgressView instead.
-class _BaseProgressBar(object):
-
- def __init__(self,
- to_file=None,
- show_pct=False,
- show_spinner=False,
- show_eta=False,
- show_bar=True,
- show_count=True,
- to_messages_file=None,
- _stack=None):
- object.__init__(self)
- if to_file is None:
- to_file = sys.stderr
- if to_messages_file is None:
- to_messages_file = sys.stdout
- self.to_file = to_file
- self.to_messages_file = to_messages_file
- self.last_msg = None
- self.last_cnt = None
- self.last_total = None
- self.show_pct = show_pct
- self.show_spinner = show_spinner
- self.show_eta = show_eta
- self.show_bar = show_bar
- self.show_count = show_count
- self._stack = _stack
- # seed throttler
- self.MIN_PAUSE = 0.1 # seconds
- now = time.time()
- # starting now
- self.start_time = now
- # next update should not throttle
- self.last_update = now - self.MIN_PAUSE - 1
-
- def finished(self):
- """Return this bar to its progress stack."""
- self.clear()
- self._stack.return_pb(self)
-
-
class DummyProgress(object):
"""Progress-bar standin that does nothing.
=== modified file 'bzrlib/tests/per_workingtree/test_commit.py'
--- a/bzrlib/tests/per_workingtree/test_commit.py 2010-04-01 12:53:53 +0000
+++ b/bzrlib/tests/per_workingtree/test_commit.py 2010-09-14 08:14:22 +0000
@@ -38,55 +38,7 @@
from bzrlib.trace import mutter
from bzrlib.workingtree import (TreeEntry, TreeDirectory, TreeFile, TreeLink,
WorkingTree)
-
-
-class CapturingUIFactory(ui.UIFactory):
- """A UI Factory for testing - capture the updates made through it."""
-
- def __init__(self):
- super(CapturingUIFactory, self).__init__()
- self._calls = []
- self.depth = 0
-
- def clear(self):
- """See progress.ProgressTask.clear()."""
-
- def clear_term(self):
- """See progress.ProgressTask.clear_term()."""
-
- def finished(self):
- """See progress.ProgressTask.finished()."""
- self.depth -= 1
-
- def note(self, fmt_string, *args, **kwargs):
- """See progress.ProgressTask.note()."""
-
- def progress_bar(self):
- return self
-
- def nested_progress_bar(self):
- self.depth += 1
- return self
-
- def update(self, message, count=None, total=None):
- """See progress.ProgressTask.update()."""
- if self.depth == 1:
- self._calls.append(("update", count, total, message))
-
-
-class TestCapturingUI(TestCase):
-
- def test_nested_ignore_depth_beyond_one(self):
- # we only want to capture the first level out progress, not
- # want sub-components might do. So we have nested bars ignored.
- factory = CapturingUIFactory()
- pb1 = factory.nested_progress_bar()
- pb1.update('foo', 0, 1)
- pb2 = factory.nested_progress_bar()
- pb2.update('foo', 0, 1)
- pb2.finished()
- pb1.finished()
- self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
+from bzrlib.tests.testui import ProgressRecordingUIFactory
class TestCommit(TestCaseWithWorkingTree):
@@ -507,7 +459,7 @@
def setUp(self):
super(TestCommitProgress, self).setUp()
- ui.ui_factory = CapturingUIFactory()
+ ui.ui_factory = ProgressRecordingUIFactory()
def test_commit_progress_steps(self):
# during commit we one progress update for every entry in the
@@ -526,7 +478,7 @@
f.close()
# set a progress bar that captures the calls so we can see what is
# emitted
- factory = CapturingUIFactory()
+ factory = ProgressRecordingUIFactory()
ui.ui_factory = factory
# TODO RBC 20060421 it would be nice to merge the reporter output
# into the factory for this test - just make the test ui factory
@@ -547,7 +499,7 @@
tree = self.make_branch_and_tree('.')
# set a progress bar that captures the calls so we can see what is
# emitted
- factory = CapturingUIFactory()
+ factory = ProgressRecordingUIFactory()
ui.ui_factory = factory
def a_hook(_, _2, _3, _4, _5, _6):
pass
@@ -570,7 +522,7 @@
tree = self.make_branch_and_tree('.')
# set a progress bar that captures the calls so we can see what is
# emitted
- factory = CapturingUIFactory()
+ factory = ProgressRecordingUIFactory()
ui.ui_factory = factory
def a_hook(_, _2, _3, _4, _5, _6, _7, _8):
pass
=== modified file 'bzrlib/tests/test_ui.py'
--- a/bzrlib/tests/test_ui.py 2010-08-25 10:20:41 +0000
+++ b/bzrlib/tests/test_ui.py 2010-09-14 08:14:22 +0000
@@ -39,6 +39,9 @@
test_progress,
)
from bzrlib.ui import text as _mod_ui_text
+from bzrlib.tests.testui import (
+ ProgressRecordingUIFactory,
+ )
class TestUIConfiguration(tests.TestCaseWithTransport):
@@ -432,3 +435,19 @@
self.assertIsNone('0', av)
self.assertIsNone('on', av)
self.assertIsNone('off', av)
+
+
+class TestProgressRecordingUI(tests.TestCase):
+ """Test test-oriented UIFactory that records progress updates"""
+
+ def test_nested_ignore_depth_beyond_one(self):
+ # we only want to capture the first level out progress, not
+ # want sub-components might do. So we have nested bars ignored.
+ factory = ProgressRecordingUIFactory()
+ pb1 = factory.nested_progress_bar()
+ pb1.update('foo', 0, 1)
+ pb2 = factory.nested_progress_bar()
+ pb2.update('foo', 0, 1)
+ pb2.finished()
+ pb1.finished()
+ self.assertEqual([("update", 0, 1, 'foo')], factory._calls)
=== added file 'bzrlib/tests/testui.py'
--- a/bzrlib/tests/testui.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/testui.py 2010-09-14 08:14:22 +0000
@@ -0,0 +1,46 @@
+# Copyright (C) 2006-2010 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""UI implementations for use in testing.
+"""
+
+
+from bzrlib import (
+ progress,
+ ui,
+ )
+
+
+class ProgressRecordingUIFactory(ui.UIFactory, progress.DummyProgress):
+ """Captures progress updates made through it.
+
+ This is overloaded as both the UIFactory and the progress model."""
+
+ def __init__(self):
+ super(ProgressRecordingUIFactory, self).__init__()
+ self._calls = []
+ self.depth = 0
+
+ def nested_progress_bar(self):
+ self.depth += 1
+ return self
+
+ def finished(self):
+ self.depth -= 1
+
+ def update(self, message, count=None, total=None):
+ if self.depth == 1:
+ self._calls.append(("update", count, total, message))
More information about the bazaar-commits
mailing list