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 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
18 |
from __future__ import absolute_import |
19 |
||
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
20 |
import os |
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
21 |
import re |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
22 |
import tempfile |
23 |
import gzip |
|
24 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
25 |
from .... import tests |
26 |
from ....tests.blackbox import ExternalBase |
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
27 |
|
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
28 |
from ..cmds import ( |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
29 |
_get_source_stream, |
30 |
)
|
|
31 |
||
|
6628.1.2
by Jelmer Vernooij
Fix imports, move exporter.py, drop explorer metadata. |
32 |
from . import ( |
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
33 |
FastimportFeature, |
34 |
)
|
|
35 |
||
36 |
||
37 |
class TestSourceStream(tests.TestCase): |
|
38 |
||
39 |
_test_needs_features = [FastimportFeature] |
|
40 |
||
41 |
def test_get_source_stream_stdin(self): |
|
42 |
# - returns standard in
|
|
43 |
self.assertIsNot(None, _get_source_stream("-")) |
|
44 |
||
45 |
def test_get_source_gz(self): |
|
46 |
# files ending in .gz are automatically decompressed.
|
|
47 |
fd, filename = tempfile.mkstemp(suffix=".gz") |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
48 |
with gzip.GzipFile(fileobj=os.fdopen(fd, "wb"), mode='wb') as f: |
49 |
f.write(b"bla") |
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
50 |
stream = _get_source_stream(filename) |
51 |
self.assertIsNot("bla", stream.read()) |
|
52 |
||
53 |
def test_get_source_file(self): |
|
54 |
# other files are opened as regular files.
|
|
55 |
fd, filename = tempfile.mkstemp() |
|
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
56 |
with os.fdopen(fd, 'wb') as f: |
57 |
f.write(b"bla") |
|
|
0.64.281
by Jelmer Vernooij
Add tests for _get_source_stream. |
58 |
stream = _get_source_stream(filename) |
|
7027.2.1
by Jelmer Vernooij
Port fastimport to python3. |
59 |
self.assertIsNot(b"bla", stream.read()) |
60 |
||
61 |
||
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
62 |
fast_export_baseline_data = """commit refs/heads/master |
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
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 |
||
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
96 |
class TestFastExport(ExternalBase): |
97 |
||
|
6628.1.5
by Jelmer Vernooij
Consistently use fastimport feature. |
98 |
_test_needs_features = [FastimportFeature] |
99 |
||
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
100 |
def test_empty(self): |
101 |
self.make_branch_and_tree("br") |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
102 |
self.assertEquals("", self.run_bzr("fast-export br")[0]) |
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
103 |
|
104 |
def test_pointless(self): |
|
105 |
tree = self.make_branch_and_tree("br") |
|
106 |
tree.commit("pointless") |
|
107 |
data = self.run_bzr("fast-export br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
108 |
self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter')) |
|
0.64.309
by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'. |
109 |
|
110 |
def test_file(self): |
|
111 |
tree = self.make_branch_and_tree("br") |
|
112 |
tree.commit("pointless") |
|
113 |
data = self.run_bzr("fast-export br br.fi")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
114 |
self.assertEquals("", data) |
|
0.64.314
by Jelmer Vernooij
Use TestCase.assertPathExists if available (fix deprecation warning with bzr 2.4) |
115 |
try: |
116 |
self.assertPathExists("br.fi") |
|
117 |
except AttributeError: # bzr < 2.4 |
|
118 |
self.failUnlessExists("br.fi") |
|
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
119 |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
120 |
def test_tag_rewriting(self): |
121 |
tree = self.make_branch_and_tree("br") |
|
122 |
tree.commit("pointless") |
|
123 |
self.assertTrue(tree.branch.supports_tags()) |
|
124 |
rev_id = tree.branch.dotted_revno_to_revision_id((1,)) |
|
125 |
tree.branch.tags.set_tag("goodTag", rev_id) |
|
126 |
tree.branch.tags.set_tag("bad Tag", rev_id) |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
127 |
|
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
128 |
# first check --no-rewrite-tag-names
|
129 |
data = self.run_bzr("fast-export --plain --no-rewrite-tag-names br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
130 |
self.assertNotEqual(-1, data.find("reset refs/tags/goodTag")) |
131 |
self.assertEqual(data.find("reset refs/tags/"), data.rfind("reset refs/tags/")) |
|
132 |
||
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
133 |
# and now with --rewrite-tag-names
|
134 |
data = self.run_bzr("fast-export --plain --rewrite-tag-names br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
135 |
self.assertNotEqual(-1, data.find("reset refs/tags/goodTag")) |
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
136 |
# "bad Tag" should be exported as bad_Tag
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
137 |
self.assertNotEqual(-1, data.find("reset refs/tags/bad_Tag")) |
|
0.133.3
by Oleksandr Usov
Implement comments from patch review: |
138 |
|
|
0.138.2
by Oleksandr Usov
Add unit test for --no-tags |
139 |
def test_no_tags(self): |
140 |
tree = self.make_branch_and_tree("br") |
|
141 |
tree.commit("pointless") |
|
142 |
self.assertTrue(tree.branch.supports_tags()) |
|
143 |
rev_id = tree.branch.dotted_revno_to_revision_id((1,)) |
|
144 |
tree.branch.tags.set_tag("someTag", rev_id) |
|
145 |
||
146 |
data = self.run_bzr("fast-export --plain --no-tags br")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
147 |
self.assertEqual(-1, data.find("reset refs/tags/someTag")) |
|
0.138.2
by Oleksandr Usov
Add unit test for --no-tags |
148 |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
149 |
def test_baseline_option(self): |
150 |
tree = self.make_branch_and_tree("bl") |
|
151 |
||
152 |
# Revision 1
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
153 |
with open('bl/a', 'w') as f: |
154 |
f.write('test 1') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
155 |
tree.add('a') |
156 |
tree.commit(message='add a') |
|
157 |
||
158 |
# Revision 2
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
159 |
with open('bl/b', 'w') as f: |
160 |
f.write('test 2') |
|
161 |
with open('bl/a', 'a') as f: |
|
162 |
f.write('\ntest 3') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
163 |
tree.add('b') |
164 |
tree.commit(message='add b, modify a') |
|
165 |
||
166 |
# Revision 3
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
167 |
with open('bl/c', 'w') as f: |
168 |
f.write('test 4') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
169 |
tree.add('c') |
170 |
tree.remove('b') |
|
171 |
tree.commit(message='add c, remove b') |
|
172 |
||
173 |
# Revision 4
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
174 |
with open('bl/a', 'a') as f: |
175 |
f.write('\ntest 5') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
176 |
tree.commit(message='modify a again') |
177 |
||
178 |
# Revision 5
|
|
|
6973.7.5
by Jelmer Vernooij
s/file/open. |
179 |
with open('bl/d', 'w') as f: |
180 |
f.write('test 6') |
|
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
181 |
tree.add('d') |
182 |
tree.commit(message='add d') |
|
183 |
||
184 |
# This exports the baseline state at Revision 3,
|
|
185 |
# followed by the deltas for 4 and 5
|
|
186 |
data = self.run_bzr("fast-export --baseline -r 3.. bl")[0] |
|
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
187 |
data = re.sub('committer.*', 'committer', data) |
|
0.135.2
by Andy Grimm
fix --baseline bugs, and add a couple of tests |
188 |
self.assertEquals(fast_export_baseline_data, data) |
189 |
||
190 |
# Also confirm that --baseline with no args is identical to full export
|
|
191 |
data1 = self.run_bzr("fast-export --baseline bl")[0] |
|
192 |
data2 = self.run_bzr("fast-export bl")[0] |
|
193 |
self.assertEquals(data1, data2) |
|
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
194 |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
195 |
simple_fast_import_stream = b"""commit refs/heads/master |
|
0.64.310
by Jelmer Vernooij
Fix fast-import-info. |
196 |
mark :1
|
197 |
committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
|
|
198 |
data 7
|
|
199 |
initial
|
|
200 |
||
201 |
"""
|
|
202 |
||
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
203 |
|
204 |
class TestFastImport(ExternalBase): |
|
205 |
||
|
6628.1.5
by Jelmer Vernooij
Consistently use fastimport feature. |
206 |
_test_needs_features = [FastimportFeature] |
207 |
||
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
208 |
def test_empty(self): |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
209 |
self.build_tree_contents([('empty.fi', b"")]) |
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
210 |
self.make_branch_and_tree("br") |
|
7027.4.2
by Jelmer Vernooij
Use StringIOWithEncoding in run_bzr. |
211 |
self.assertEquals("", self.run_bzr("fast-import empty.fi br")[0]) |
|
0.131.1
by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'. |
212 |
|
213 |
def test_file(self): |
|
214 |
tree = self.make_branch_and_tree("br") |
|
215 |
self.build_tree_contents([('file.fi', simple_fast_import_stream)]) |
|
216 |
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. |
217 |
self.assertEquals(1, tree.branch.revno()) |
|
0.64.321
by Jelmer Vernooij
Allow fast-import-filter to be used without first argument. |
218 |
|
|
0.64.355
by Jelmer Vernooij
Print sane error when a fastimport file is incomplete. |
219 |
def test_missing_bytes(self): |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
220 |
self.build_tree_contents([('empty.fi', b""" |
|
0.64.355
by Jelmer Vernooij
Print sane error when a fastimport file is incomplete. |
221 |
commit refs/heads/master
|
222 |
mark :1
|
|
223 |
committer
|
|
224 |
data 15
|
|
225 |
""")]) |
|
226 |
self.make_branch_and_tree("br") |
|
|
7045.1.1
by Jelmer Vernooij
Fix another 300 tests. |
227 |
self.run_bzr_error(['brz: ERROR: 4: Parse error: line 4: Command .*commit.* is missing section .*committer.*\n'], "fast-import empty.fi br") |
|
0.64.355
by Jelmer Vernooij
Print sane error when a fastimport file is incomplete. |
228 |