0.1.238
by Alexander Belchenko
util.py: new helper function file_extension() as much smarter os.path.splitext()[1]. +test |
1 |
# -*- coding: utf-8 -*-
|
2 |
#
|
|
3 |
# Copyright (C) 2008 Alexander Belchenko
|
|
4 |
#
|
|
5 |
# This program is free software; you can redistribute it and/or
|
|
6 |
# modify it under the terms of the GNU General Public License
|
|
7 |
# as published by the Free Software Foundation; either version 2
|
|
8 |
# of the License, or (at your option) any later version.
|
|
9 |
#
|
|
10 |
# This program is distributed in the hope that it will be useful,
|
|
11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
# GNU General Public License for more details.
|
|
14 |
#
|
|
15 |
# You should have received a copy of the GNU General Public License
|
|
16 |
# along with this program; if not, write to the Free Software
|
|
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
18 |
||
19 |
"""Tests for QBzr plugin."""
|
|
20 |
||
0.1.477
by Alexander Belchenko
util.py: new helper method url_for_display() |
21 |
import sys |
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
22 |
|
0.168.34
by Gary van der Merwe
Merge Fix isolation breaks by allowing the smallest possible access. (vila) (Cherrypick of trunk rev 992) |
23 |
from bzrlib import ( |
24 |
errors, |
|
25 |
tests, |
|
26 |
)
|
|
27 |
from bzrlib.transport import memory |
|
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
28 |
|
0.264.1
by Vincent Ladeuil
Allow tests to be run with --parallel=fork. |
29 |
from bzrlib.plugins.qbzr.lib import ( |
30 |
tests as qtests, |
|
31 |
util, |
|
32 |
)
|
|
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
33 |
from bzrlib.plugins.qbzr.lib.tests import mock |
0.1.238
by Alexander Belchenko
util.py: new helper function file_extension() as much smarter os.path.splitext()[1]. +test |
34 |
|
35 |
||
0.264.1
by Vincent Ladeuil
Allow tests to be run with --parallel=fork. |
36 |
class TestUtil(qtests.QTestCase): |
0.1.238
by Alexander Belchenko
util.py: new helper function file_extension() as much smarter os.path.splitext()[1]. +test |
37 |
|
38 |
def test_file_extension(self): |
|
39 |
self.assertEquals('', util.file_extension('')) |
|
40 |
self.assertEquals('', util.file_extension('/foo/bar.x/')) |
|
41 |
self.assertEquals('', util.file_extension('C:/foo/bar.x/')) |
|
42 |
self.assertEquals('', util.file_extension('.bzrignore')) |
|
43 |
self.assertEquals('', util.file_extension('/foo/bar.x/.bzrignore')) |
|
44 |
self.assertEquals('.txt', util.file_extension('foo.txt')) |
|
45 |
self.assertEquals('.txt', util.file_extension('/foo/bar.x/foo.txt')) |
|
0.1.246
by Alexander Belchenko
qdiff: options to filter diff output (to see added/deleted/modified/renamed files in any combination) |
46 |
|
47 |
def test_filter_options(self): |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
48 |
fo = util.FilterOptions() |
49 |
self.assertEquals(False, bool(fo)) |
|
50 |
self.assertEquals(False, fo.is_all_enable()) |
|
51 |
self.assertEquals('', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
52 |
self.assertEquals(False, fo.check('added')) |
53 |
self.assertEquals(False, fo.check('removed')) |
|
54 |
self.assertEquals(False, fo.check('deleted')) |
|
55 |
self.assertEquals(False, fo.check('renamed')) |
|
56 |
self.assertEquals(False, fo.check('modified')) |
|
57 |
self.assertEquals(False, fo.check('renamed and modified')) |
|
58 |
self.assertRaises(ValueError, fo.check, 'spam') |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
59 |
|
60 |
fo = util.FilterOptions(deleted=True) |
|
61 |
self.assertEquals(True, bool(fo)) |
|
62 |
self.assertEquals(False, fo.is_all_enable()) |
|
63 |
self.assertEquals('deleted files', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
64 |
self.assertEquals(False, fo.check('added')) |
65 |
self.assertEquals(True, fo.check('removed')) |
|
66 |
self.assertEquals(True, fo.check('deleted')) |
|
67 |
self.assertEquals(False, fo.check('renamed')) |
|
68 |
self.assertEquals(False, fo.check('modified')) |
|
69 |
self.assertEquals(False, fo.check('renamed and modified')) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
70 |
|
71 |
fo = util.FilterOptions(added=True) |
|
72 |
self.assertEquals(True, bool(fo)) |
|
73 |
self.assertEquals(False, fo.is_all_enable()) |
|
74 |
self.assertEquals('added files', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
75 |
self.assertEquals(True, fo.check('added')) |
76 |
self.assertEquals(False, fo.check('removed')) |
|
77 |
self.assertEquals(False, fo.check('deleted')) |
|
78 |
self.assertEquals(False, fo.check('renamed')) |
|
79 |
self.assertEquals(False, fo.check('modified')) |
|
80 |
self.assertEquals(False, fo.check('renamed and modified')) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
81 |
|
82 |
fo = util.FilterOptions(renamed=True) |
|
83 |
self.assertEquals(True, bool(fo)) |
|
84 |
self.assertEquals(False, fo.is_all_enable()) |
|
85 |
self.assertEquals('renamed files', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
86 |
self.assertEquals(False, fo.check('added')) |
87 |
self.assertEquals(False, fo.check('removed')) |
|
88 |
self.assertEquals(False, fo.check('deleted')) |
|
89 |
self.assertEquals(True, fo.check('renamed')) |
|
90 |
self.assertEquals(False, fo.check('modified')) |
|
91 |
self.assertEquals(True, fo.check('renamed and modified')) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
92 |
|
93 |
fo = util.FilterOptions(modified=True) |
|
94 |
self.assertEquals(True, bool(fo)) |
|
95 |
self.assertEquals(False, fo.is_all_enable()) |
|
96 |
self.assertEquals('modified files', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
97 |
self.assertEquals(False, fo.check('added')) |
98 |
self.assertEquals(False, fo.check('removed')) |
|
99 |
self.assertEquals(False, fo.check('deleted')) |
|
100 |
self.assertEquals(False, fo.check('renamed')) |
|
101 |
self.assertEquals(True, fo.check('modified')) |
|
102 |
self.assertEquals(True, fo.check('renamed and modified')) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
103 |
|
104 |
fo = util.FilterOptions(added=True, deleted=True, modified=True, |
|
105 |
renamed=True) |
|
106 |
self.assertEquals(True, bool(fo)) |
|
107 |
self.assertEquals(True, fo.is_all_enable()) |
|
108 |
self.assertEquals('deleted files, added files, ' |
|
109 |
'renamed files, modified files', fo.to_str()) |
|
0.1.314
by Alexander Belchenko
Restore filter options for qdiff. |
110 |
self.assertEquals(True, fo.check('added')) |
111 |
self.assertEquals(True, fo.check('removed')) |
|
112 |
self.assertEquals(True, fo.check('deleted')) |
|
113 |
self.assertEquals(True, fo.check('renamed')) |
|
114 |
self.assertEquals(True, fo.check('modified')) |
|
115 |
self.assertEquals(True, fo.check('renamed and modified')) |
|
116 |
||
117 |
fo = util.FilterOptions(all_enable=True) |
|
118 |
self.assertEquals(True, bool(fo)) |
|
119 |
self.assertEquals(True, fo.is_all_enable()) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
120 |
|
0.1.246
by Alexander Belchenko
qdiff: options to filter diff output (to see added/deleted/modified/renamed files in any combination) |
121 |
fo = util.FilterOptions() |
122 |
fo.all_enable() |
|
123 |
self.assertEquals(True, bool(fo)) |
|
0.1.248
by Alexander Belchenko
qdiff: show filter options in window title |
124 |
self.assertEquals(True, fo.is_all_enable()) |
0.1.477
by Alexander Belchenko
util.py: new helper method url_for_display() |
125 |
|
126 |
def test_url_for_display(self): |
|
127 |
self.assertEquals(None, util.url_for_display(None)) |
|
128 |
self.assertEquals('', util.url_for_display('')) |
|
129 |
self.assertEquals('http://bazaar.launchpad.net/~qbzr-dev/qbzr/trunk', |
|
130 |
util.url_for_display('http://bazaar.launchpad.net/%7Eqbzr-dev/qbzr/trunk')) |
|
131 |
if sys.platform == 'win32': |
|
132 |
self.assertEquals('C:/work/qbzr/', |
|
133 |
util.url_for_display('file:///C:/work/qbzr/')) |
|
134 |
else: |
|
135 |
self.assertEquals('/home/work/qbzr/', |
|
136 |
util.url_for_display('file:///home/work/qbzr/')) |
|
0.1.513
by Lukáš Lalinský
HTML-encode ", too, otherwise it breaks text in title="..." |
137 |
|
0.1.523
by Alexander Belchenko
util.py: new helper function is_binary_content() check entire [file] content for presence of 0x00 byte (not only first 1K as bzrlib's check_text_lines did). |
138 |
def test_is_binary_content(self): |
139 |
self.assertEquals(False, util.is_binary_content([])) |
|
140 |
self.assertEquals(False, util.is_binary_content(['foo\n', 'bar\r\n', 'spam\r'])) |
|
141 |
self.assertEquals(True, util.is_binary_content(['\x00'])) |
|
142 |
self.assertEquals(True, util.is_binary_content(['a'*2048 + '\x00'])) |
|
0.95.1
by jszakmeister
Fix all occurrences of revision.get_summary() to use a new util method. This (partially) fixes a backtrace when using bzr qlog against a remote SVN repository. |
143 |
|
144 |
def test_get_summary(self): |
|
145 |
import bzrlib.revision |
|
146 |
||
147 |
r = bzrlib.revision.Revision('1') |
|
148 |
||
149 |
r.message = None |
|
150 |
self.assertEquals('(no message)', util.get_summary(r)) |
|
151 |
||
152 |
r.message = '' |
|
153 |
self.assertEquals('(no message)', util.get_summary(r)) |
|
154 |
||
0.95.3
by jszakmeister
Add another test case for get_summary(). |
155 |
r.message = 'message' |
156 |
self.assertEquals('message', util.get_summary(r)) |
|
157 |
||
0.95.2
by jszakmeister
Stop backtracing in qlog when there is no message set on the revision. |
158 |
def test_get_message(self): |
159 |
import bzrlib.revision |
|
160 |
||
161 |
r = bzrlib.revision.Revision('1') |
|
162 |
||
163 |
r.message = None |
|
164 |
self.assertEquals('(no message)', util.get_message(r)) |
|
165 |
||
166 |
r.message = 'message' |
|
167 |
self.assertEquals('message', util.get_message(r)) |
|
168 |
||
0.1.755
by Alexander Belchenko
progress bar messages should be unicode strings (to use in PyQt) |
169 |
def test_ensure_unicode(self): |
170 |
self.assertEqual(u'foo', util.ensure_unicode('foo')) |
|
171 |
self.assertEqual(u'foo', util.ensure_unicode(u'foo')) |
|
172 |
self.assertEqual(u'\u1234', util.ensure_unicode(u'\u1234')) |
|
173 |
self.assertEqual(1, util.ensure_unicode(1)) |
|
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
174 |
|
0.214.4
by Alexander Belchenko
added platform dependent shlex_split_unicode which takes care about \ in windows paths. |
175 |
def test__shlex_split_unicode_linux(self): |
176 |
self.assertEquals([u'foo/bar', u'\u1234'], |
|
177 |
util._shlex_split_unicode_linux(u"foo/bar \u1234")) |
|
178 |
||
179 |
def test__shlex_split_unicode_windows(self): |
|
180 |
self.assertEquals([u'C:\\foo\\bar', u'\u1234'], |
|
181 |
util._shlex_split_unicode_windows(u"C:\\foo\\bar \u1234")) |
|
182 |
||
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
183 |
|
0.168.34
by Gary van der Merwe
Merge Fix isolation breaks by allowing the smallest possible access. (vila) (Cherrypick of trunk rev 992) |
184 |
class TestOpenTree(tests.TestCaseWithTransport): |
185 |
||
186 |
def test_no_ui_mode_no_branch(self): |
|
187 |
self.vfs_transport_factory = memory.MemoryServer |
|
188 |
mf = mock.MockFunction() |
|
189 |
self.assertRaises(errors.NotBranchError, |
|
190 |
util.open_tree, self.get_url('non/existent/path'), |
|
191 |
ui_mode=False, _critical_dialog=mf) |
|
192 |
self.assertEqual(0, mf.count) |
|
0.170.1
by Vincent Ladeuil
Fix isolation breaks by allowing the smallest possible access. |
193 |
|
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
194 |
def test_no_ui_mode(self): |
195 |
mf = mock.MockFunction() |
|
196 |
self.make_branch('a') |
|
197 |
self.assertRaises(errors.NoWorkingTree, |
|
198 |
util.open_tree, 'a', ui_mode=False, _critical_dialog=mf) |
|
199 |
self.assertEqual(0, mf.count) |
|
200 |
#
|
|
201 |
self.make_branch_and_tree('b') |
|
202 |
tree = util.open_tree('b', ui_mode=False, _critical_dialog=mf) |
|
203 |
self.assertNotEqual(None, tree) |
|
204 |
self.assertEqual(0, mf.count) |
|
205 |
||
0.168.34
by Gary van der Merwe
Merge Fix isolation breaks by allowing the smallest possible access. (vila) (Cherrypick of trunk rev 992) |
206 |
def test_ui_mode_no_branch(self): |
207 |
self.vfs_transport_factory = memory.MemoryServer |
|
208 |
mf = mock.MockFunction() |
|
209 |
tree = util.open_tree(self.get_url('/non/existent/path'), |
|
210 |
ui_mode=True, _critical_dialog=mf) |
|
211 |
self.assertEqual(None, tree) |
|
212 |
self.assertEqual(1, mf.count) |
|
213 |
||
0.103.3
by Alexander Belchenko
tests for open_tree with MockFunction. |
214 |
def test_ui_mode(self): |
215 |
mf = mock.MockFunction() |
|
216 |
self.make_branch('a') |
|
217 |
mf = mock.MockFunction() |
|
218 |
tree = util.open_tree('a', ui_mode=True, _critical_dialog=mf) |
|
219 |
self.assertEqual(None, tree) |
|
220 |
self.assertEqual(1, mf.count) |
|
221 |
#
|
|
222 |
self.make_branch_and_tree('b') |
|
223 |
mf = mock.MockFunction() |
|
224 |
tree = util.open_tree('b', ui_mode=False, _critical_dialog=mf) |
|
225 |
self.assertNotEqual(None, tree) |
|
226 |
self.assertEqual(0, mf.count) |