~bzr-pqm/bzr/bzr.dev

6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2008-2011, 2016 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
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
21
from bzrlib import transport
3675.1.1 by Martin Pool
Merge and update log+ transport decorator
22
from bzrlib.tests import TestCaseWithMemoryTransport
23
from bzrlib.trace import mutter
4491.2.3 by Martin Pool
Add test for TransportLogDecorator handling of readv
24
from bzrlib.transport.log import TransportLogDecorator
3675.1.1 by Martin Pool
Merge and update log+ transport decorator
25
26
27
class TestTransportLog(TestCaseWithMemoryTransport):
28
29
    def test_log_transport(self):
30
        base_transport = self.get_transport('')
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
31
        logging_transport = transport.get_transport(
32
            'log+' + base_transport.base)
3675.1.1 by Martin Pool
Merge and update log+ transport decorator
33
34
        # operations such as mkdir are logged
35
        mutter('where are you?')
36
        logging_transport.mkdir('subdir')
4794.1.15 by Robert Collins
Review feedback.
37
        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.
38
        self.assertContainsRe(log, r'mkdir memory\+\d+://.*subdir')
39
        self.assertContainsRe(log, '  --> None')
3675.1.1 by Martin Pool
Merge and update log+ transport decorator
40
        # they have the expected effect
41
        self.assertTrue(logging_transport.has('subdir'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
42
        # and they operate on the underlying transport
3675.1.1 by Martin Pool
Merge and update log+ transport decorator
43
        self.assertTrue(base_transport.has('subdir'))
44
4491.2.3 by Martin Pool
Add test for TransportLogDecorator handling of readv
45
    def test_log_readv(self):
46
        # see <https://bugs.launchpad.net/bzr/+bug/340347>
47
48
        # transports are not required to return a generator, but we
49
        # specifically want to check that those that do cause it to be passed
50
        # through, for the sake of minimum interference
51
        base_transport = DummyReadvTransport()
52
        # construct it directly to avoid needing the dummy transport to be
53
        # registered etc
54
        logging_transport = TransportLogDecorator(
55
            'log+dummy:///', _decorated=base_transport)
56
57
        result = base_transport.readv('foo', [(0, 10)])
58
        # sadly there's no types.IteratorType, and GeneratorType is too
59
        # specific
60
        self.assertTrue(getattr(result, 'next'))
61
62
        result = logging_transport.readv('foo', [(0, 10)])
63
        self.assertTrue(getattr(result, 'next'))
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
64
        self.assertEqual(list(result),
4491.2.3 by Martin Pool
Add test for TransportLogDecorator handling of readv
65
            [(0, 'abcdefghij')])
66
67
68
class DummyReadvTransport(object):
69
70
    base = 'dummy:///'
71
72
    def readv(self, filename, offset_length_pairs):
73
        yield (0, 'abcdefghij')
74
75
    def abspath(self, path):
76
        return self.base + path