bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2671.1.5
by Andrew Bennetts
Move has_same_location tests to a new file. |
1 |
# Copyright (C) 2007 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 implementations of Repository.has_same_location."""
|
|
18 |
||
19 |
from bzrlib import bzrdir |
|
20 |
from bzrlib.tests.repository_implementations import TestCaseWithRepository |
|
21 |
from bzrlib.transport import get_transport |
|
22 |
||
23 |
||
24 |
class TestHasSameLocation(TestCaseWithRepository): |
|
25 |
"""Tests for Repository.has_same_location method.""" |
|
26 |
||
27 |
def assertSameRepo(self, a, b): |
|
28 |
"""Asserts that two objects are the same repository. |
|
29 |
||
30 |
This method does the comparison both ways (`a.has_same_location(b)` as
|
|
31 |
well as `b.has_same_location(a)`) to make sure both objects'
|
|
32 |
`has_same_location` methods give the same results.
|
|
33 |
"""
|
|
34 |
self.assertTrue(a.has_same_location(b), |
|
35 |
"%r is not the same repository as %r" % (a, b)) |
|
36 |
self.assertTrue(b.has_same_location(a), |
|
37 |
"%r is the same as %r, but not vice versa" % (a, b)) |
|
38 |
||
39 |
def assertDifferentRepo(self, a, b): |
|
40 |
"""Asserts that two objects are the not same repository. |
|
41 |
||
42 |
This method does the comparison both ways (`a.has_same_location(b)` as
|
|
43 |
well as `b.has_same_location(a)`) to make sure both objects'
|
|
44 |
`has_same_location` methods give the same results.
|
|
45 |
||
46 |
:seealso: assertDifferentRepo
|
|
47 |
"""
|
|
48 |
self.assertFalse(a.has_same_location(b), |
|
49 |
"%r is not the same repository as %r" % (a, b)) |
|
50 |
self.assertFalse(b.has_same_location(a), |
|
51 |
"%r is the same as %r, but not vice versa" % (a, b)) |
|
52 |
||
53 |
def test_same_repo_instance(self): |
|
54 |
"""A repository object is the same repository as itself.""" |
|
55 |
repo = self.make_repository('.') |
|
56 |
self.assertSameRepo(repo, repo) |
|
57 |
||
58 |
def test_same_repo_location(self): |
|
59 |
"""Different repository objects for the same location are the same.""" |
|
60 |
repo = self.make_repository('.') |
|
61 |
reopened_repo = repo.bzrdir.open_repository() |
|
62 |
self.failIf( |
|
63 |
repo is reopened_repo, |
|
64 |
"This test depends on reopened_repo being a different instance of "
|
|
65 |
"the same repo.") |
|
66 |
self.assertSameRepo(repo, reopened_repo) |
|
67 |
||
68 |
def test_different_repos_not_equal(self): |
|
69 |
"""Repositories at different locations are not the same.""" |
|
70 |
repo_one = self.make_repository('one') |
|
71 |
repo_two = self.make_repository('two') |
|
72 |
self.assertDifferentRepo(repo_one, repo_two) |
|
73 |
||
74 |
def test_same_bzrdir_different_control_files_not_equal(self): |
|
75 |
"""Repositories in the same bzrdir, but with different control files, |
|
76 |
are not the same.
|
|
77 |
||
78 |
This can happens e.g. when upgrading a repository. This test mimics how
|
|
79 |
CopyConverter creates a second repository in one bzrdir.
|
|
80 |
"""
|
|
81 |
repo = self.make_repository('repo') |
|
82 |
try: |
|
83 |
control_transport = repo.control_files._transport |
|
84 |
except AttributeError: |
|
85 |
# This test only applies to repository formats with control_files.
|
|
86 |
return
|
|
87 |
if control_transport.base == repo.bzrdir.transport.base: |
|
88 |
# This test only applies to repository formats where the repo
|
|
89 |
# control_files are separate from other bzrdir files, i.e. metadir
|
|
90 |
# formats.
|
|
91 |
return
|
|
92 |
control_transport.copy_tree('.', '../repository.backup') |
|
93 |
backup_transport = control_transport.clone('../repository.backup') |
|
94 |
backup_repo = repo._format.open(repo.bzrdir, _found=True, |
|
95 |
_override_transport=backup_transport) |
|
96 |
||
97 |
self.assertDifferentRepo(repo, backup_repo) |
|
98 |
||
99 |
def test_different_format_not_equal(self): |
|
100 |
"""Different format repositories are comparable and not the same. |
|
101 |
||
102 |
Comparing different format repository objects should give a negative
|
|
103 |
result, rather than trigger an exception (which could happen with a
|
|
104 |
naive __eq__ implementation, e.g. due to missing attributes).
|
|
105 |
"""
|
|
106 |
repo = self.make_repository('repo') |
|
107 |
other_repo = self.make_repository('other', format='default') |
|
108 |
if repo._format == other_repo._format: |
|
109 |
# We're testing the default format! So we have to use a non-default
|
|
110 |
# format for other_repo.
|
|
111 |
get_transport(self.get_vfs_only_url()).delete_tree('other') |
|
112 |
other_repo = self.make_repository('other', format='metaweave') |
|
113 |
# Make sure the other_repo is not a RemoteRepository.
|
|
114 |
other_bzrdir = bzrdir.BzrDir.open(self.get_vfs_only_url('other')) |
|
115 |
other_repo = other_bzrdir.open_repository() |
|
116 |
self.assertDifferentRepo(repo, other_repo) |
|
117 |
||
118 |