/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
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")
48
        f = gzip.GzipFile(fileobj=os.fdopen(fd, "w"), mode='w')
49
        f.write("bla")
50
        f.close()
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()
57
        f = os.fdopen(fd, 'w')
58
        f.write("bla")
59
        f.close()
60
        stream = _get_source_stream(filename)
61
        self.assertIsNot("bla", stream.read())
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
62
63
0.135.2 by Andy Grimm
fix --baseline bugs, and add a couple of tests
64
fast_export_baseline_data = """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
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
98
class TestFastExport(ExternalBase):
99
6628.1.5 by Jelmer Vernooij
Consistently use fastimport feature.
100
    _test_needs_features = [FastimportFeature]
101
0.64.309 by Jelmer Vernooij
Add some blackbox tests for 'bzr fast-export'.
102
    def test_empty(self):
103
        self.make_branch_and_tree("br")
104
        self.assertEquals("", self.run_bzr("fast-export br")[0])
105
106
    def test_pointless(self):
107
        tree = self.make_branch_and_tree("br")
108
        tree.commit("pointless")
109
        data = self.run_bzr("fast-export br")[0]
110
        self.assertTrue(data.startswith('commit refs/heads/master\nmark :1\ncommitter'))
111
112
    def test_file(self):
113
        tree = self.make_branch_and_tree("br")
114
        tree.commit("pointless")
115
        data = self.run_bzr("fast-export br br.fi")[0]
116
        self.assertEquals("", data)
0.64.314 by Jelmer Vernooij
Use TestCase.assertPathExists if available (fix deprecation warning with bzr 2.4)
117
        try:
118
            self.assertPathExists("br.fi")
119
        except AttributeError: # bzr < 2.4
120
            self.failUnlessExists("br.fi")
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
121
0.133.3 by Oleksandr Usov
Implement comments from patch review:
122
    def test_tag_rewriting(self):
123
        tree = self.make_branch_and_tree("br")
124
        tree.commit("pointless")
125
        self.assertTrue(tree.branch.supports_tags())
126
        rev_id = tree.branch.dotted_revno_to_revision_id((1,))
127
        tree.branch.tags.set_tag("goodTag", rev_id)
128
        tree.branch.tags.set_tag("bad Tag", rev_id)
129
        
130
        # first check --no-rewrite-tag-names
131
        data = self.run_bzr("fast-export --plain --no-rewrite-tag-names br")[0]
132
        self.assertNotEqual(-1, data.find("reset refs/tags/goodTag"))
133
        self.assertEqual(data.find("reset refs/tags/"), data.rfind("reset refs/tags/"))
134
        
135
        # and now with --rewrite-tag-names
136
        data = self.run_bzr("fast-export --plain --rewrite-tag-names br")[0]
137
        self.assertNotEqual(-1, data.find("reset refs/tags/goodTag"))
138
        # "bad Tag" should be exported as bad_Tag
139
        self.assertNotEqual(-1, data.find("reset refs/tags/bad_Tag"))
140
0.138.2 by Oleksandr Usov
Add unit test for --no-tags
141
    def test_no_tags(self):
142
        tree = self.make_branch_and_tree("br")
143
        tree.commit("pointless")
144
        self.assertTrue(tree.branch.supports_tags())
145
        rev_id = tree.branch.dotted_revno_to_revision_id((1,))
146
        tree.branch.tags.set_tag("someTag", rev_id)
147
148
        data = self.run_bzr("fast-export --plain --no-tags br")[0]
149
        self.assertEqual(-1, data.find("reset refs/tags/someTag"))
150
0.135.2 by Andy Grimm
fix --baseline bugs, and add a couple of tests
151
    def test_baseline_option(self):
152
        tree = self.make_branch_and_tree("bl")
153
154
        # Revision 1
155
        file('bl/a', 'w').write('test 1')
156
        tree.add('a')
157
        tree.commit(message='add a')
158
159
        # Revision 2
160
        file('bl/b', 'w').write('test 2')
161
        file('bl/a', 'a').write('\ntest 3')
162
        tree.add('b')
163
        tree.commit(message='add b, modify a')
164
165
        # Revision 3
166
        file('bl/c', 'w').write('test 4')
167
        tree.add('c')
168
        tree.remove('b')
169
        tree.commit(message='add c, remove b')
170
171
        # Revision 4
172
        file('bl/a', 'a').write('\ntest 5')
173
        tree.commit(message='modify a again')
174
175
        # Revision 5
176
        file('bl/d', 'w').write('test 6')
177
        tree.add('d')
178
        tree.commit(message='add d')
179
180
        # This exports the baseline state at Revision 3,
181
        # followed by the deltas for 4 and 5
182
        data = self.run_bzr("fast-export --baseline -r 3.. bl")[0]
183
        data = re.sub('committer.*', 'committer', data)
184
        self.assertEquals(fast_export_baseline_data, data)
185
186
        # Also confirm that --baseline with no args is identical to full export
187
        data1 = self.run_bzr("fast-export --baseline bl")[0]
188
        data2 = self.run_bzr("fast-export bl")[0]
189
        self.assertEquals(data1, data2)
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
190
191
simple_fast_import_stream = """commit refs/heads/master
192
mark :1
193
committer Jelmer Vernooij <jelmer@samba.org> 1299718135 +0100
194
data 7
195
initial
196
197
"""
198
199
class TestFastImportInfo(ExternalBase):
200
6628.1.5 by Jelmer Vernooij
Consistently use fastimport feature.
201
    _test_needs_features = [FastimportFeature]
202
0.64.310 by Jelmer Vernooij
Fix fast-import-info.
203
    def test_simple(self):
204
        self.build_tree_contents([('simple.fi', simple_fast_import_stream)])
205
        output = self.run_bzr("fast-import-info simple.fi")[0]
206
        self.assertEquals(output, """Command counts:
