~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transport_log.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-07-02 04:49:28 UTC
  • mfrom: (4491.2.9 340347-log-decorator)
  • Revision ID: pqm@pqm.ubuntu.com-20090702044928-90mv3s7kk139lbsf
(mbp) fix log+ transport decorator

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007, 2009 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
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):
41
45
        # and they operate on the underlying transport
42
46
        self.assertTrue(base_transport.has('subdir'))
43
47
 
44
 
 
 
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