/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2011, 2016 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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
16
17
6622.1.29 by Jelmer Vernooij
Fix some more tests.
18
"""Black-box tests for brz export.
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
19
"""
20
21
import os
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
22
import stat
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
23
import tarfile
5718.5.26 by Jelmer Vernooij
Work around zip info time zone issues.
24
import time
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
25
import zipfile
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
26
4241.9.1 by Vincent Ladeuil
Fix test_tar_export erroring test.
27
6968.2.7 by Jelmer Vernooij
Add breezy.archive.
28
from ...archive import zip
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
29
from ... import (
4241.9.1 by Vincent Ladeuil
Fix test_tar_export erroring test.
30
    export,
7045.4.7 by Jelmer Vernooij
Fix remaining tests.
31
    osutils,
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
32
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
33
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
34
    BytesIO,
35
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
36
from .. import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
37
    features,
38
    TestCaseWithTransport,
39
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
40
from ..matchers import ContainsNoVfsCalls
5283.4.5 by Martin Pool
Update remaining subclasses of ExternalBase
41
42
43
class TestExport(TestCaseWithTransport):
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
44
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
45
    # On Windows, if we fail to set the binary bit, and a '\r' or '\n'
46
    # ends up in the data stream, we will get corruption. Add a fair amount
47
    # of random data, to help ensure there is at least one.
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
48
    _file_content = (b'!\r\n\t\n \r'
49
        + b'r29trp9i1r8k0e24c2o7mcx2isrlaw7toh1hv2mtst3o1udkl36v9xn2z8kt\n'
50
          b'tvjn7e3i9cj1qs1rw9gcye9w72cbdueiufw8nky7bs08lwggir59d62knecp\n'
51
          b'7s0537r8sg3e8hdnidji49rswo47c3j8190nh8emef2b6j1mf5kdq45nt3f5\n'
52
          b'1sz9u7fuzrm4w8bebre7p62sh5os2nkj2iiyuk9n0w0pjpdulu9k2aajejah\n'
53
          b'ini90ny40qzs12ajuy0ua6l178n93lvy2atqngnntsmtlmqx7yhp0q9a1xr4\n'
54
          b'1n69kgbo6qu9osjpqq83446r00jijtcstzybfqwm1lnt9spnri2j07bt7bbh\n'
55
          b'rf3ejatdxta83te2s0pt9rc4hidgy3d2pc53p4wscdt2b1dfxdj9utf5m17f\n'
56
          b'f03oofcau950o090vyx6m72vfkywo7gp3ajzi6uk02dwqwtumq4r44xx6ho7\n'
57
          b'nhynborjdjep5j53f9548msb7gd3x9a1xveb4s8zfo6cbdw2kdngcrbakwu8\n'
58
          b'ql5a8l94gplkwr7oypw5nt1gj5i3xwadyjfr3lb61tfkz31ba7uda9knb294\n'
59
          b'1azhfta0q3ry9x36lxyanvhp0g5z0t5a0i4wnoc8p4htexi915y1cnw4nznn\n'
60
          b'aj70dvp88ifiblv2bsp98hz570teinj8g472ddxni9ydmazfzwtznbf3hrg6\n'
61
          b'84gigirjt6n2yagf70036m8d73cz0jpcighpjtxsmbgzbxx7nb4ewq6jbgnc\n'
62
          b'hux1b0qtsdi0zfhj6g1otf5jcldmtdvuon8y1ttszkqw3ograwi25yl921hy\n'
63
          b'izgscmfha9xdhxxabs07b40secpw22ah9iwpbmsns6qz0yr6fswto3ft2ez5\n'
64
          b'ngn48pdfxj1pw246drmj1y2ll5af5w7cz849rapzd9ih7qvalw358co0yzrs\n'
65
          b'xan9291d1ivjku4o5gjrsnmllrqwxwy86pcivinbmlnzasa9v3o22lgv4uyd\n'
66
          b'q8kw77bge3hr5rr5kzwjxk223bkmo3z9oju0954undsz8axr3kb3730otrcr\n'
67
          b'9cwhu37htnizdwxmpoc5qmobycfm7ubbykfumv6zgkl6b8zlslwl7a8b81vz\n'
68
          b'3weqkvv5csfza9xvwypr6lo0t03fwp0ihmci3m1muh0lf2u30ze0hjag691j\n'
69
          b'27fjtd3e3zbiin5n2hq21iuo09ukbs73r5rt7vaw6axvoilvdciir9ugjh2c\n'
70
          b'na2b8dr0ptftoyhyxv1iwg661y338e28fhz4xxwgv3hnoe98ydfa1oou45vj\n'
71
          b'ln74oac2keqt0agbylrqhfscin7ireae2bql7z2le823ksy47ud57z8ctomp\n'
72
          b'31s1vwbczdjwqp0o2jc7mkrurvzg8mj2zwcn2iily4gcl4sy4fsh4rignlyz\n')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
73
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
74
    def make_basic_tree(self):
75
        tree = self.make_branch_and_tree('tree')
76
        self.build_tree_contents([('tree/a', self._file_content)])
77
        tree.add('a')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
78
        tree.commit('1')
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
79
        return tree
80
81
    def make_tree_with_extra_bzr_files(self):
82
        tree = self.make_basic_tree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
83
        self.build_tree_contents([('tree/.bzrrules', b'')])
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
84
        self.build_tree(['tree/.bzr-adir/', 'tree/.bzr-adir/afile'])
85
        tree.add(['.bzrrules', '.bzr-adir/', '.bzr-adir/afile'])
86
87
        self.run_bzr('ignore something -d tree')
88
        tree.commit('2')
89
        return tree
90
91
    def test_tar_export_ignores_bzr(self):
92
        tree = self.make_tree_with_extra_bzr_files()
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
93
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
94
        self.assertTrue(tree.has_filename('.bzrignore'))
95
        self.assertTrue(tree.has_filename('.bzrrules'))
96
        self.assertTrue(tree.has_filename('.bzr-adir'))
97
        self.assertTrue(tree.has_filename('.bzr-adir/afile'))
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
98
        self.run_bzr('export test.tar.gz -d tree')
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
99
        ball = tarfile.open('test.tar.gz')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
100
        # Make sure the tarball contains 'a', but does not contain
101
        # '.bzrignore'.
5724.1.2 by John Arbash Meinel
Force test_tar_export to test that it outputs in binary.
102
        self.assertEqual(['test/a'],
103
                         sorted(ball.getnames()))
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
104
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
105
    def test_tar_export_unicode_filename(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
106
        self.requireFeature(features.UnicodeFilenameFeature)
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
107
        tree = self.make_branch_and_tree('tar')
4241.9.5 by Vincent Ladeuil
Fix unicode related OSX failures.
108
        # FIXME: using fname = u'\xe5.txt' below triggers a bug revealed since
109
        # bzr.dev revno 4216 but more related to OSX/working trees/unicode than
4241.9.6 by Vincent Ladeuil
Add NEWS entry.
110
        # export itself --vila 20090406
4241.9.5 by Vincent Ladeuil
Fix unicode related OSX failures.
111
        fname = u'\N{Euro Sign}.txt'
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
112
        self.build_tree(['tar/' + fname])
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
113
        tree.add([fname])
114
        tree.commit('first')
115
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
116
        self.run_bzr('export test.tar -d tar')
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
117
        ball = tarfile.open('test.tar')
118
        # all paths are prefixed with the base name of the tarball
7045.4.7 by Jelmer Vernooij
Fix remaining tests.
119
        self.assertEqual([u'test/' + fname],
120
                         [osutils.safe_unicode(n) for n in ball.getnames()])
1185.61.1 by Jamie Wilkinson
add blackbox tests for ensuring .bzrignore is not exported
121
5152.1.1 by Parth Malwankar
Fixed bug #413406. unicode names for parent directory
122
    def test_tar_export_unicode_basedir(self):
123
        """Test for bug #413406"""
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
124
        self.requireFeature(features.UnicodeFilenameFeature)
5152.1.1 by Parth Malwankar
Fixed bug #413406. unicode names for parent directory
125
        basedir = u'\N{euro sign}'
126
        os.mkdir(basedir)
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
127
        self.run_bzr(['init', basedir])
128
        self.run_bzr(['export', '--format', 'tgz', u'test.tar.gz',
129
                      '-d', basedir])
130
131
    def test_zip_export_ignores_bzr(self):
132
        tree = self.make_tree_with_extra_bzr_files()
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
133
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
134
        self.assertTrue(tree.has_filename('.bzrignore'))
135
        self.assertTrue(tree.has_filename('.bzrrules'))
136
        self.assertTrue(tree.has_filename('.bzr-adir'))
137
        self.assertTrue(tree.has_filename('.bzr-adir/afile'))
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
138
        self.run_bzr('export test.zip -d tree')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
139
140
        zfile = zipfile.ZipFile('test.zip')
141
        # Make sure the zipfile contains 'a', but does not contain
142
        # '.bzrignore'.
143
        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
144
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
145
    # TODO: This really looks like something that should be using permutation
146
    #       testing. Though the actual setup and teardown functions are pretty
147
    #       different for each
148
    def assertZipANameAndContent(self, zfile, root=''):
149
        """The file should only contain name 'a' and _file_content"""
150
        fname = root + 'a'
151
        self.assertEqual([fname], sorted(zfile.namelist()))
152
        zfile.testzip()
153
        self.assertEqualDiff(self._file_content, zfile.read(fname))
154
5718.5.9 by Jelmer Vernooij
Add test for export zip to stdout.
155
    def test_zip_export_stdout(self):
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
156
        tree = self.make_basic_tree()
7065.3.6 by Jelmer Vernooij
Fix some more tests.
157
        contents = self.run_bzr_raw('export -d tree --format=zip -')[0]
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
158
        self.assertZipANameAndContent(zipfile.ZipFile(BytesIO(contents)))
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
159
160
    def test_zip_export_file(self):
161
        tree = self.make_basic_tree()
162
        self.run_bzr('export -d tree test.zip')
163
        self.assertZipANameAndContent(zipfile.ZipFile('test.zip'),
164
                                      root='test/')
165
166
    def assertTarANameAndContent(self, ball, root=''):
167
        fname = root + 'a'
7045.1.10 by Jelmer Vernooij
Fix iterator use in export.
168
        ball_iter = iter(ball)
169
        tar_info = next(ball_iter)
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
170
        self.assertEqual(fname, tar_info.name)
171
        self.assertEqual(tarfile.REGTYPE, tar_info.type)
172
        self.assertEqual(len(self._file_content), tar_info.size)
173
        f = ball.extractfile(tar_info)
174
        if self._file_content != f.read():
175
            self.fail('File content has been corrupted.'
176
                      ' Check that all streams are handled in binary mode.')
177
        # There should be no other files in the tarball
7045.1.10 by Jelmer Vernooij
Fix iterator use in export.
178
        self.assertRaises(StopIteration, next, ball_iter)
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
179
180
    def run_tar_export_disk_and_stdout(self, extension, tarfile_flags):
181
        tree = self.make_basic_tree()
182
        fname = 'test.%s' % (extension,)
5952.1.26 by Vincent Ladeuil
Fix the test failure, streams should be closed. In the right order.
183
        self.run_bzr('export -d tree %s' % (fname,))
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
184
        mode = 'r|%s' % (tarfile_flags,)
185
        ball = tarfile.open(fname, mode=mode)
186
        self.assertTarANameAndContent(ball, root='test/')
7065.3.6 by Jelmer Vernooij
Fix some more tests.
187
        content = self.run_bzr_raw('export -d tree --format=%s -' % (extension,))[0]
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
188
        ball = tarfile.open(mode=mode, fileobj=BytesIO(content))
5724.1.3 by John Arbash Meinel
Change the exporters to ensure that we are writing the data out in binary mode.
189
        self.assertTarANameAndContent(ball, root='')
190
191
    def test_tar_export(self):
192
        self.run_tar_export_disk_and_stdout('tar', '')
193
194
    def test_tgz_export(self):
195
        self.run_tar_export_disk_and_stdout('tgz', 'gz')
196
197
    def test_tbz2_export(self):
198
        self.run_tar_export_disk_and_stdout('tbz2', 'bz2')
199
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
200
    def test_zip_export_unicode(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
201
        self.requireFeature(features.UnicodeFilenameFeature)
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
202
        tree = self.make_branch_and_tree('zip')
4241.9.5 by Vincent Ladeuil
Fix unicode related OSX failures.
203
        fname = u'\N{Euro Sign}.txt'
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
204
        self.build_tree(['zip/' + fname])
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
205
        tree.add([fname])
206
        tree.commit('first')
207
208
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
209
        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
210
        zfile = zipfile.ZipFile('test.zip')
211
        # all paths are prefixed with the base name of the zipfile
7045.1.6 by Jelmer Vernooij
Always pass in filenames as unicode for zipfiles.
212
        self.assertEqual(['test/' + fname],
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
213
                         sorted(zfile.namelist()))
1185.61.5 by Jamie Wilkinson
add test for directory export
214
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
215
    def test_zip_export_directories(self):
216
        tree = self.make_branch_and_tree('zip')
217
        self.build_tree(['zip/a', 'zip/b/', 'zip/b/c', 'zip/d/'])
218
        tree.add(['a', 'b', 'b/c', 'd'])
219
        tree.commit('init')
220
221
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
222
        self.run_bzr('export test.zip')
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
223
        zfile = zipfile.ZipFile('test.zip')
224
        names = sorted(zfile.namelist())
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
225
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
226
        # even on win32, zipfile.ZipFile changes all names to use
227
        # forward slashes
228
        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
229
6968.2.7 by Jelmer Vernooij
Add breezy.archive.
230
        file_attr = stat.S_IFREG | zip.FILE_PERMISSIONS
231
        dir_attr = (stat.S_IFDIR | zip.ZIP_DIRECTORY_BIT |
232
                    zip.DIR_PERMISSIONS)
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
233
234
        a_info = zfile.getinfo(names[0])
235
        self.assertEqual(file_attr, a_info.external_attr)
236
237
        b_info = zfile.getinfo(names[1])
238
        self.assertEqual(dir_attr, b_info.external_attr)
239
240
        c_info = zfile.getinfo(names[2])
241
        self.assertEqual(file_attr, c_info.external_attr)
242
243
        d_info = zfile.getinfo(names[3])
244
        self.assertEqual(dir_attr, d_info.external_attr)
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
245
1185.61.5 by Jamie Wilkinson
add test for directory export
246
    def test_dir_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
247
        tree = self.make_branch_and_tree('dir')
248
        self.build_tree(['dir/a'])
249
        tree.add('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
250
        self.build_tree_contents([('dir/.bzrrules', b'')])
3577.3.1 by Ian Clatworthy
do not export .bzrrules
251
        tree.add('.bzrrules')
3577.3.2 by Ian Clatworthy
tweaks following jam's review
252
        self.build_tree(['dir/.bzr-adir/', 'dir/.bzr-adir/afile'])
253
        tree.add(['.bzr-adir/', '.bzr-adir/afile'])
1185.61.5 by Jamie Wilkinson
add test for directory export
254
255
        os.chdir('dir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
256
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
257
        tree.commit('1')
1185.61.5 by Jamie Wilkinson
add test for directory export
258
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
259
        self.assertTrue(tree.has_filename('.bzrignore'))
260
        self.assertTrue(tree.has_filename('.bzrrules'))
261
        self.assertTrue(tree.has_filename('.bzr-adir'))
262
        self.assertTrue(tree.has_filename('.bzr-adir/afile'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
263
        self.run_bzr('export direxport')
1185.61.5 by Jamie Wilkinson
add test for directory export
264
265
        files = sorted(os.listdir('direxport'))
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
266
        # Make sure the exported directory contains 'a', but does not contain
267
        # '.bzrignore'.
268
        self.assertEqual(['a'], files)
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
269
270
    def example_branch(self):
3613.2.1 by Robert Collins
Teach export how to export a subdirectory. (Robert Collins)
271
        """Create a branch a 'branch' containing hello and goodbye."""
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
272
        tree = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
273
        self.build_tree_contents([('branch/hello', b'foo')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
274
        tree.add('hello')
275
        tree.commit('setup')
276
6855.4.1 by Jelmer Vernooij
Yet more bees.
277
        self.build_tree_contents([('branch/goodbye', b'baz')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
278
        tree.add('goodbye')
279
        tree.commit('setup')
280
        return tree
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
281
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
282
    def test_basic_directory_export(self):
283
        self.example_branch()
284
        os.chdir('branch')
285
286
        # Directory exports
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
287
        self.run_bzr('export ../latest')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
288
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('../latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
289
        self.check_file_contents('../latest/goodbye', b'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
290
        self.run_bzr('export ../first -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
291
        self.assertEqual(['hello'], sorted(os.listdir('../first')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
292
        self.check_file_contents('../first/hello', b'foo')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
293
294
        # Even with .gz and .bz2 it is still a directory
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
295
        self.run_bzr('export ../first.gz -r 1')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
296
        self.check_file_contents('../first.gz/hello', b'foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
297
        self.run_bzr('export ../first.bz2 -r 1')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
298
        self.check_file_contents('../first.bz2/hello', b'foo')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
299
300
    def test_basic_tarfile_export(self):
301
        self.example_branch()
302
        os.chdir('branch')
303
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
304
        self.run_bzr('export ../first.tar -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
305
        self.assertTrue(os.path.isfile('../first.tar'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
306
        tf = tarfile.open('../first.tar')
307
        try:
308
            self.assertEqual(['first/hello'], sorted(tf.getnames()))
7027.4.1 by Jelmer Vernooij
Use StringIOWithEncoding on Python3.
309
            self.assertEqual(b'foo', tf.extractfile('first/hello').read())
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
310
        finally:
311
            tf.close()
312
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
313
        self.run_bzr('export ../first.tar.gz -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
314
        self.assertTrue(os.path.isfile('../first.tar.gz'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
315
        self.run_bzr('export ../first.tbz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
316
        self.assertTrue(os.path.isfile('../first.tbz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
317
        self.run_bzr('export ../first.tar.bz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
318
        self.assertTrue(os.path.isfile('../first.tar.bz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
319
        self.run_bzr('export ../first.tar.tbz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
320
        self.assertTrue(os.path.isfile('../first.tar.tbz2'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
321
322
        tf = tarfile.open('../first.tar.tbz2', 'r:bz2')
323
        try:
324
            self.assertEqual(['first.tar/hello'], sorted(tf.getnames()))
7027.10.2 by Jelmer Vernooij
Merge trunk.
325
            self.assertEqual(b'foo', tf.extractfile('first.tar/hello').read())
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
326
        finally:
327
            tf.close()
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
328
        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
329
        tf = tarfile.open('../first2.tar')
330
        try:
331
            self.assertEqual(['pizza/hello'], sorted(tf.getnames()))
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
332
            self.assertEqual(b'foo', tf.extractfile('pizza/hello').read())
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
333
        finally:
334
            tf.close()
335
336
    def test_basic_zipfile_export(self):
337
        self.example_branch()
338
        os.chdir('branch')
339
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
340
        self.run_bzr('export ../first.zip -r 1')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
341
        self.assertPathExists('../first.zip')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
342
        zf = zipfile.ZipFile('../first.zip')
343
        try:
344
            self.assertEqual(['first/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
345
            self.assertEqual(b'foo', zf.read('first/hello'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
346
        finally:
347
            zf.close()
348
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
349
        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
350
        zf = zipfile.ZipFile('../first2.zip')
351
        try:
352
            self.assertEqual(['pizza/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
353
            self.assertEqual(b'foo', zf.read('pizza/hello'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
354
        finally:
355
            zf.close()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
356
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
357
        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
358
        zf = zipfile.ZipFile('../first-zip')
359
        try:
360
            self.assertEqual(['first-zip/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
361
            self.assertEqual(b'foo', zf.read('first-zip/hello'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
362
        finally:
363
            zf.close()
364
2099.1.1 by Daniel Silverstone
Add source branch support to export command
365
    def test_export_from_outside_branch(self):
366
        self.example_branch()
367
368
        # Use directory exports to test stating the branch location
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
369
        self.run_bzr('export latest branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
370
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
371
        self.check_file_contents('latest/goodbye', b'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
372
        self.run_bzr('export first -r 1 branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
373
        self.assertEqual(['hello'], sorted(os.listdir('first')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
374
        self.check_file_contents('first/hello', b'foo')
3613.2.1 by Robert Collins
Teach export how to export a subdirectory. (Robert Collins)
375
376
    def test_export_partial_tree(self):
377
        tree = self.example_branch()
378
        self.build_tree(['branch/subdir/', 'branch/subdir/foo.txt'])
379
        tree.smart_add(['branch'])
380
        tree.commit('more setup')
381
        out, err = self.run_bzr('export exported branch/subdir')
382
        self.assertEqual(['foo.txt'], os.listdir('exported'))
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
383
5076.2.3 by Jelmer Vernooij
Review comments from Rob.
384
    def test_dir_export_per_file_timestamps(self):
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
385
        tree = self.example_branch()
6855.4.1 by Jelmer Vernooij
Yet more bees.
386
        self.build_tree_contents([('branch/har', b'foo')])
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
387
        tree.add('har')
5151.3.1 by Martin
Fix os.utime test failures, three on FAT filesystems and one with readonly files
388
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
389
        tree.commit('setup', timestamp=315532800)
5076.2.3 by Jelmer Vernooij
Review comments from Rob.
390
        self.run_bzr('export --per-file-timestamps t branch')
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
391
        har_st = os.stat('t/har')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
392
        self.assertEqual(315532800, har_st.st_mtime)
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
393
5966.1.1 by Szilveszter Farkas
Fixed exporting subdirectories with per file timestamps.
394
    def test_dir_export_partial_tree_per_file_timestamps(self):
395
        tree = self.example_branch()
396
        self.build_tree(['branch/subdir/', 'branch/subdir/foo.txt'])
397
        tree.smart_add(['branch'])
398
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
399
        tree.commit('setup', timestamp=315532800)
400
        self.run_bzr('export --per-file-timestamps tpart branch/subdir')
401
        foo_st = os.stat('tpart/foo.txt')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
402
        self.assertEqual(315532800, foo_st.st_mtime)
5966.1.1 by Szilveszter Farkas
Fixed exporting subdirectories with per file timestamps.
403
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
404
    def test_export_directory(self):
405
        """Test --directory option"""
406
        self.example_branch()
407
        self.run_bzr(['export', '--directory=branch', 'latest'])
408
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
409
        self.check_file_contents('latest/goodbye', b'baz')
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
410
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
411
    def test_export_uncommitted(self):
412
        """Test --uncommitted option"""
413
        self.example_branch()
414
        os.chdir('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
415
        self.build_tree_contents([('goodbye', b'uncommitted data')])
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
416
        self.run_bzr(['export', '--uncommitted', 'latest'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
417
        self.check_file_contents('latest/goodbye', b'uncommitted data')
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
418
419
    def test_export_uncommitted_no_tree(self):
420
        """Test --uncommitted option only works with a working tree."""
421
        tree = self.example_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
422
        tree.controldir.destroy_workingtree()
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
423
        os.chdir('branch')
424
        self.run_bzr_error(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
425
            ['brz: ERROR: --uncommitted requires a working tree'],
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
426
            'export --uncommitted latest')
427
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
428
    def test_zip_export_per_file_timestamps(self):
429
        tree = self.example_branch()
6855.4.1 by Jelmer Vernooij
Yet more bees.
430
        self.build_tree_contents([('branch/har', b'foo')])
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
431
        tree.add('har')
432
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
5718.5.26 by Jelmer Vernooij
Work around zip info time zone issues.
433
        timestamp = 347151600
434
        tree.commit('setup', timestamp=timestamp)
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
435
        self.run_bzr('export --per-file-timestamps test.zip branch')
436
        zfile = zipfile.ZipFile('test.zip')
437
        info = zfile.getinfo("test/har")
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
438
        self.assertEqual(time.localtime(timestamp)[:6], info.date_time)
6283.1.12 by Jelmer Vernooij
Add hpss call count test for 'bzr export'.
439
440
441
class TestSmartServerExport(TestCaseWithTransport):
442
443
    def test_simple_export(self):
444
        self.setup_smart_server_with_call_log()
445
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
446
        self.build_tree_contents([('branch/foo', b'thecontents')])
6283.1.12 by Jelmer Vernooij
Add hpss call count test for 'bzr export'.
447
        t.add("foo")
448
        t.commit("message")
449
        self.reset_smart_call_log()
450
        out, err = self.run_bzr(['export', "foo.tar.gz", self.get_url('branch')])
451
        # This figure represent the amount of work to perform this use case. It
452
        # is entirely ok to reduce this number if a test fails due to rpc_count
453
        # being too low. If rpc_count increases, more network roundtrips have
454
        # become necessary for this use case. Please do not adjust this number
455
        # upwards without agreement from bzr's network support maintainers.
6282.6.11 by Jelmer Vernooij
Adjust some call counts.
456
        self.assertLength(7, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
457
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
458
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)