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