/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3408.7.1 by Martin Pool
Support tarball export to stdout
1
# Copyright (C) 2005, 2006, 2008 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
18
"""Black-box tests for bzr export.
19
"""
20
3408.7.1 by Martin Pool
Support tarball export to stdout
21
from StringIO import StringIO
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
22
import os
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
23
import stat
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
24
import sys
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
25
import tarfile
26
import zipfile
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
27
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
28
from bzrlib.export import (
29
    zip_exporter,
30
    )
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
31
from bzrlib.tests import TestSkipped
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
32
from bzrlib.tests.blackbox import ExternalBase
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
33
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
34
35
class TestExport(ExternalBase):
36
37
    def test_tar_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
38
        tree = self.make_branch_and_tree('tar')
39
        self.build_tree(['tar/a'])
40
        tree.add('a')
3577.3.1 by Ian Clatworthy
do not export .bzrrules
41
        self.build_tree_contents([('tar/.bzrrules', '')])
42
        tree.add('.bzrrules')
3577.3.2 by Ian Clatworthy
tweaks following jam's review
43
        self.build_tree(['tar/.bzr-adir/', 'tar/.bzr-adir/afile'])
44
        tree.add(['.bzr-adir/', '.bzr-adir/afile'])
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
45
46
        os.chdir('tar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
48
        tree.commit('1')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
49
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
50
        self.failUnless(tree.has_filename('.bzrignore'))
3577.3.1 by Ian Clatworthy
do not export .bzrrules
51
        self.failUnless(tree.has_filename('.bzrrules'))
3577.3.2 by Ian Clatworthy
tweaks following jam's review
52
        self.failUnless(tree.has_filename('.bzr-adir'))
53
        self.failUnless(tree.has_filename('.bzr-adir/afile'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
54
        self.run_bzr('export test.tar.gz')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
55
        ball = tarfile.open('test.tar.gz')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
56
        # Make sure the tarball contains 'a', but does not contain
57
        # '.bzrignore'.
58
        self.assertEqual(['test/a'], sorted(ball.getnames()))
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
59
3408.7.1 by Martin Pool
Support tarball export to stdout
60
        out, err = self.run_bzr('export --format=tgz --root=test -')
61
        ball = tarfile.open('', fileobj=StringIO(out))
62
        self.assertEqual(['test/a'], sorted(ball.getnames()))
63
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
64
    def test_tar_export_unicode(self):
65
        tree = self.make_branch_and_tree('tar')
66
        fname = u'\xe5.txt'
67
        try:
68
            self.build_tree(['tar/' + fname])
69
        except UnicodeError:
70
            raise TestSkipped('Unable to represent path %r' % (fname,))
71
        tree.add([fname])
72
        tree.commit('first')
73
74
        os.chdir('tar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
75
        self.run_bzr('export test.tar')
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
76
        ball = tarfile.open('test.tar')
77
        # all paths are prefixed with the base name of the tarball
78
        self.assertEqual(['test/' + fname.encode('utf8')],
79
                         sorted(ball.getnames()))
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
80
81
    def test_zip_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
82
        tree = self.make_branch_and_tree('zip')
83
        self.build_tree(['zip/a'])
84
        tree.add('a')
3577.3.1 by Ian Clatworthy
do not export .bzrrules
85
        self.build_tree_contents([('zip/.bzrrules', '')])
86
        tree.add('.bzrrules')
3577.3.2 by Ian Clatworthy
tweaks following jam's review
87
        self.build_tree(['zip/.bzr-adir/', 'zip/.bzr-adir/afile'])
88
        tree.add(['.bzr-adir/', '.bzr-adir/afile'])
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
89
90
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
91
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
92
        tree.commit('1')
93
94
        self.failUnless(tree.has_filename('.bzrignore'))
3577.3.1 by Ian Clatworthy
do not export .bzrrules
95
        self.failUnless(tree.has_filename('.bzrrules'))
3577.3.2 by Ian Clatworthy
tweaks following jam's review
96
        self.failUnless(tree.has_filename('.bzr-adir'))
97
        self.failUnless(tree.has_filename('.bzr-adir/afile'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
98
        self.run_bzr('export test.zip')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
99
100
        zfile = zipfile.ZipFile('test.zip')
101
        # Make sure the zipfile contains 'a', but does not contain
102
        # '.bzrignore'.
103
        self.assertEqual(['test/a'], sorted(zfile.namelist()))
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
104
105
    def test_zip_export_unicode(self):
106
        tree = self.make_branch_and_tree('zip')
107
        fname = u'\xe5.txt'
108
        try:
109
            self.build_tree(['zip/' + fname])
110
        except UnicodeError:
111
            raise TestSkipped('Unable to represent path %r' % (fname,))
112
        tree.add([fname])
113
        tree.commit('first')
114
115
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
116
        self.run_bzr('export test.zip')
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
117
        zfile = zipfile.ZipFile('test.zip')
118
        # all paths are prefixed with the base name of the zipfile
119
        self.assertEqual(['test/' + fname.encode('utf8')],
120
                         sorted(zfile.namelist()))
1185.61.5 by Jamie Wilkinson
add test for directory export
121
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
122
    def test_zip_export_directories(self):
123
        tree = self.make_branch_and_tree('zip')
124
        self.build_tree(['zip/a', 'zip/b/', 'zip/b/c', 'zip/d/'])
125
        tree.add(['a', 'b', 'b/c', 'd'])
126
        tree.commit('init')
127
128
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
129
        self.run_bzr('export test.zip')
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
130
        zfile = zipfile.ZipFile('test.zip')
131
        names = sorted(zfile.namelist())
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
132
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
133
        # even on win32, zipfile.ZipFile changes all names to use
134
        # forward slashes
135
        self.assertEqual(['test/a', 'test/b/', 'test/b/c', 'test/d/'], names)
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
136
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
137
        file_attr = stat.S_IFREG
138
        dir_attr = stat.S_IFDIR | zip_exporter.ZIP_DIRECTORY_BIT
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
139
140
        a_info = zfile.getinfo(names[0])
141
        self.assertEqual(file_attr, a_info.external_attr)
142
143
        b_info = zfile.getinfo(names[1])
144
        self.assertEqual(dir_attr, b_info.external_attr)
145
146
        c_info = zfile.getinfo(names[2])
147
        self.assertEqual(file_attr, c_info.external_attr)
148
149
        d_info = zfile.getinfo(names[3])
150
        self.assertEqual(dir_attr, d_info.external_attr)
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
151
1185.61.5 by Jamie Wilkinson
add test for directory export
152
    def test_dir_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
153
        tree = self.make_branch_and_tree('dir')
154
        self.build_tree(['dir/a'])
155
        tree.add('a')
3577.3.1 by Ian Clatworthy
do not export .bzrrules
156
        self.build_tree_contents([('dir/.bzrrules', '')])
157
        tree.add('.bzrrules')
3577.3.2 by Ian Clatworthy
tweaks following jam's review
158
        self.build_tree(['dir/.bzr-adir/', 'dir/.bzr-adir/afile'])
159
        tree.add(['.bzr-adir/', '.bzr-adir/afile'])
1185.61.5 by Jamie Wilkinson
add test for directory export
160
161
        os.chdir('dir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
162
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
163
        tree.commit('1')
1185.61.5 by Jamie Wilkinson
add test for directory export
164
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
165
        self.failUnless(tree.has_filename('.bzrignore'))
3577.3.1 by Ian Clatworthy
do not export .bzrrules
166
        self.failUnless(tree.has_filename('.bzrrules'))
3577.3.2 by Ian Clatworthy
tweaks following jam's review
167
        self.failUnless(tree.has_filename('.bzr-adir'))
168
        self.failUnless(tree.has_filename('.bzr-adir/afile'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
169
        self.run_bzr('export direxport')
1185.61.5 by Jamie Wilkinson
add test for directory export
170
171
        files = sorted(os.listdir('direxport'))
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
172
        # Make sure the exported directory contains 'a', but does not contain
173
        # '.bzrignore'.
174
        self.assertEqual(['a'], files)
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
175
176
    def example_branch(self):
177
        tree = self.make_branch_and_tree('branch')
2024.2.4 by John Arbash Meinel
Use build_tree_contents instead of manually opening the file
178
        self.build_tree_contents([('branch/hello', 'foo')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
179
        tree.add('hello')
180
        tree.commit('setup')
181
2024.2.4 by John Arbash Meinel
Use build_tree_contents instead of manually opening the file
182
        self.build_tree_contents([('branch/goodbye', 'baz')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
183
        tree.add('goodbye')
184
        tree.commit('setup')
185
        return tree
186
        
187
    def test_basic_directory_export(self):
188
        self.example_branch()
189
        os.chdir('branch')
190
191
        # Directory exports
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
192
        self.run_bzr('export ../latest')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
193
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('../latest')))
194
        self.check_file_contents('../latest/goodbye', 'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
195
        self.run_bzr('export ../first -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
196
        self.assertEqual(['hello'], sorted(os.listdir('../first')))
197
        self.check_file_contents('../first/hello', 'foo')
198
199
        # Even with .gz and .bz2 it is still a directory
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
200
        self.run_bzr('export ../first.gz -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
201
        self.check_file_contents('../first.gz/hello', 'foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
202
        self.run_bzr('export ../first.bz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
203
        self.check_file_contents('../first.bz2/hello', 'foo')
204
205
    def test_basic_tarfile_export(self):
206
        self.example_branch()
207
        os.chdir('branch')
208
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
209
        self.run_bzr('export ../first.tar -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
210
        self.failUnless(os.path.isfile('../first.tar'))
211
        tf = tarfile.open('../first.tar')
212
        try:
213
            self.assertEqual(['first/hello'], sorted(tf.getnames()))
214
            self.assertEqual('foo', tf.extractfile('first/hello').read())
215
        finally:
216
            tf.close()
217
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
218
        self.run_bzr('export ../first.tar.gz -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
219
        self.failUnless(os.path.isfile('../first.tar.gz'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
220
        self.run_bzr('export ../first.tbz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
221
        self.failUnless(os.path.isfile('../first.tbz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
222
        self.run_bzr('export ../first.tar.bz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
223
        self.failUnless(os.path.isfile('../first.tar.bz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
224
        self.run_bzr('export ../first.tar.tbz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
225
        self.failUnless(os.path.isfile('../first.tar.tbz2'))
226
227
        tf = tarfile.open('../first.tar.tbz2', 'r:bz2')
228
        try:
229
            self.assertEqual(['first.tar/hello'], sorted(tf.getnames()))
230
            self.assertEqual('foo', tf.extractfile('first.tar/hello').read())
231
        finally:
232
            tf.close()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
233
        self.run_bzr('export ../first2.tar -r 1 --root pizza')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
234
        tf = tarfile.open('../first2.tar')
235
        try:
236
            self.assertEqual(['pizza/hello'], sorted(tf.getnames()))
237
            self.assertEqual('foo', tf.extractfile('pizza/hello').read())
238
        finally:
239
            tf.close()
240
241
    def test_basic_zipfile_export(self):
242
        self.example_branch()
243
        os.chdir('branch')
244
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
245
        self.run_bzr('export ../first.zip -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
246
        self.failUnlessExists('../first.zip')
247
        zf = zipfile.ZipFile('../first.zip')
248
        try:
249
            self.assertEqual(['first/hello'], sorted(zf.namelist()))
250
            self.assertEqual('foo', zf.read('first/hello'))
251
        finally:
252
            zf.close()
253
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
254
        self.run_bzr('export ../first2.zip -r 1 --root pizza')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
255
        zf = zipfile.ZipFile('../first2.zip')
256
        try:
257
            self.assertEqual(['pizza/hello'], sorted(zf.namelist()))
258
            self.assertEqual('foo', zf.read('pizza/hello'))
259
        finally:
260
            zf.close()
261
        
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
262
        self.run_bzr('export ../first-zip --format=zip -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
263
        zf = zipfile.ZipFile('../first-zip')
264
        try:
265
            self.assertEqual(['first-zip/hello'], sorted(zf.namelist()))
266
            self.assertEqual('foo', zf.read('first-zip/hello'))
267
        finally:
268
            zf.close()
269
2099.1.1 by Daniel Silverstone
Add source branch support to export command
270
    def test_export_from_outside_branch(self):
271
        self.example_branch()
272
273
        # Use directory exports to test stating the branch location
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
274
        self.run_bzr('export latest branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
275
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
276
        self.check_file_contents('latest/goodbye', 'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
277
        self.run_bzr('export first -r 1 branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
278
        self.assertEqual(['hello'], sorted(os.listdir('first')))
279
        self.check_file_contents('first/hello', 'foo')