~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/__init__.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
 
# -*- coding: utf-8 -*-
 
3
#          and others
4
4
#
5
5
# This program is free software; you can redistribute it and/or modify
6
6
# it under the terms of the GNU General Public License as published by
24
24
rather than in tests/branch_implementations/*.py.
25
25
"""
26
26
 
 
27
from bzrlib import (
 
28
    errors,
 
29
    tests,
 
30
    )
27
31
from bzrlib.branch import (BranchFormat,
28
32
                           BranchTestProviderAdapter,
29
33
                           _legacy_formats,
30
34
                           )
31
 
from bzrlib.tests import (
32
 
                          adapt_modules,
33
 
                          default_transport,
34
 
                          TestLoader,
35
 
                          TestSuite,
36
 
                          )
 
35
from bzrlib.remote import RemoteBranchFormat, RemoteBzrDirFormat
 
36
from bzrlib.smart.server import (
 
37
    SmartTCPServer_for_testing,
 
38
    ReadonlySmartTCPServer_for_testing,
 
39
    )
 
40
from bzrlib.tests.bzrdir_implementations.test_bzrdir import TestCaseWithBzrDir
 
41
from bzrlib.transport.memory import MemoryServer
 
42
 
 
43
 
 
44
class TestCaseWithBranch(TestCaseWithBzrDir):
 
45
    """This helper will be adapted for each branch_implementation test."""
 
46
 
 
47
    def setUp(self):
 
48
        super(TestCaseWithBranch, self).setUp()
 
49
        self.branch = None
 
50
 
 
51
    def get_branch(self):
 
52
        if self.branch is None:
 
53
            self.branch = self.make_branch('')
 
54
        return self.branch
 
55
 
 
56
    def make_branch(self, relpath, format=None):
 
57
        repo = self.make_repository(relpath, format=format)
 
58
        # fixme RBC 20060210 this isnt necessarily a fixable thing,
 
59
        # Skipped is the wrong exception to raise.
 
60
        try:
 
61
            return self.branch_format.initialize(repo.bzrdir)
 
62
        except errors.UninitializableFormat:
 
63
            raise tests.TestSkipped('Uninitializable branch format')
 
64
 
 
65
    def make_repository(self, relpath, shared=False, format=None):
 
66
        made_control = self.make_bzrdir(relpath, format=format)
 
67
        return made_control.create_repository(shared=shared)
 
68
 
 
69
    def create_tree_with_merge(self):
 
70
        """Create a branch with a simple ancestry.
 
71
 
 
72
        The graph should look like:
 
73
            digraph H {
 
74
                "rev-1" -> "rev-2" -> "rev-3";
 
75
                "rev-1" -> "rev-1.1.1" -> "rev-3";
 
76
            }
 
77
 
 
78
        Or in ASCII:
 
79
            1
 
80
            |\
 
81
            2 1.1.1
 
82
            |/
 
83
            3
 
84
        """
 
85
        tree = self.make_branch_and_memory_tree('tree')
 
86
        tree.lock_write()
 
87
        try:
 
88
            tree.add('')
 
89
            tree.commit('first', rev_id='rev-1')
 
90
            tree.commit('second', rev_id='rev-1.1.1')
 
91
            # Uncommit that last commit and switch to the other line
 
92
            tree.branch.set_last_revision_info(1, 'rev-1')
 
93
            tree.set_parent_ids(['rev-1'])
 
94
            tree.commit('alt-second', rev_id='rev-2')
 
95
            tree.set_parent_ids(['rev-2', 'rev-1.1.1'])
 
96
            tree.commit('third', rev_id='rev-3')
 
97
        finally:
 
98
            tree.unlock()
 
99
 
 
100
        return tree
37
101
 
38
102
 
39
103
def test_suite():
40
 
    result = TestSuite()
 
104
    result = tests.TestSuite()
41
105
    test_branch_implementations = [
42
106
        'bzrlib.tests.branch_implementations.test_bound_sftp',
43
107
        'bzrlib.tests.branch_implementations.test_branch',
44
108
        'bzrlib.tests.branch_implementations.test_break_lock',
 
109
        'bzrlib.tests.branch_implementations.test_create_checkout',
 
110
        'bzrlib.tests.branch_implementations.test_commit',
 
111
        'bzrlib.tests.branch_implementations.test_get_revision_id_to_revno_map',
 
112
        'bzrlib.tests.branch_implementations.test_hooks',
45
113
        'bzrlib.tests.branch_implementations.test_http',
 
114
        'bzrlib.tests.branch_implementations.test_last_revision_info',
46
115
        'bzrlib.tests.branch_implementations.test_locking',
47
116
        'bzrlib.tests.branch_implementations.test_parent',
48
117
        'bzrlib.tests.branch_implementations.test_permissions',
49
118
        'bzrlib.tests.branch_implementations.test_pull',
 
119
        'bzrlib.tests.branch_implementations.test_push',
 
120
        'bzrlib.tests.branch_implementations.test_revision_history',
 
121
        'bzrlib.tests.branch_implementations.test_revision_id_to_revno',
 
122
        'bzrlib.tests.branch_implementations.test_tags',
 
123
        'bzrlib.tests.branch_implementations.test_uncommit',
50
124
        'bzrlib.tests.branch_implementations.test_update',
51
125
        ]
 
126
    # Generate a list of branch formats and their associated bzrdir formats to
 
127
    # use.
 
128
    combinations = [(format, format._matchingbzrdir) for format in 
 
129
         BranchFormat._formats.values() + _legacy_formats]
52
130
    adapter = BranchTestProviderAdapter(
53
 
        default_transport,
 
131
        # None here will cause the default vfs transport server to be used.
 
132
        None,
54
133
        # None here will cause a readonly decorator to be created
55
134
        # by the TestCaseWithTransport.get_readonly_transport method.
56
135
        None,
57
 
        [(format, format._matchingbzrdir) for format in 
58
 
         BranchFormat._formats.values() + _legacy_formats])
59
 
    loader = TestLoader()
60
 
    adapt_modules(test_branch_implementations, adapter, loader, result)
 
136
        combinations)
 
137
    loader = tests.TestLoader()
 
138
    tests.adapt_modules(test_branch_implementations, adapter, loader, result)
 
139
 
 
140
    adapt_to_smart_server = BranchTestProviderAdapter(
 
141
        SmartTCPServer_for_testing,
 
142
        ReadonlySmartTCPServer_for_testing,
 
143
        [(RemoteBranchFormat(), RemoteBzrDirFormat())],
 
144
        MemoryServer
 
145
        )
 
146
    tests.adapt_modules(test_branch_implementations,
 
147
                        adapt_to_smart_server,
 
148
                        loader,
 
149
                        result)
 
150
 
61
151
    return result