/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.
7143.15.2 by Jelmer Vernooij
Run autopep8.
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/')
7143.15.2 by Jelmer Vernooij
Run autopep8.
187
        content = self.run_bzr_raw(
188
            'export -d tree --format=%s -' % (extension,))[0]
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
189
        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.
190
        self.assertTarANameAndContent(ball, root='')
191
192
    def test_tar_export(self):
193
        self.run_tar_export_disk_and_stdout('tar', '')
194
195
    def test_tgz_export(self):
196
        self.run_tar_export_disk_and_stdout('tgz', 'gz')
197
198
    def test_tbz2_export(self):
199
        self.run_tar_export_disk_and_stdout('tbz2', 'bz2')
200
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
201
    def test_zip_export_unicode(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
202
        self.requireFeature(features.UnicodeFilenameFeature)
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
203
        tree = self.make_branch_and_tree('zip')
4241.9.5 by Vincent Ladeuil
Fix unicode related OSX failures.
204
        fname = u'\N{Euro Sign}.txt'
5050.37.1 by Andrew Bennetts
Some fixes for tests that did not cope with LANG=C.
205
        self.build_tree(['zip/' + fname])
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
206
        tree.add([fname])
207
        tree.commit('first')
208
209
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
210
        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
211
        zfile = zipfile.ZipFile('test.zip')
212
        # 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.
213
        self.assertEqual(['test/' + fname],
2024.2.1 by John Arbash Meinel
Fix bug #56815 by exporting paths in utf8 to tarfile and zipfile
214
                         sorted(zfile.namelist()))
1185.61.5 by Jamie Wilkinson
add test for directory export
215
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
216
    def test_zip_export_directories(self):
217
        tree = self.make_branch_and_tree('zip')
218
        self.build_tree(['zip/a', 'zip/b/', 'zip/b/c', 'zip/d/'])
219
        tree.add(['a', 'b', 'b/c', 'd'])
220
        tree.commit('init')
221
222
        os.chdir('zip')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
223
        self.run_bzr('export test.zip')
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
224
        zfile = zipfile.ZipFile('test.zip')
225
        names = sorted(zfile.namelist())
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
226
2024.2.8 by John Arbash Meinel
paths are always forward slashed for python zipfiles
227
        # even on win32, zipfile.ZipFile changes all names to use
228
        # forward slashes
229
        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
230
6968.2.7 by Jelmer Vernooij
Add breezy.archive.
231
        file_attr = stat.S_IFREG | zip.FILE_PERMISSIONS
232
        dir_attr = (stat.S_IFDIR | zip.ZIP_DIRECTORY_BIT |
233
                    zip.DIR_PERMISSIONS)
2024.2.7 by John Arbash Meinel
Set the external_attr bits so Windows respects our directories
234
235
        a_info = zfile.getinfo(names[0])
236
        self.assertEqual(file_attr, a_info.external_attr)
237
238
        b_info = zfile.getinfo(names[1])
239
        self.assertEqual(dir_attr, b_info.external_attr)
240
241
        c_info = zfile.getinfo(names[2])
242
        self.assertEqual(file_attr, c_info.external_attr)
243
244
        d_info = zfile.getinfo(names[3])
245
        self.assertEqual(dir_attr, d_info.external_attr)
2024.2.6 by John Arbash Meinel
In zip files, directories must have trailing slashes
246
1185.61.5 by Jamie Wilkinson
add test for directory export
247
    def test_dir_export(self):
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
248
        tree = self.make_branch_and_tree('dir')
249
        self.build_tree(['dir/a'])
250
        tree.add('a')
6855.4.1 by Jelmer Vernooij
Yet more bees.
251
        self.build_tree_contents([('dir/.bzrrules', b'')])
3577.3.1 by Ian Clatworthy
do not export .bzrrules
252
        tree.add('.bzrrules')
3577.3.2 by Ian Clatworthy
tweaks following jam's review
253
        self.build_tree(['dir/.bzr-adir/', 'dir/.bzr-adir/afile'])
254
        tree.add(['.bzr-adir/', '.bzr-adir/afile'])
1185.61.5 by Jamie Wilkinson
add test for directory export
255
256
        os.chdir('dir')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
257
        self.run_bzr('ignore something')
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
258
        tree.commit('1')
1185.61.5 by Jamie Wilkinson
add test for directory export
259
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
260
        self.assertTrue(tree.has_filename('.bzrignore'))
261
        self.assertTrue(tree.has_filename('.bzrrules'))
262
        self.assertTrue(tree.has_filename('.bzr-adir'))
263
        self.assertTrue(tree.has_filename('.bzr-adir/afile'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
264
        self.run_bzr('export direxport')
1185.61.5 by Jamie Wilkinson
add test for directory export
265
266
        files = sorted(os.listdir('direxport'))
2024.2.2 by John Arbash Meinel
Cleanup the export tests to act more like the current api.
267
        # Make sure the exported directory contains 'a', but does not contain
268
        # '.bzrignore'.
269
        self.assertEqual(['a'], files)
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
270
271
    def example_branch(self):
3613.2.1 by Robert Collins
Teach export how to export a subdirectory. (Robert Collins)
272
        """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
273
        tree = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
274
        self.build_tree_contents([('branch/hello', b'foo')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
275
        tree.add('hello')
276
        tree.commit('setup')
277
6855.4.1 by Jelmer Vernooij
Yet more bees.
278
        self.build_tree_contents([('branch/goodbye', b'baz')])
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
279
        tree.add('goodbye')
280
        tree.commit('setup')
281
        return tree
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
282
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
283
    def test_basic_directory_export(self):
284
        self.example_branch()
285
        os.chdir('branch')
286
287
        # Directory exports
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
288
        self.run_bzr('export ../latest')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
289
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('../latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
290
        self.check_file_contents('../latest/goodbye', b'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
291
        self.run_bzr('export ../first -r 1')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
292
        self.assertEqual(['hello'], sorted(os.listdir('../first')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
293
        self.check_file_contents('../first/hello', b'foo')
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
294
295
        # Even with .gz and .bz2 it is still a directory
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
296
        self.run_bzr('export ../first.gz -r 1')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
297
        self.check_file_contents('../first.gz/hello', b'foo')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
298
        self.run_bzr('export ../first.bz2 -r 1')
6973.10.4 by Jelmer Vernooij
Update python3.passing.
299
        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
300
301
    def test_basic_tarfile_export(self):
302
        self.example_branch()
303
        os.chdir('branch')
304
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
305
        self.run_bzr('export ../first.tar -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
306
        self.assertTrue(os.path.isfile('../first.tar'))
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
307
        with tarfile.open('../first.tar') as tf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
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
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
311
        self.run_bzr('export ../first.tar.gz -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
312
        self.assertTrue(os.path.isfile('../first.tar.gz'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
313
        self.run_bzr('export ../first.tbz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
314
        self.assertTrue(os.path.isfile('../first.tbz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
315
        self.run_bzr('export ../first.tar.bz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
316
        self.assertTrue(os.path.isfile('../first.tar.bz2'))
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
317
        self.run_bzr('export ../first.tar.tbz2 -r 1')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
318
        self.assertTrue(os.path.isfile('../first.tar.tbz2'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
319
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
320
        with tarfile.open('../first.tar.tbz2', 'r:bz2') as tf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
321
            self.assertEqual(['first.tar/hello'], sorted(tf.getnames()))
7027.10.2 by Jelmer Vernooij
Merge trunk.
322
            self.assertEqual(b'foo', tf.extractfile('first.tar/hello').read())
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
323
        self.run_bzr('export ../first2.tar -r 1 --root pizza')
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
324
        with tarfile.open('../first2.tar') as tf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
325
            self.assertEqual(['pizza/hello'], sorted(tf.getnames()))
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
326
            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
327
328
    def test_basic_zipfile_export(self):
329
        self.example_branch()
330
        os.chdir('branch')
331
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
332
        self.run_bzr('export ../first.zip -r 1')
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
333
        self.assertPathExists('../first.zip')
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
334
        with zipfile.ZipFile('../first.zip') as zf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
335
            self.assertEqual(['first/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
336
            self.assertEqual(b'foo', zf.read('first/hello'))
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
337
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
338
        self.run_bzr('export ../first2.zip -r 1 --root pizza')
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
339
        with zipfile.ZipFile('../first2.zip') as zf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
340
            self.assertEqual(['pizza/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
341
            self.assertEqual(b'foo', zf.read('pizza/hello'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
342
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
343
        self.run_bzr('export ../first-zip --format=zip -r 1')
7356.1.5 by Jelmer Vernooij
Use more ExitStacks.
344
        with zipfile.ZipFile('../first-zip') as zf:
2024.2.3 by John Arbash Meinel
Move out export tests from test_too_much, refactor
345
            self.assertEqual(['first-zip/hello'], sorted(zf.namelist()))
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
346
            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
347
2099.1.1 by Daniel Silverstone
Add source branch support to export command
348
    def test_export_from_outside_branch(self):
349
        self.example_branch()
350
351
        # Use directory exports to test stating the branch location
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
352
        self.run_bzr('export latest branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
353
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
354
        self.check_file_contents('latest/goodbye', b'baz')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
355
        self.run_bzr('export first -r 1 branch')
2099.1.1 by Daniel Silverstone
Add source branch support to export command
356
        self.assertEqual(['hello'], sorted(os.listdir('first')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
357
        self.check_file_contents('first/hello', b'foo')
3613.2.1 by Robert Collins
Teach export how to export a subdirectory. (Robert Collins)
358
359
    def test_export_partial_tree(self):
360
        tree = self.example_branch()
361
        self.build_tree(['branch/subdir/', 'branch/subdir/foo.txt'])
362
        tree.smart_add(['branch'])
363
        tree.commit('more setup')
364
        out, err = self.run_bzr('export exported branch/subdir')
365
        self.assertEqual(['foo.txt'], os.listdir('exported'))
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
366
5076.2.3 by Jelmer Vernooij
Review comments from Rob.
367
    def test_dir_export_per_file_timestamps(self):
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
368
        tree = self.example_branch()
6855.4.1 by Jelmer Vernooij
Yet more bees.
369
        self.build_tree_contents([('branch/har', b'foo')])
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
370
        tree.add('har')
5151.3.1 by Martin
Fix os.utime test failures, three on FAT filesystems and one with readonly files
371
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
372
        tree.commit('setup', timestamp=315532800)
5076.2.3 by Jelmer Vernooij
Review comments from Rob.
373
        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``
374
        har_st = os.stat('t/har')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
375
        self.assertEqual(315532800, har_st.st_mtime)
5076.2.2 by Jelmer Vernooij
``bzr export`` now takes an optional argument ``--use-tree-timestamp``
376
5966.1.1 by Szilveszter Farkas
Fixed exporting subdirectories with per file timestamps.
377
    def test_dir_export_partial_tree_per_file_timestamps(self):
378
        tree = self.example_branch()
379
        self.build_tree(['branch/subdir/', 'branch/subdir/foo.txt'])
380
        tree.smart_add(['branch'])
381
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
382
        tree.commit('setup', timestamp=315532800)
383
        self.run_bzr('export --per-file-timestamps tpart branch/subdir')
384
        foo_st = os.stat('tpart/foo.txt')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
385
        self.assertEqual(315532800, foo_st.st_mtime)
5966.1.1 by Szilveszter Farkas
Fixed exporting subdirectories with per file timestamps.
386
5171.3.7 by Martin von Gagern
Added blackbox tests for --directory option.
387
    def test_export_directory(self):
388
        """Test --directory option"""
389
        self.example_branch()
390
        self.run_bzr(['export', '--directory=branch', 'latest'])
391
        self.assertEqual(['goodbye', 'hello'], sorted(os.listdir('latest')))
6973.10.4 by Jelmer Vernooij
Update python3.passing.
392
        self.check_file_contents('latest/goodbye', b'baz')
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
393
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
394
    def test_export_uncommitted(self):
395
        """Test --uncommitted option"""
396
        self.example_branch()
397
        os.chdir('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
398
        self.build_tree_contents([('goodbye', b'uncommitted data')])
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
399
        self.run_bzr(['export', '--uncommitted', 'latest'])
6973.10.4 by Jelmer Vernooij
Update python3.passing.
400
        self.check_file_contents('latest/goodbye', b'uncommitted data')
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
401
402
    def test_export_uncommitted_no_tree(self):
403
        """Test --uncommitted option only works with a working tree."""
404
        tree = self.example_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
405
        tree.controldir.destroy_workingtree()
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
406
        os.chdir('branch')
407
        self.run_bzr_error(
6622.1.29 by Jelmer Vernooij
Fix some more tests.
408
            ['brz: ERROR: --uncommitted requires a working tree'],
6331.2.2 by Jelmer Vernooij
Add --uncommitted option to export.
409
            'export --uncommitted latest')
410
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
411
    def test_zip_export_per_file_timestamps(self):
412
        tree = self.example_branch()
6855.4.1 by Jelmer Vernooij
Yet more bees.
413
        self.build_tree_contents([('branch/har', b'foo')])
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
414
        tree.add('har')
415
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
5718.5.26 by Jelmer Vernooij
Work around zip info time zone issues.
416
        timestamp = 347151600
417
        tree.commit('setup', timestamp=timestamp)
5718.5.13 by Jelmer Vernooij
Add test for zip with per-file-timestamps.
418
        self.run_bzr('export --per-file-timestamps test.zip branch')
419
        zfile = zipfile.ZipFile('test.zip')
420
        info = zfile.getinfo("test/har")
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
421
        self.assertEqual(time.localtime(timestamp)[:6], info.date_time)
6283.1.12 by Jelmer Vernooij
Add hpss call count test for 'bzr export'.
422
423
424
class TestSmartServerExport(TestCaseWithTransport):
425
426
    def test_simple_export(self):
427
        self.setup_smart_server_with_call_log()
428
        t = self.make_branch_and_tree('branch')
6855.4.1 by Jelmer Vernooij
Yet more bees.
429
        self.build_tree_contents([('branch/foo', b'thecontents')])
6283.1.12 by Jelmer Vernooij
Add hpss call count test for 'bzr export'.
430
        t.add("foo")
431
        t.commit("message")
432
        self.reset_smart_call_log()
7143.15.2 by Jelmer Vernooij
Run autopep8.
433
        out, err = self.run_bzr(
434
            ['export', "foo.tar.gz", self.get_url('branch')])
6283.1.12 by Jelmer Vernooij
Add hpss call count test for 'bzr export'.
435
        # This figure represent the amount of work to perform this use case. It
436
        # is entirely ok to reduce this number if a test fails due to rpc_count
437
        # being too low. If rpc_count increases, more network roundtrips have
438
        # become necessary for this use case. Please do not adjust this number
439
        # upwards without agreement from bzr's network support maintainers.
7240.8.2 by Jelmer Vernooij
Fix tests.
440
        self.assertLength(8, self.hpss_calls)
6366.1.4 by Jelmer Vernooij
Test connection count calls for most blackbox commands.
441
        self.assertLength(1, self.hpss_connections)
6282.6.42 by Jelmer Vernooij
merge hpss-get-checkout-format.
442
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)