4763.2.4
by John Arbash Meinel
merge bzr.2.1 in preparation for NEWS entry. |
1 |
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
|
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
16 |
|
17 |
||
18 |
"""Tests for log+ transport decorator."""
|
|
19 |
||
20 |
||
4491.2.3
by Martin Pool
Add test for TransportLogDecorator handling of readv |
21 |
import types |
22 |
||
23 |
||
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
24 |
from bzrlib.tests import TestCaseWithMemoryTransport |
25 |
from bzrlib.trace import mutter |
|
26 |
from bzrlib.transport import get_transport |
|
4491.2.3
by Martin Pool
Add test for TransportLogDecorator handling of readv |
27 |
from bzrlib.transport.log import TransportLogDecorator |
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
28 |
|
29 |
||
30 |
class TestTransportLog(TestCaseWithMemoryTransport): |
|
31 |
||
32 |
def test_log_transport(self): |
|
33 |
base_transport = self.get_transport('') |
|
34 |
logging_transport = get_transport('log+' + base_transport.base) |
|
35 |
||
36 |
# operations such as mkdir are logged
|
|
37 |
mutter('where are you?') |
|
38 |
logging_transport.mkdir('subdir') |
|
4794.1.15
by Robert Collins
Review feedback. |
39 |
log = self.get_log() |
4794.1.8
by Robert Collins
Move the passing of test logs to the result to be via the getDetails API and remove all public use of TestCase._get_log. |
40 |
self.assertContainsRe(log, r'mkdir memory\+\d+://.*subdir') |
41 |
self.assertContainsRe(log, ' --> None') |
|
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
42 |
# they have the expected effect
|
43 |
self.assertTrue(logging_transport.has('subdir')) |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
44 |
# and they operate on the underlying transport
|
3675.1.1
by Martin Pool
Merge and update log+ transport decorator |
45 |
self.assertTrue(base_transport.has('subdir')) |
46 |
||
4491.2.3
by Martin Pool
Add test for TransportLogDecorator handling of readv |
47 |
def test_log_readv(self): |
48 |
# see <https://bugs.launchpad.net/bzr/+bug/340347>
|
|
49 |
||
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
|
|
55 |
# registered etc
|
|
56 |
logging_transport = TransportLogDecorator( |
|
57 |
'log+dummy:///', _decorated=base_transport) |
|
58 |
||
59 |
result = base_transport.readv('foo', [(0, 10)]) |
|
60 |
# sadly there's no types.IteratorType, and GeneratorType is too
|
|
61 |
# specific
|
|
62 |
self.assertTrue(getattr(result, 'next')) |
|
63 |
||
64 |
result = logging_transport.readv('foo', [(0, 10)]) |
|
65 |
self.assertTrue(getattr(result, 'next')) |
|
66 |
self.assertEquals(list(result), |
|
67 |
[(0, 'abcdefghij')]) |
|
68 |
||
69 |
||
70 |
class DummyReadvTransport(object): |
|
71 |
||
72 |
base = 'dummy:///' |
|
73 |
||
74 |
def readv(self, filename, offset_length_pairs): |
|
75 |
yield (0, 'abcdefghij') |
|
76 |
||
77 |
def abspath(self, path): |
|
78 |
return self.base + path |