6
6
from unittest import makeSuite
8
from bzrlib import osutils
10
revision as _mod_revision,
9
13
from bzrlib.bzrdir import BzrDir
14
from bzrlib.export.tar_exporter import export_tarball
10
15
from bzrlib.plugins.bzrtools.upstream_import import (
19
from bzrlib.tests import TestCaseInTempDir
24
from bzrlib.tests import (
26
TestCaseWithTransport,
22
30
def import_tar_broken(tree, tar_input):
121
129
archive_file.add(prefix + 'README')
124
archive_file = builder(result, 'a')
131
f = file(prefix + 'README', 'wb')
134
# Add a second entry for README with different contents.
125
135
archive_file.add(prefix + 'README')
126
136
archive_file.close()
154
164
return ZipFileWrapper(fileobj, 'w')
155
165
return self.make_archive(maker)
157
def test_top_directory(self):
158
self.assertEqual(top_directory('ab/b/c'), 'ab')
159
self.assertEqual(top_directory('/etc'), '/')
167
def make_tar_with_bzrdir(self):
169
tar_file = tarfile.open('tar-with-bzrdir.tar', 'w', result)
170
os.mkdir('toplevel-dir')
171
tar_file.add('toplevel-dir')
172
os.mkdir('toplevel-dir/.bzr')
173
tar_file.add('toplevel-dir/.bzr')
175
rmtree('toplevel-dir')
179
def test_top_path(self):
180
self.assertEqual(top_path('ab/b/c'), 'ab')
181
self.assertEqual(top_path('etc'), 'etc')
182
self.assertEqual(top_path('project-0.1'), 'project-0.1')
161
184
def test_common_directory(self):
162
185
self.assertEqual(common_directory(['ab/c/d', 'ab/c/e']), 'ab')
163
186
self.assertIs(common_directory(['ab/c/d', 'ac/c/e']), None)
164
self.assertIs(None, common_directory(['FEEDME']))
187
self.assertEqual('FEEDME', common_directory(['FEEDME']))
166
189
def test_untar(self):
167
190
def builder(fileobj, mode='w'):
205
228
archive_file = self.make_archive2(builder, subdir)
206
229
importer(tree, archive_file)
207
230
self.assertTrue(tree.path2id('README') is not None)
231
# Ensure the second version of the file is used.
232
self.assertEqual(tree.get_file_text(tree.path2id('README')),
208
234
self.assertTrue(not os.path.exists(tree.abspath('FEEDME')))
222
248
import_tar(tree, tar_file)
223
249
self.assertTrue(tree.path2id('README') is not None)
251
def test_no_crash_with_bzrdir(self):
252
tar_file = self.make_tar_with_bzrdir()
253
tree = BzrDir.create_standalone_workingtree('tree')
254
import_tar(tree, tar_file)
255
# So long as it did not crash, that should be ok
258
class TestWithStuff(TestCaseWithTransport):
260
def transform_to_tar(self, tt):
262
tarball = tarfile.open(None, 'w|', stream)
263
export_tarball(tt.get_preview_tree(), tarball, '')
266
def get_empty_tt(self):
267
b = self.make_repository('foo')
268
null_tree = b.revision_tree(_mod_revision.NULL_REVISION)
269
tt = transform.TransformPreview(null_tree)
270
root = tt.new_directory('', transform.ROOT_PARENT, 'tree-root')
272
self.addCleanup(tt.finalize)
275
def test_nonascii_paths(self):
276
tt = self.get_empty_tt()
277
encoded_file = tt.new_file(
278
u'\u1234file', tt.root, 'contents', 'new-file')
279
encoded_file = tt.new_file(
280
'other', tt.root, 'contents', 'other-file')
281
tarfile = self.transform_to_tar(tt)
283
tree = self.make_branch_and_tree('bar')
284
import_tar(tree, tarfile)
285
self.assertPathExists(u'bar/\u1234file')
225
288
def test_suite():
226
289
return makeSuite(TestImport)