/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 von Gagern
  • Date: 2010-04-20 08:47:38 UTC
  • mfrom: (5167 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5195.
  • Revision ID: martin.vgagern@gmx.net-20100420084738-ygymnqmdllzrhpfn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
2
2
#
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
12
12
#
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
16
16
 
17
17
 
18
18
"""Tests for log+ transport decorator."""
19
19
 
20
20
 
 
21
import types
 
22
 
 
23
 
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
24
28
 
25
29
 
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),
38
 
            '  --> None')
 
39
        log = self.get_log()
 
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'))
43
46
 
44
 
 
 
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