/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3703.3.2 by Andrew Bennetts
Simple effort tests for pushing an empty branch.
1
# Copyright (C) 2008 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Effort tests for the smart protocol."""
18
19
from bzrlib import (
20
    builtins,
21
    debug,
22
    tests,
23
    )
24
from bzrlib.branch import Branch
3703.3.3 by Andrew Bennetts
Neater effort tests for push by using a _SmartClient.hooks['call'] hook.
25
from bzrlib.smart import client, server
3703.3.2 by Andrew Bennetts
Simple effort tests for pushing an empty branch.
26
from bzrlib.transport import get_transport
27
28
29
class EmptyPushEffortTests(tests.TestCaseWithMemoryTransport):
30
    """Tests that a push of 0 revisions should make a limited number of smart
31
    protocol RPCs.
32
    """
33
34
    def setUp(self):
35
        super(EmptyPushEffortTests, self).setUp()
36
        debug.debug_flags.add('hpss')
37
        self.smart_server = server.SmartTCPServer_for_testing()
38
        self.smart_server.setUp(self.get_server())
39
        self.addCleanup(self.smart_server.tearDown)
40
        self.empty_branch = self.make_branch('empty')
41
        self.make_branch('target')
3703.3.3 by Andrew Bennetts
Neater effort tests for push by using a _SmartClient.hooks['call'] hook.
42
        client._SmartClient.hooks.install_named_hook(
43
            'call', self.capture_hpss_call, None)
44
        self.hpss_calls = []
45
46
    def capture_hpss_call(self, params):
47
        self.hpss_calls.append(params.method)
3703.3.2 by Andrew Bennetts
Simple effort tests for pushing an empty branch.
48
49
    def test_empty_branch_api(self):
50
        transport = get_transport(self.smart_server.get_url()).clone('target')
51
        target = Branch.open_from_transport(transport)
52
        self.empty_branch.push(target)
3703.3.3 by Andrew Bennetts
Neater effort tests for push by using a _SmartClient.hooks['call'] hook.
53
        self.assertEqual(
54
            ['BzrDir.open',
55
             'BzrDir.open_branch',
56
             'BzrDir.find_repositoryV2',
57
             'Branch.lock_write',
58
             'Branch.last_revision_info',
59
             'Branch.unlock'],
60
            self.hpss_calls)
3703.3.2 by Andrew Bennetts
Simple effort tests for pushing an empty branch.
61
62
    def test_empty_branch_command(self):
63
        cmd = builtins.cmd_push()
64
        cmd.outf = tests.StringIOWrapper()
65
        cmd.run(
66
            directory=self.get_url() + 'empty',
67
            location=self.smart_server.get_url() + 'target')
3703.3.3 by Andrew Bennetts
Neater effort tests for push by using a _SmartClient.hooks['call'] hook.
68
        self.assertTrue(len(self.hpss_calls) <= 8)
3703.3.2 by Andrew Bennetts
Simple effort tests for pushing an empty branch.
69
70