bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
1 |
# Copyright (C) 2007-2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Tests for interface conformance of canonical paths of trees."""
|
|
18 |
||
19 |
||
20 |
from breezy import ( |
|
21 |
tests, |
|
22 |
)
|
|
|
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
23 |
from breezy.tests.per_workingtree import ( |
24 |
TestCaseWithWorkingTree, |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
25 |
)
|
26 |
from breezy.tests import ( |
|
27 |
features, |
|
28 |
)
|
|
29 |
||
30 |
||
|
7104.3.3
by Jelmer Vernooij
Move get_canonical_paths to WorkingTree. |
31 |
class TestCanonicalPaths(TestCaseWithWorkingTree): |
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
32 |
|
33 |
def _make_canonical_test_tree(self, commit=True): |
|
34 |
# make a tree used by all the 'canonical' tests below.
|
|
35 |
work_tree = self.make_branch_and_tree('tree') |
|
36 |
self.build_tree(['tree/dir/', 'tree/dir/file']) |
|
37 |
work_tree.add(['dir', 'dir/file']) |
|
38 |
if commit: |
|
39 |
work_tree.commit('commit 1') |
|
40 |
# XXX: this isn't actually guaranteed to return the class we want to
|
|
41 |
# test -- mbp 2010-02-12
|
|
42 |
return work_tree |
|
43 |
||
44 |
def test_canonical_path(self): |
|
45 |
work_tree = self._make_canonical_test_tree() |
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
46 |
if features.CaseInsensitiveFilesystemFeature.available(): |
47 |
self.assertEqual('dir/file', |
|
48 |
work_tree.get_canonical_path('Dir/File')) |
|
49 |
else: |
|
50 |
self.assertEqual('Dir/File', |
|
51 |
work_tree.get_canonical_path('Dir/File')) |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
52 |
|
53 |
def test_canonical_path_before_commit(self): |
|
54 |
work_tree = self._make_canonical_test_tree(False) |
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
55 |
if features.CaseInsensitiveFilesystemFeature.available(): |
56 |
self.assertEqual('dir/file', |
|
57 |
work_tree.get_canonical_path('Dir/File')) |
|
58 |
else: |
|
59 |
self.assertEqual('Dir/File', |
|
60 |
work_tree.get_canonical_path('Dir/File')) |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
61 |
|
62 |
def test_canonical_path_dir(self): |
|
63 |
# check it works when asked for just the directory portion.
|
|
64 |
work_tree = self._make_canonical_test_tree() |
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
65 |
if features.CaseInsensitiveFilesystemFeature.available(): |
66 |
self.assertEqual('dir', work_tree.get_canonical_path('Dir')) |
|
67 |
else: |
|
68 |
self.assertEqual('Dir', work_tree.get_canonical_path('Dir')) |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
69 |
|
70 |
def test_canonical_path_root(self): |
|
71 |
work_tree = self._make_canonical_test_tree() |
|
72 |
self.assertEqual('', work_tree.get_canonical_path('')) |
|
73 |
self.assertEqual('/', work_tree.get_canonical_path('/')) |
|
74 |
||
75 |
def test_canonical_path_invalid_all(self): |
|
76 |
work_tree = self._make_canonical_test_tree() |
|
77 |
self.assertEqual('foo/bar', |
|
78 |
work_tree.get_canonical_path('foo/bar')) |
|
79 |
||
80 |
def test_canonical_invalid_child(self): |
|
81 |
work_tree = self._make_canonical_test_tree() |
|
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
82 |
if features.CaseInsensitiveFilesystemFeature.available(): |
83 |
self.assertEqual('dir/None', |
|
84 |
work_tree.get_canonical_path('Dir/None')) |
|
85 |
else: |
|
86 |
self.assertEqual('Dir/None', |
|
87 |
work_tree.get_canonical_path('Dir/None')) |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
88 |
|
89 |
def test_canonical_tree_name_mismatch(self): |
|
90 |
# see <https://bugs.launchpad.net/bzr/+bug/368931>
|
|
91 |
# some of the trees we want to use can only exist on a disk, not in
|
|
92 |
# memory - therefore we can only test this if the filesystem is
|
|
93 |
# case-sensitive.
|
|
94 |
self.requireFeature(features.case_sensitive_filesystem_feature) |
|
95 |
work_tree = self.make_branch_and_tree('.') |
|
96 |
self.build_tree(['test/', 'test/file', 'Test']) |
|
97 |
work_tree.add(['test/', 'test/file', 'Test']) |
|
98 |
||
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
99 |
self.assertEqual(['test', 'Test', 'test/file', 'Test/file'], |
100 |
list(work_tree.get_canonical_paths( |
|
101 |
['test', 'Test', 'test/file', 'Test/file']))) |
|
102 |
||
103 |
test_revid = work_tree.commit('commit') |
|
104 |
test_tree = work_tree.branch.repository.revision_tree(test_revid) |
|
|
7104.3.2
by Jelmer Vernooij
Split out canonical path. |
105 |
test_tree.lock_read() |
106 |
self.addCleanup(test_tree.unlock) |
|
107 |
||
|
7104.3.4
by Jelmer Vernooij
Fix tests. |
108 |
self.assertEqual(['', 'Test', 'test', 'test/file'], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
109 |
[p for p, e in test_tree.iter_entries_by_dir()]) |