Rev 4908: Get the basic interface tested. in http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes
John Arbash Meinel
john at arbash-meinel.com
Fri Dec 18 17:16:11 GMT 2009
At http://bazaar.launchpad.net/~jameinel/bzr/2.1.0rc1-dbytes
------------------------------------------------------------
revno: 4908
revision-id: john at arbash-meinel.com-20091218171609-gpft7w4hvt1zj827
parent: john at arbash-meinel.com-20091218163921-tcltjarx4pxxm08y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1.0rc1-dbytes
timestamp: Fri 2009-12-18 11:16:09 -0600
message:
Get the basic interface tested.
Also expose a small bug in TextProgressView. If we didn't have a
progress bar yet, we wouldn't actually track how much data was
transferred. But we might as well.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_uifactory/__init__.py'
--- a/bzrlib/tests/per_uifactory/__init__.py 2009-11-16 01:18:03 +0000
+++ b/bzrlib/tests/per_uifactory/__init__.py 2009-12-18 17:16:09 +0000
@@ -39,6 +39,7 @@
from bzrlib import (
tests,
+ transport,
ui,
)
@@ -83,6 +84,17 @@
raise tests.TestSkipped(str(e))
output_stream.write('hello!')
+ def test_transport_activity(self):
+ # It doesn't matter what the implementation does, we just want to make
+ # sure the interface is there
+ t = transport.get_transport('memory:///')
+ self.factory.report_transport_activity(t, 1000, 'write')
+ self.factory.report_transport_activity(t, 2000, 'read')
+ self.factory.log_transport_activity()
+ self._check_log_transport_activity_noarg()
+ self.factory.log_transport_activity(display=True)
+ self._check_log_transport_activity_display()
+
class TestTextUIFactory(tests.TestCase, UIFactoryTestMixin):
@@ -113,6 +125,50 @@
self.stderr.getvalue())
self.assertEquals("", self.stdout.getvalue())
+ def _check_log_transport_activity_noarg(self):
+ self.assertEqual('', self.stdout.getvalue())
+ self.assertEqual('', self.stderr.getvalue())
+
+ def _check_log_transport_activity_display(self):
+ self.assertEqual('', self.stdout.getvalue())
+ # Without a TTY, we shouldn't display anything
+ self.assertEqual('', self.stderr.getvalue())
+
+
+class TestTTYTextUIFactory(TestTextUIFactory):
+
+ def setUp(self):
+ super(TestTTYTextUIFactory, self).setUp()
+
+ class TTYStringIO(object):
+ """Thunk over to StringIO() for everything but 'isatty'"""
+
+ def __init__(self):
+ self.__dict__['_sio'] = StringIO()
+
+ def isatty(self):
+ return True
+
+ def __getattr__(self, name):
+ return getattr(self._sio, name)
+
+ def __setattr__(self, name, value):
+ return setattr(self._sio, name, value)
+
+ # Remove 'TERM' == 'dumb' which causes us to *not* treat output as a
+ # real terminal, even though isatty returns True
+ self._captureVar('TERM', None)
+ self.stderr = TTYStringIO()
+ self.stdout = TTYStringIO()
+ self.factory = ui.text.TextUIFactory(self.stdin, self.stdout,
+ self.stderr)
+
+ def _check_log_transport_activity_display(self):
+ self.assertEqual('', self.stdout.getvalue())
+ # Displaying the result should do something
+ self.assertEqual('\nTotal byte count: 0.003MiB (3000B)\n',
+ self.stderr.getvalue())
+
class TestSilentUIFactory(tests.TestCase, UIFactoryTestMixin):
# discards output, therefore tests for output expect nothing
@@ -134,6 +190,12 @@
def _check_show_warning(self, msg):
pass
+ def _check_log_transport_activity_noarg(self):
+ pass
+
+ def _check_log_transport_activity_display(self):
+ pass
+
class TestCannedInputUIFactory(tests.TestCase, UIFactoryTestMixin):
# discards output, reads input from variables
@@ -154,4 +216,8 @@
def _check_show_warning(self, msg):
pass
+ def _check_log_transport_activity_noarg(self):
+ pass
+ def _check_log_transport_activity_display(self):
+ pass
=== modified file 'bzrlib/ui/text.py'
--- a/bzrlib/ui/text.py 2009-12-18 16:39:21 +0000
+++ b/bzrlib/ui/text.py 2009-12-18 17:16:09 +0000
@@ -379,6 +379,8 @@
# XXX: Probably there should be a transport activity model, and that
# too should be seen by the progress view, rather than being poked in
# here.
+ self._total_byte_count += byte_count
+ self._bytes_since_update += byte_count
if not self._have_output:
# As a workaround for <https://launchpad.net/bugs/321935> we only
# show transport activity when there's already a progress bar
@@ -387,8 +389,6 @@
# output. Eventually it would be nice to have that automatically
# synchronized.
return
- self._total_byte_count += byte_count
- self._bytes_since_update += byte_count
now = time.time()
if self._total_byte_count < 2000:
# a little resistance at first, so it doesn't stay stuck at 0
More information about the bazaar-commits
mailing list