/brz/remove-bazaar

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