1
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Tests for log+ transport decorator."""
21
24
from bzrlib.tests import TestCaseWithMemoryTransport
22
25
from bzrlib.trace import mutter
23
26
from bzrlib.transport import get_transport
27
from bzrlib.transport.log import TransportLogDecorator
26
30
class TestTransportLog(TestCaseWithMemoryTransport):
32
36
# operations such as mkdir are logged
33
37
mutter('where are you?')
34
38
logging_transport.mkdir('subdir')
35
self.assertContainsRe(self._get_log(True),
36
r'mkdir memory\+\d+://.*subdir')
37
self.assertContainsRe(self._get_log(True),
40
self.assertContainsRe(log, r'mkdir memory\+\d+://.*subdir')
41
self.assertContainsRe(log, ' --> None')
39
42
# they have the expected effect
40
43
self.assertTrue(logging_transport.has('subdir'))
41
# and they operate on the underlying transport
44
# and they operate on the underlying transport
42
45
self.assertTrue(base_transport.has('subdir'))
47
def test_log_readv(self):
48
# see <https://bugs.launchpad.net/bzr/+bug/340347>
50
# transports are not required to return a generator, but we
51
# specifically want to check that those that do cause it to be passed
52
# through, for the sake of minimum interference
53
base_transport = DummyReadvTransport()
54
# construct it directly to avoid needing the dummy transport to be
56
logging_transport = TransportLogDecorator(
57
'log+dummy:///', _decorated=base_transport)
59
result = base_transport.readv('foo', [(0, 10)])
60
# sadly there's no types.IteratorType, and GeneratorType is too
62
self.assertTrue(getattr(result, 'next'))
64
result = logging_transport.readv('foo', [(0, 10)])
65
self.assertTrue(getattr(result, 'next'))
66
self.assertEquals(list(result),
70
class DummyReadvTransport(object):
74
def readv(self, filename, offset_length_pairs):
75
yield (0, 'abcdefghij')
77
def abspath(self, path):
78
return self.base + path