3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
16 |
|
17 |
"""Views stored within a working tree.
|
|
18 |
||
3586.1.33
by Ian Clatworthy
cleanup trailing whitespace |
19 |
The views are actually in the WorkingTree.views namespace, but these are
|
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
20 |
1:1 with WorkingTree implementations so can be tested from here.
|
21 |
"""
|
|
22 |
||
23 |
||
4032.4.3
by Eduardo Padoan
Added tests for views.check_path_in_view() |
24 |
from bzrlib import views, errors |
6437.70.10
by John Arbash Meinel
WorkingTreeFormat6._matchingbzrdir wasn't actually creating a matching bzrdir. |
25 |
from bzrlib.tests import TestNotApplicable, TestSkipped |
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
26 |
from bzrlib.workingtree import WorkingTree |
27 |
||
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
28 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
29 |
|
30 |
||
31 |
class TestTreeViews(TestCaseWithWorkingTree): |
|
32 |
||
33 |
def setUp(self): |
|
3586.1.33
by Ian Clatworthy
cleanup trailing whitespace |
34 |
# formats that don't support views can skip the rest of these
|
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
35 |
# tests...
|
36 |
fmt = self.workingtree_format |
|
37 |
f = getattr(fmt, 'supports_views') |
|
38 |
if f is None: |
|
39 |
raise TestSkipped("format %s doesn't declare whether it " |
|
40 |
"supports views, assuming not" % fmt) |
|
41 |
if not f(): |
|
6437.70.10
by John Arbash Meinel
WorkingTreeFormat6._matchingbzrdir wasn't actually creating a matching bzrdir. |
42 |
raise TestNotApplicable("format %s doesn't support views" % fmt) |
6552.1.4
by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super(). |
43 |
super(TestTreeViews, self).setUp() |
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
44 |
|
45 |
def test_views_initially_empty(self): |
|
46 |
wt = self.make_branch_and_tree('wt') |
|
47 |
current, views = wt.views.get_view_info() |
|
48 |
self.assertEqual(None, current) |
|
49 |
self.assertEqual({}, views) |
|
50 |
||
51 |
def test_set_and_get_view_info(self): |
|
52 |
wt = self.make_branch_and_tree('wt') |
|
53 |
view_current = 'view-name' |
|
54 |
view_dict = { |
|
55 |
view_current: ['dir-1'], |
|
56 |
'other-name': ['dir-2']} |
|
57 |
wt.views.set_view_info(view_current, view_dict) |
|
58 |
current, views = wt.views.get_view_info() |
|
59 |
self.assertEquals(view_current, current) |
|
60 |
self.assertEquals(view_dict, views) |
|
61 |
# then reopen the tree and see they're still there
|
|
62 |
wt = WorkingTree.open('wt') |
|
63 |
current, views = wt.views.get_view_info() |
|
64 |
self.assertEquals(view_current, current) |
|
65 |
self.assertEquals(view_dict, views) |
|
66 |
# test setting a current view which does not exist
|
|
67 |
self.assertRaises(errors.NoSuchView, |
|
68 |
wt.views.set_view_info, 'yet-another', view_dict) |
|
69 |
current, views = wt.views.get_view_info() |
|
70 |
self.assertEquals(view_current, current) |
|
71 |
self.assertEquals(view_dict, views) |
|
72 |
# test clearing the current view
|
|
3586.1.7
by Ian Clatworthy
first cut at WTF5 |
73 |
wt.views.set_view_info(None, view_dict) |
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
74 |
current, views = wt.views.get_view_info() |
75 |
self.assertEquals(None, current) |
|
76 |
self.assertEquals(view_dict, views) |
|
77 |
||
78 |
def test_lookup_view(self): |
|
79 |
wt = self.make_branch_and_tree('wt') |
|
80 |
view_current = 'view-name' |
|
81 |
view_dict = { |
|
82 |
view_current: ['dir-1'], |
|
83 |
'other-name': ['dir-2']} |
|
84 |
wt.views.set_view_info(view_current, view_dict) |
|
85 |
# test lookup of the default view
|
|
86 |
result = wt.views.lookup_view() |
|
87 |
self.assertEqual(result, ['dir-1']) |
|
88 |
# test lookup of a named view
|
|
89 |
result = wt.views.lookup_view('other-name') |
|
90 |
self.assertEqual(result, ['dir-2']) |
|
91 |
||
92 |
def test_set_view(self): |
|
93 |
wt = self.make_branch_and_tree('wt') |
|
94 |
# test that set_view sets the current view by default
|
|
95 |
wt.views.set_view('view-1', ['dir-1']) |
|
96 |
current, views = wt.views.get_view_info() |
|
97 |
self.assertEquals('view-1', current) |
|
98 |
self.assertEquals({'view-1': ['dir-1']}, views) |
|
99 |
# test adding a view and not making it the current one
|
|
100 |
wt.views.set_view('view-2', ['dir-2'], make_current=False) |
|
101 |
current, views = wt.views.get_view_info() |
|
102 |
self.assertEquals('view-1', current) |
|
103 |
self.assertEquals({'view-1': ['dir-1'], 'view-2': ['dir-2']}, views) |
|
104 |
||
105 |
def test_unicode_view(self): |
|
106 |
wt = self.make_branch_and_tree('wt') |
|
107 |
view_name = u'\u3070' |
|
108 |
view_files = ['foo', 'bar/'] |
|
109 |
view_dict = {view_name: view_files} |
|
110 |
wt.views.set_view_info(view_name, view_dict) |
|
111 |
current, views = wt.views.get_view_info() |
|
112 |
self.assertEquals(view_name, current) |
|
113 |
self.assertEquals(view_dict, views) |
|
114 |
||
115 |
def test_no_such_view(self): |
|
116 |
wt = self.make_branch_and_tree('wt') |
|
117 |
try: |
|
118 |
wt.views.lookup_view('opaque') |
|
119 |
except errors.NoSuchView, e: |
|
120 |
self.assertEquals(e.view_name, 'opaque') |
|
3586.1.7
by Ian Clatworthy
first cut at WTF5 |
121 |
self.assertEquals(str(e), 'No such view: opaque.') |
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
122 |
else: |
123 |
self.fail("didn't get expected exception") |
|
124 |
||
125 |
def test_delete_view(self): |
|
126 |
wt = self.make_branch_and_tree('wt') |
|
127 |
view_name = u'\N{GREEK SMALL LETTER ALPHA}' |
|
128 |
view_files = ['alphas/'] |
|
129 |
wt.views.set_view(view_name, view_files) |
|
130 |
# now try to delete it
|
|
131 |
wt.views.delete_view(view_name) |
|
132 |
# now you can't look it up
|
|
133 |
self.assertRaises(errors.NoSuchView, |
|
134 |
wt.views.lookup_view, view_name) |
|
135 |
# and it's not in the dictionary
|
|
136 |
self.assertEquals(wt.views.get_view_info()[1], {}) |
|
137 |
# and you can't remove it a second time
|
|
138 |
self.assertRaises(errors.NoSuchView, |
|
139 |
wt.views.delete_view, view_name) |
|
140 |
# or remove a view that never existed
|
|
141 |
self.assertRaises(errors.NoSuchView, |
|
142 |
wt.views.delete_view, view_name + '2') |
|
143 |
||
4032.4.3
by Eduardo Padoan
Added tests for views.check_path_in_view() |
144 |
def test_check_path_in_view(self): |
145 |
wt = self.make_branch_and_tree('wt') |
|
146 |
view_current = 'view-name' |
|
147 |
view_dict = { |
|
148 |
view_current: ['dir-1'], |
|
149 |
'other-name': ['dir-2']} |
|
150 |
wt.views.set_view_info(view_current, view_dict) |
|
151 |
self.assertEqual(views.check_path_in_view(wt, 'dir-1'), None) |
|
152 |
self.assertEqual(views.check_path_in_view(wt, 'dir-1/sub'), None) |
|
153 |
self.assertRaises(errors.FileOutsideView, |
|
154 |
views.check_path_in_view, wt, 'dir-2') |
|
155 |
self.assertRaises(errors.FileOutsideView, |
|
156 |
views.check_path_in_view, wt, 'dir-2/sub') |
|
157 |
self.assertRaises(errors.FileOutsideView, |
|
158 |
views.check_path_in_view, wt, 'other') |
|
159 |
||
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
160 |
|
161 |
class TestUnsupportedViews(TestCaseWithWorkingTree): |
|
162 |
"""Formats that don't support views should give reasonable errors."""
|
|
163 |
||
164 |
def setUp(self): |
|
165 |
fmt = self.workingtree_format |
|
166 |
supported = getattr(fmt, 'supports_views') |
|
167 |
if supported is None: |
|
168 |
warn("Format %s doesn't declare whether it supports views or not" |
|
169 |
% fmt) |
|
170 |
raise TestSkipped('No view support at all') |
|
171 |
if supported(): |
|
172 |
raise TestSkipped("Format %s declares that views are supported" |
|
173 |
% fmt) |
|
174 |
# it's covered by TestTreeViews
|
|
6552.1.4
by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super(). |
175 |
super(TestUnsupportedViews, self).setUp() |
4032.1.2
by John Arbash Meinel
Track down a few more files that have trailing whitespace. |
176 |
|
3586.1.4
by Ian Clatworthy
first cut at tree-level view tests |
177 |
def test_view_methods_raise(self): |
178 |
wt = self.make_branch_and_tree('wt') |
|
179 |
self.assertRaises(errors.ViewsNotSupported, |
|
180 |
wt.views.set_view_info, 'bar', {'bar': ['bars/']}) |
|
181 |
self.assertRaises(errors.ViewsNotSupported, |
|
182 |
wt.views.get_view_info) |
|
183 |
self.assertRaises(errors.ViewsNotSupported, |
|
184 |
wt.views.lookup_view, 'foo') |
|
185 |
self.assertRaises(errors.ViewsNotSupported, |
|
186 |
wt.views.set_view, 'foo', 'bar') |
|
187 |
self.assertRaises(errors.ViewsNotSupported, |
|
188 |
wt.views.delete_view, 'foo') |