/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_tree.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by 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
"""Tests for Tree and InterTree."""
 
18
 
 
19
from bzrlib.tests import TestCaseWithTransport
 
20
from bzrlib.tree import InterTree
 
21
 
 
22
 
 
23
class TestInterTree(TestCaseWithTransport):
 
24
 
 
25
    def test_revision_tree_revision_tree(self):
 
26
        # we should have an InterTree registered for RevisionTree to
 
27
        # RevisionTree.
 
28
        tree = self.make_branch_and_tree('.')
 
29
        rev_id = tree.commit('first post')
 
30
        rev_id2 = tree.commit('second post', allow_pointless=True)
 
31
        rev_tree = tree.branch.repository.revision_tree(rev_id)
 
32
        rev_tree2 = tree.branch.repository.revision_tree(rev_id2)
 
33
        optimiser = InterTree.get(rev_tree, rev_tree2)
 
34
        self.assertIsInstance(optimiser, InterTree)
 
35
        optimiser = InterTree.get(rev_tree2, rev_tree)
 
36
        self.assertIsInstance(optimiser, InterTree)
 
37
 
 
38
    def test_working_tree_revision_tree(self):
 
39
        # we should have an InterTree available for WorkingTree to 
 
40
        # RevisionTree.
 
41
        tree = self.make_branch_and_tree('.')
 
42
        rev_id = tree.commit('first post')
 
43
        rev_tree = tree.branch.repository.revision_tree(rev_id)
 
44
        optimiser = InterTree.get(rev_tree, tree)
 
45
        self.assertIsInstance(optimiser, InterTree)
 
46
        optimiser = InterTree.get(tree, rev_tree)
 
47
        self.assertIsInstance(optimiser, InterTree)
 
48
 
 
49
    def test_working_tree_working_tree(self):
 
50
        # we should have an InterTree available for WorkingTree to 
 
51
        # WorkingTree.
 
52
        tree = self.make_branch_and_tree('1')
 
53
        tree2 = self.make_branch_and_tree('2')
 
54
        optimiser = InterTree.get(tree, tree2)
 
55
        self.assertIsInstance(optimiser, InterTree)
 
56
        optimiser = InterTree.get(tree2, tree)
 
57
        self.assertIsInstance(optimiser, InterTree)
 
58
 
 
59
 
 
60
class RecordingOptimiser(InterTree):
 
61
 
 
62
    calls = []
 
63
 
 
64
    def compare(self, want_unchanged=False, specific_files=None,
 
65
        extra_trees=None, require_versioned=False, include_root=False):
 
66
        self.calls.append(
 
67
            ('compare', self.source, self.target, want_unchanged,
 
68
             specific_files, extra_trees, require_versioned, 
 
69
             include_root)
 
70
            )
 
71
    
 
72
    @classmethod
 
73
    def is_compatible(klass, source, target):
 
74
        return True
 
75
 
 
76
 
 
77
class TestTree(TestCaseWithTransport):
 
78
 
 
79
    def test_compare_calls_InterTree_compare(self):
 
80
        """This test tests the way Tree.compare() uses InterTree."""
 
81
        old_optimisers = InterTree._optimisers
 
82
        try:
 
83
            InterTree._optimisers = []
 
84
            RecordingOptimiser.calls = []
 
85
            InterTree.register_optimiser(RecordingOptimiser)
 
86
            tree = self.make_branch_and_tree('1')
 
87
            tree2 = self.make_branch_and_tree('2')
 
88
            # do a series of calls:
 
89
            # trivial usage
 
90
            tree.changes_from(tree2)
 
91
            # pass in all optional arguments by position
 
92
            tree.changes_from(tree2, 'unchanged', 'specific', 'extra', 
 
93
                              'require', True)
 
94
            # pass in all optional arguments by keyword
 
95
            tree.changes_from(tree2,
 
96
                specific_files='specific',
 
97
                want_unchanged='unchanged',
 
98
                extra_trees='extra',
 
99
                require_versioned='require',
 
100
                include_root=True,
 
101
                )
 
102
        finally:
 
103
            InterTree._optimisers = old_optimisers
 
104
        self.assertEqual(
 
105
            [
 
106
             ('compare', tree2, tree, False, None, None, False, False),
 
107
             ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
 
108
              'require', True),
 
109
             ('compare', tree2, tree, 'unchanged', 'specific', 'extra',
 
110
              'require', True),
 
111
            ], RecordingOptimiser.calls)