bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
1 |
# Copyright (C) 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
|
|
|
0.64.334
by Jelmer Vernooij
Remove old FSF address. Thanks Dan Callaghan. |
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
15 |
|
16 |
"""Test the command implementations."""
|
|
17 |
||
18 |
import os |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
19 |
import re |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
20 |
import tempfile |
21 |
import gzip |
|
22 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
23 |
from .... import tests |
|
7290.43.1
by Jelmer Vernooij
Fx symlink fastexporting on Python 3. |
24 |
from ....tests import features |
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
25 |
from ....tests.blackbox import ExternalBase |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
26 |
|
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
27 |
from ..cmds import ( |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
28 |
_get_source_stream, |
29 |
)
|
|
30 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
31 |
from . import ( |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
32 |
FastimportFeature, |
33 |
)
|
|
34 |
||
35 |
||
36 |
class TestSourceStream(tests.TestCase): |
|
37 |
||
38 |
_test_needs_features = [FastimportFeature] |
|
39 |
||
40 |
def test_get_source_stream_stdin(self): |
|
41 |
# - returns standard in
|
|
42 |
self.assertIsNot(None, _get_source_stream("-")) |
|
43 |
||
44 |
def test_get_source_gz(self): |
|
45 |
# files ending in .gz are automatically decompressed.
|
|
46 |
fd, filename = tempfile.mkstemp(suffix=".gz") |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
47 |
with gzip.GzipFile(fileobj=os.fdopen(fd, "wb"), mode='wb') as f: |
48 |
f.write(b"bla") |
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
49 |
stream = _get_source_stream(filename) |
50 |
self.assertIsNot("bla", stream.read()) |
|
51 |
||
52 |
def test_get_source_file(self): |
|
53 |
# other files are opened as regular files.
|
|
54 |
fd, filename = tempfile.mkstemp() |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
55 |
with os.fdopen(fd, 'wb') as f: |
56 |
f.write(b"bla") |
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
57 |
stream = _get_source_stream(filename) |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
58 |
self.assertIsNot(b"bla", stream.read()) |
59 |
||
60 |
||
|
7222.1.1
by Jelmer Vernooij
Fix a spurious test. |
61 |
fast_export_baseline_data1 = """reset refs/heads/master |
62 |
commit refs/heads/master
|
|
63 |
mark :1
|
|
64 |
committer
|
|
65 |
data 15
|
|
66 |
add c, remove b
|
|
67 |
M 644 inline a
|
|
68 |
data 13
|
|
69 |
test 1
|
|
70 |
test 3
|
|
71 |
M 644 inline c
|
|
72 |
data 6
|
|
73 |
test 4
|
|
74 |
commit refs/heads/master
|
|
75 |
mark :2
|
|
76 |
committer
|
|
77 |
data 14
|
|
78 |
modify a again
|
|
79 |
from :1
|
|
80 |
M 644 inline a
|
|
81 |
data 20
|
|
82 |
test 1
|
|
83 |
test 3
|
|
84 |
test 5
|
|
85 |
commit refs/heads/master
|
|
86 |
mark :3
|
|
87 |
committer
|
|
88 |
data 5
|
|
89 |
add d
|
|
90 |
from :2
|
|
91 |
M 644 inline d
|
|
92 |
data 6
|
|
93 |
test 6
|
|
94 |
"""
|
|
95 |
||
96 |
||
97 |
fast_export_baseline_data2 = """reset refs/heads/master |
|
98 |
commit refs/heads/master
|
|
99 |
mark :1
|
|
100 |
committer
|
|
101 |
data 15
|
|
102 |
add c, remove b
|
|
103 |
M 644 inline c
|
|
104 |
data 6
|
|
105 |
test 4
|
|
106 |
M 644 inline a
|
|
107 |
data 13
|
|
108 |
test 1
|
|
109 |
test 3
|
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
110 |
commit refs/heads/master
|
111 |
mark :2
|
|
112 |
committer
|
|
113 |
data 14
|
|
114 |
modify a again
|
|
115 |
from :1
|
|
116 |
M 644 inline a
|
|
117 |
data 20
|
|
118 |
test 1
|
|
119 |
test 3
|
|
120 |
test 5
|
|
121 |
commit refs/heads/master
|
|
122 |
mark :3
|
|
123 |
committer
|
|
124 |
data 5
|
|
125 |
add d
|
|
126 |
from :2
|
|
127 |
M 644 inline d
|
|
128 |
data 6
|
|
129 |
test 6
|
|
130 |
"""
|
|
131 |
||
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
132 |
|
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
133 |
class TestFastExport(ExternalBase): |
134 |
||
|
6628.1.5
by Jelmer Vernooij
Consistently use fastimport feature. |
135 |
_test_needs_features = [FastimportFeature] |
136 |
||
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
137 |
def test_empty(self): |
138 |
self.make_branch_and_tree("br") |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
139 |
self.assertEquals("", self.run_bzr("fast-export br")[0]) |
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
140 |
|
141 |
def test_pointless(self): |
|
142 |
tree = self.make_branch_and_tree("br") |
|
143 |
tree.commit("pointless") |
|
144 |
data = self.run_bzr("fast-export br")[0] |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
145 |
self.assertTrue(data.startswith( |
|
7194.1.2
by Jelmer Vernooij
Fix test. |
146 |
'reset refs/heads/master\n' |
147 |
'commit refs/heads/master\n' |
|
|
7194.1.1
by Jelmer Vernooij
Merge lp:~a-s-usov/bzr-fastimport/no-temp-branches |
148 |
'mark :1\ncommitter'), data) |
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
149 |
|
150 |
def test_file(self): |
|
151 |
tree = self.make_branch_and_tree("br") |
|
152 |
tree.commit("pointless") |
|
153 |
data = self.run_bzr("fast-export br br.fi")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
154 |
self.assertEquals("", data) |
|
7194.1.1
by Jelmer Vernooij
Merge lp:~a-s-usov/bzr-fastimport/no-temp-branches |
155 |
self.assertPathExists("br.fi") |
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
156 |
|
|
7290.43.1
by Jelmer Vernooij
Fx symlink fastexporting on Python 3. |
157 |
def test_symlink(self): |
158 |
tree = self.make_branch_and_tree("br") |
|
159 |
self.requireFeature(features.SymlinkFeature) |
|
160 |
os.symlink('symlink-target', 'br/symlink') |
|
161 |
tree.add('symlink') |
|
162 |
tree.commit("add a symlink") |
|
163 |
data = self.run_bzr("fast-export br br.fi")[0] |
|
164 |
self.assertEquals("", data) |
|
165 |
self.assertPathExists("br.fi") |
|
166 |
||
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
167 |
def test_tag_rewriting(self): |
168 |
tree = self.make_branch_and_tree("br") |
|
169 |
tree.commit("pointless") |
|
170 |
self.assertTrue(tree.branch.supports_tags()) |
|
171 |
rev_id = tree.branch.dotted_revno_to_revision_id((1,)) |
|
172 |
tree.branch.tags.set_tag("goodTag", rev_id) |
|
173 |
tree.branch.tags.set_tag("bad Tag", rev_id) |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
174 |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
175 |
# first check --no-rewrite-tag-names
|
176 |
data = self.run_bzr("fast-export --plain --no-rewrite-tag-names br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
177 |
self.assertNotEqual(-1, data.find("reset refs/tags/goodTag")) |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
178 |
self.assertEqual(data.find("reset refs/tags/"), |
179 |
data.rfind("reset refs/tags/")) |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
180 |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
181 |
# and now with --rewrite-tag-names
|
182 |
data = self.run_bzr("fast-export --plain --rewrite-tag-names br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
183 |
self.assertNotEqual(-1, data.find("reset refs/tags/goodTag")) |
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
184 |
# "bad Tag" should be exported as bad_Tag
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
185 |
self.assertNotEqual(-1, data.find("reset refs/tags/bad_Tag")) |
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
186 |
|
|
0.138.2
by Oleksandr Usov
Add unit test for --no-tags |
187 |
def test_no_tags(self): |
188 |
tree = self.make_branch_and_tree("br") |
|
189 |
tree.commit("pointless") |
|
190 |
self.assertTrue(tree.branch.supports_tags()) |
|
191 |
rev_id = tree.branch.dotted_revno_to_revision_id((1,)) |
|
192 |
tree.branch.tags.set_tag("someTag", rev_id) |
|
193 |
||
194 |
data = self.run_bzr("fast-export --plain --no-tags br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
195 |
self.assertEqual(-1, data.find("reset refs/tags/someTag")) |
|
0.138.2
by Oleksandr Usov
Add unit test for --no-tags |
196 |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
197 |
def test_baseline_option(self): |
198 |
tree = self.make_branch_and_tree("bl") |
|
199 |
||
200 |
# Revision 1
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
201 |
with open('bl/a', 'w') as f: |
202 |
f.write('test 1') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
203 |
tree.add('a') |
204 |
tree.commit(message='add a') |
|
205 |
||
206 |
# Revision 2
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
207 |
with open('bl/b', 'w') as f: |
208 |
f.write('test 2') |
|
209 |
with open('bl/a', 'a') as f: |
|
210 |
f.write('\ntest 3') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
211 |
tree.add('b') |
212 |
tree.commit(message='add b, modify a') |
|
213 |
||
214 |
# Revision 3
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
215 |
with open('bl/c', 'w') as f: |
216 |
f.write('test 4') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
217 |
tree.add('c') |
218 |
tree.remove('b') |
|
219 |
tree.commit(message='add c, remove b') |
|
220 |
||
221 |
# Revision 4
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
222 |
with open('bl/a', 'a') as f: |
223 |
f.write('\ntest 5') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
224 |
tree.commit(message='modify a again') |
225 |
||
226 |
# Revision 5
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
227 |
with open('bl/d', 'w') as f: |
228 |
f.write('test 6') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
229 |
tree.add('d') |
230 |
tree.commit(message='add d') |
|
231 |
||
232 |
# This exports the baseline state at Revision 3,
|
|
233 |
# followed by the deltas for 4 and 5
|
|
234 |
data = self.run_bzr("fast-export --baseline -r 3.. bl")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
235 |
data = re.sub('committer.*', 'committer', data) |
|
7222.1.1
by Jelmer Vernooij
Fix a spurious test. |
236 |
self.assertIn(data, (fast_export_baseline_data1, fast_export_baseline_data2)) |
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
237 |
|
238 |
# Also confirm that --baseline with no args is identical to full export
|
|
239 |
data1 = self.run_bzr("fast-export --baseline bl")[0] |
|
240 |
data2 = self.run_bzr("fast-export bl")[0] |
|
241 |
self.assertEquals(data1, data2) |
|
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
242 |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
243 |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
244 |
simple_fast_import_stream = b"""commit refs/heads/master |
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
245 |
mark :1
|
246 |
committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
|
|
247 |
data 7
|
|
248 |
initial
|
|
249 |
||
250 |
"""
|
|
251 |
||
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
252 |
|
253 |
class TestFastImport(ExternalBase): |
|
254 |
||
|
6628.1.5
by Jelmer Vernooij
Consistently use fastimport feature. |
255 |
_test_needs_features = [FastimportFeature] |
256 |
||
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
257 |
def test_empty(self): |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
258 |
self.build_tree_contents([('empty.fi', b"")]) |
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
259 |
self.make_branch_and_tree("br") |
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
260 |
self.assertEquals("", self.run_bzr("fast-import empty.fi br")[0]) |
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
261 |
|
262 |
def test_file(self): |
|
263 |
tree = self.make_branch_and_tree("br") |
|
264 |
self.build_tree_contents([('file.fi', simple_fast_import_stream)]) |
|
265 |
data = self.run_bzr("fast-import file.fi br")[0] |
|
|
0.131.2
by Jelmer Vernooij
Fix 'bzr fast-import' bzrdir argument and add a blackbox test. |
266 |
self.assertEquals(1, tree.branch.revno()) |
|
0.64.321
by Jelmer Vernooij
Allow fast-import-filter to be used without first argument. |
267 |
|
|
0.64.355
by Jelmer Vernooij
Print sane error when a fastimport file is incomplete. |
268 |
def test_missing_bytes(self): |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
269 |
self.build_tree_contents([('empty.fi', b""" |
|
0.64.355
by Jelmer Vernooij
Print sane error when a fastimport file is incomplete. |
270 |
commit refs/heads/master
|
271 |
mark :1
|
|
272 |
committer
|
|
273 |
data 15
|
|
274 |
""")]) |
|
275 |
self.make_branch_and_tree("br") |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
276 |
self.run_bzr_error( |
277 |
['brz: ERROR: 4: Parse error: line 4: Command .*commit.* is missing section .*committer.*\n'], "fast-import empty.fi br") |