/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_log.py

  • Committer: Martin Pool
  • Date: 2009-12-14 06:06:59 UTC
  • mfrom: (4889 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4891.
  • Revision ID: mbp@sourcefrog.net-20091214060659-1ucv8hpnky0cbnaj
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005, 2006, 2007, 2009 Canonical Ltd
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
"""Tests for log+ transport decorator."""
 
19
 
 
20
 
 
21
import types
 
22
 
 
23
 
 
24
from bzrlib.tests import TestCaseWithMemoryTransport
 
25
from bzrlib.trace import mutter
 
26
from bzrlib.transport import get_transport
 
27
from bzrlib.transport.log import TransportLogDecorator
 
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')
 
39
        self.assertContainsRe(self._get_log(True),
 
40
            r'mkdir memory\+\d+://.*subdir')
 
41
        self.assertContainsRe(self._get_log(True),
 
42
            '  --> None')
 
43
        # they have the expected effect
 
44
        self.assertTrue(logging_transport.has('subdir'))
 
45
        # and they operate on the underlying transport
 
46
        self.assertTrue(base_transport.has('subdir'))
 
47
 
 
48
    def test_log_readv(self):
 
49
        # see <https://bugs.launchpad.net/bzr/+bug/340347>
 
50
 
 
51
        # transports are not required to return a generator, but we
 
52
        # specifically want to check that those that do cause it to be passed
 
53
        # through, for the sake of minimum interference
 
54
        base_transport = DummyReadvTransport()
 
55
        # construct it directly to avoid needing the dummy transport to be
 
56
        # registered etc
 
57
        logging_transport = TransportLogDecorator(
 
58
            'log+dummy:///', _decorated=base_transport)
 
59
 
 
60
        result = base_transport.readv('foo', [(0, 10)])
 
61
        # sadly there's no types.IteratorType, and GeneratorType is too
 
62
        # specific
 
63
        self.assertTrue(getattr(result, 'next'))
 
64
 
 
65
        result = logging_transport.readv('foo', [(0, 10)])
 
66
        self.assertTrue(getattr(result, 'next'))
 
67
        self.assertEquals(list(result),
 
68
            [(0, 'abcdefghij')])
 
69
 
 
70
 
 
71
class DummyReadvTransport(object):
 
72
 
 
73
    base = 'dummy:///'
 
74
 
 
75
    def readv(self, filename, offset_length_pairs):
 
76
        yield (0, 'abcdefghij')
 
77
 
 
78
    def abspath(self, path):
 
79
        return self.base + path