207
\t0\tblob
208
\t0\tcheckpoint
209
\t1\tcommit
210
\t0\tfeature
211
\t0\tprogress
212
\t0\treset
213
\t0\ttag
214
File command counts:
215
\t0\tfilemodify
216
\t0\tfiledelete
217
\t0\tfilecopy
218
\t0\tfilerename
219
\t0\tfiledeleteall
220
Parent counts:
221
\t1\tparents-0
222
\t0\ttotal revisions merged
223
Commit analysis:
224
\tno\texecutables
225
\tno\tseparate authors found
226
\tno\tsymlinks
227
\tno\tblobs referenced by SHA
228
Head analysis:
229
\t[':1']\trefs/heads/master
230
Merges:
231
""")
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
232
233
234
class TestFastImport(ExternalBase):
235
6628.1.5 by Jelmer Vernooij
Consistently use fastimport feature.
236
    _test_needs_features = [FastimportFeature]
237
0.131.1 by Jelmer Vernooij
Add blackbox tests for 'bzr fast-import'.
238
    def test_empty(self):
239
        self.build_tree_contents([('empty.fi', "")])
240
        self.make_branch_and_tree("br")
241
        self.assertEquals("", self.run_bzr("fast-import empty.fi br")[0])
242
243
    def test_file(self):
244
        tree = self.make_branch_and_tree("br")
245
        self.build_tree_contents([('file.fi', simple_fast_import_stream)])
246
        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.
247
        self.assertEquals(1, tree.branch.revno())
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
248
0.64.355 by Jelmer Vernooij
Print sane error when a fastimport file is incomplete.
249
    def test_missing_bytes(self):
250
        self.build_tree_contents([('empty.fi', """
251
commit refs/heads/master
252
mark :1
253
committer
254
data 15
255
""")])
256
        self.make_branch_and_tree("br")
6628.1.3 by Jelmer Vernooij
Merge compatibility fixes.
257
        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.
258
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
259
260
class TestFastImportFilter(ExternalBase):
261
6628.1.5 by Jelmer Vernooij
Consistently use fastimport feature.
262
    _test_needs_features = [FastimportFeature]
263
0.64.321 by Jelmer Vernooij
Allow fast-import-filter to be used without first argument.
264
    def test_empty(self):
265
        self.build_tree_contents([('empty.fi', "")])
266
        self.make_branch_and_tree("br")
267
        self.assertEquals("", self.run_bzr("fast-import-filter -")[0])
268
269
    def test_default_stdin(self):
270
        self.build_tree_contents([('empty.fi', "")])
271
        self.make_branch_and_tree("br")
272
        self.assertEquals("", self.run_bzr("fast-import-filter")[0])