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