9
9
from bzrlib.bzrdir import BzrDir
10
10
from bzrlib.plugins.bzrtools.upstream_import import (
19
18
from bzrlib.tests import TestCaseInTempDir
22
def import_tar_broken(tree, tar_input):
24
Import a tarfile with names that that end in //, e.g. Feisty Python 2.5
26
tar_file = tarfile.open('lala', 'r', tar_input)
27
for member in tar_file.members:
28
if member.name.endswith('/'):
30
import_archive(tree, tar_file)
33
20
class DirFileWriter(object):
35
22
def __init__(self, fileobj, mode):
154
141
return ZipFileWrapper(fileobj, 'w')
155
142
return self.make_archive(maker)
157
def test_top_path(self):
158
self.assertEqual(top_path('ab/b/c'), 'ab')
159
self.assertEqual(top_path('etc'), 'etc')
160
self.assertEqual(top_path('project-0.1'), 'project-0.1')
144
def test_top_directory(self):
145
self.assertEqual(top_directory('ab/b/c'), 'ab')
146
self.assertEqual(top_directory('/etc'), '/')
162
148
def test_common_directory(self):
163
149
self.assertEqual(common_directory(['ab/c/d', 'ab/c/e']), 'ab')
164
150
self.assertIs(common_directory(['ab/c/d', 'ac/c/e']), None)
165
self.assertEqual('FEEDME', common_directory(['FEEDME']))
151
self.assertIs(None, common_directory(['FEEDME']))
167
153
def test_untar(self):
168
154
def builder(fileobj, mode='w'):
169
155
return tarfile.open('project-0.1.tar', mode, fileobj)
170
156
self.archive_test(builder, import_tar)
172
def test_broken_tar(self):
173
def builder(fileobj, mode='w'):
174
return tarfile.open('project-0.1.tar', mode, fileobj)
175
self.archive_test(builder, import_tar_broken, subdir=True)
177
158
def test_unzip(self):
178
159
def builder(fileobj, mode='w'):
179
160
return ZipFileWrapper(fileobj, mode)
215
196
tar_file = self.make_messed_tar()
216
197
tree = BzrDir.create_standalone_workingtree('tree')
217
198
import_tar(tree, tar_file)
218
self.assertTrue(tree.path2id('project-0.1/README') is not None)
199
self.assertTrue(tree.path2id('project-0.1/README') is not None)
220
201
def test_untar_gzip(self):
221
202
tar_file = self.make_tar(mode='w:gz')
222
203
tree = BzrDir.create_standalone_workingtree('tree')
223
204
import_tar(tree, tar_file)
224
self.assertTrue(tree.path2id('README') is not None)
205
self.assertTrue(tree.path2id('README') is not None)
226
207
def test_suite():
227
208
return makeSuite(TestImport)