/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')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
41
42
        os.chdir('tar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
43
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
44
        tree.commit('1')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
45
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
46
        self.failUnless(tree.has_filename('.bzrignore'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
47
        self.run_bzr('export test.tar.gz')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
48
        ball = tarfile.open('test.tar.gz')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
49
        # Make sure the tarball contains 'a', but does not contain
50
        # '.bzrignore'.
51
        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
52
3408.7.1 by Martin Pool
Support tarball export to stdout
53
        out, err = self.run_bzr('export --format=tgz --root=test -')
54
        ball = tarfile.open('', fileobj=StringIO(out))
55
        self.assertEqual(['test/a'], sorted(ball.getnames()))
56
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
57
    def test_tar_export_unicode(self):
58
        tree = self.make_branch_and_tree('tar')
59
        fname = u'\xe5.txt'
60
        try:
61
            self.build_tree(['tar/' + fname])
62
        except UnicodeError:
63
            raise TestSkipped('Unable to represent path %r' % (fname,))
64
        tree.add([fname])
65
        tree.commit('first')
66
67
        os.chdir('tar')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
68
        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
69
        ball = tarfile.open('test.tar')
70
        # all paths are prefixed with the base name of the tarball
71
        self.assertEqual(['test/' + fname.encode('utf8')],
72
                         sorted(ball.getnames()))
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
73
74
    def test_zip_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
75
        tree = self.make_branch_and_tree('zip')
76
        self.build_tree(['zip/a'])
77
        tree.add('a')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
78
79
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
80
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
81
        tree.commit('1')
82
83
        self.failUnless(tree.has_filename('.bzrignore'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
84
        self.run_bzr('export test.zip')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
85
86
        zfile = zipfile.ZipFile('test.zip')
87
        # Make sure the zipfile contains 'a', but does not contain
88
        # '.bzrignore'.
89
        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
90
91
    def test_zip_export_unicode(self):
92
        tree = self.make_branch_and_tree('zip')
93
        fname = u'\xe5.txt'
94
        try:
95
            self.build_tree(['zip/' + fname])
96
        except UnicodeError:
97
            raise TestSkipped('Unable to represent path %r' % (fname,))
98
        tree.add([fname])
99
        tree.commit('first')
100
101
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
102
        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
103
        zfile = zipfile.ZipFile('test.zip')
104
        # all paths are prefixed with the base name of the zipfile
105
        self.assertEqual(['test/' + fname.encode('utf8')],
106
                         sorted(zfile.namelist()))
1185.61.5 by Jamie Wilkinson
add test for directory export
107
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
108
    def test_zip_export_directories(self):
109
        tree = self.make_branch_and_tree('zip')
110
        self.build_tree(['zip/a', 'zip/b/', 'zip/b/c', 'zip/d/'])
111
        tree.add(['a', 'b', 'b/c', 'd'])
112
        tree.commit('init')
113
114
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
115
        self.run_bzr('export test.zip')
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
116
        zfile = zipfile.ZipFile('test.zip')
117
        names = sorted(zfile.namelist())
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
118
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
119
        # even on win32, zipfile.ZipFile changes all names to use
120
        # forward slashes
121
        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
122
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
123
        file_attr = stat.S_IFREG
124
        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
125
126
        a_info = zfile.getinfo(names[0])
127
        self.assertEqual(file_attr, a_info.external_attr)
128
129
        b_info = zfile.getinfo(names[1])
130
        self.assertEqual(dir_attr, b_info.external_attr)
131
132
        c_info = zfile.getinfo(names[2])
133
        self.assertEqual(file_attr, c_info.external_attr)
134
135
        d_info = zfile.getinfo(names[3])
136
        self.assertEqual(dir_attr, d_info.external_attr)
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
137
1185.61.5 by Jamie Wilkinson
add test for directory export
138
    def test_dir_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
139
        tree = self.make_branch_and_tree('dir')
140
        self.build_tree(['dir/a'])
141
        tree.add('a')
1185.61.5 by Jamie Wilkinson
add test for directory export
142
143
        os.chdir('dir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
144
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
145
        tree.commit('1')
1185.61.5 by Jamie Wilkinson
add test for directory export
146
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
147
        self.failUnless(tree.has_filename('.bzrignore'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
148
        self.run_bzr('export direxport')
1185.61.5 by Jamie Wilkinson
add test for directory export
149
150
        files = sorted(os.listdir('direxport'))
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
151
        # Make sure the exported directory contains 'a', but does not contain
152
        # '.bzrignore'.
153
        self.assertEqual(['a'], files)
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
154
155
    def example_branch(self):
156
        tree = self.make_branch_and_tree('branch')
2024.2.4 by John Arbash Meinel
Use build_tree_contents instead of manually opening the file
157
        self.build_tree_contents([('branch/hello', 'foo')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
158
        tree.add('hello')
159
        tree.commit('setup')
160
2024.2.4 by John Arbash Meinel
Use build_tree_contents instead of manually opening the file
161
        self.build_tree_contents([('branch/goodbye', 'baz')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
162
        tree.add('goodbye')
163
        tree.commit('setup')
164
        return tree
165
        
166
    def test_basic_directory_export(self):
167
        self.example_branch()
168
        os.chdir('branch')
169
170
        # Directory exports
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
171
        self.run_bzr('export ../latest')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
172
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('../latest')))
173
        self.check_file_contents('../latest/goodbye', 'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
174
        self.run_bzr('export ../first -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
175
        self.assertEqual(['hello'], sorted(os.listdir('../first')))
176
        self.check_file_contents('../first/hello', 'foo')
177
178
        # Even with .gz and .bz2 it is still a directory
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
179
        self.run_bzr('export ../first.gz -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
180
        self.check_file_contents('../first.gz/hello', 'foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
181
        self.run_bzr('export ../first.bz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
182
        self.check_file_contents('../first.bz2/hello', 'foo')
183
184
    def test_basic_tarfile_export(self):
185
        self.example_branch()
186
        os.chdir('branch')
187
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
188
        self.run_bzr('export ../first.tar -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
189
        self.failUnless(os.path.isfile('../first.tar'))
190
        tf = tarfile.open('../first.tar')
191
        try:
192
            self.assertEqual(['first/hello'], sorted(tf.getnames()))
193
            self.assertEqual('foo', tf.extractfile('first/hello').read())
194
        finally:
195
            tf.close()
196
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
197
        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
198
        self.failUnless(os.path.isfile('../first.tar.gz'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
199
        self.run_bzr('export ../first.tbz2 -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
200
        self.failUnless(os.path.isfile('../first.tbz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
201
        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
202
        self.failUnless(os.path.isfile('../first.tar.bz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
203
        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
204
        self.failUnless(os.path.isfile('../first.tar.tbz2'))
205
206
        tf = tarfile.open('../first.tar.tbz2', 'r:bz2')
207
        try:
208
            self.assertEqual(['first.tar/hello'], sorted(tf.getnames()))
209
            self.assertEqual('foo', tf.extractfile('first.tar/hello').read())
210
        finally:
211
            tf.close()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
212
        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
213
        tf = tarfile.open('../first2.tar')
214
        try:
215
            self.assertEqual(['pizza/hello'], sorted(tf.getnames()))
216
            self.assertEqual('foo', tf.extractfile('pizza/hello').read())
217
        finally:
218
            tf.close()
219
220
    def test_basic_zipfile_export(self):
221
        self.example_branch()
222
        os.chdir('branch')
223
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
224
        self.run_bzr('export ../first.zip -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
225
        self.failUnlessExists('../first.zip')
226
        zf = zipfile.ZipFile('../first.zip')
227
        try:
228
            self.assertEqual(['first/hello'], sorted(zf.namelist()))
229
            self.assertEqual('foo', zf.read('first/hello'))
230
        finally:
231
            zf.close()
232
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
233
        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
234
        zf = zipfile.ZipFile('../first2.zip')
235
        try:
236
            self.assertEqual(['pizza/hello'], sorted(zf.namelist()))
237
            self.assertEqual('foo', zf.read('pizza/hello'))
238
        finally:
239
            zf.close()
240
        
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
241
        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
242
        zf = zipfile.ZipFile('../first-zip')
243
        try:
244
            self.assertEqual(['first-zip/hello'], sorted(zf.namelist()))
245
            self.assertEqual('foo', zf.read('first-zip/hello'))
246
        finally:
247
            zf.close()
248
2099.1.1 by Daniel Silverstone
Add source branch support to export command
249
    def test_export_from_outside_branch(self):
250
        self.example_branch()
251
252
        # Use directory exports to test stating the branch location
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
253
        self.run_bzr('export latest branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
254
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
255
        self.check_file_contents('latest/goodbye', 'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
256
        self.run_bzr('export first -r 1 branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
257
        self.assertEqual(['hello'], sorted(os.listdir('first')))
258
        self.check_file_contents('first/hello', 'foo')