121
121
archive_file.add(prefix + 'README')
124
archive_file = builder(result, 'a')
123
f = file(prefix + 'README', 'wb')
126
# Add a second entry for README with different contents.
125
127
archive_file.add(prefix + 'README')
126
128
archive_file.close()
154
156
return ZipFileWrapper(fileobj, 'w')
155
157
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'), '/')
159
def make_tar_with_bzrdir(self):
161
tar_file = tarfile.open('tar-with-bzrdir.tar', 'w', result)
162
os.mkdir('toplevel-dir')
163
tar_file.add('toplevel-dir')
164
os.mkdir('toplevel-dir/.bzr')
165
tar_file.add('toplevel-dir/.bzr')
167
rmtree('toplevel-dir')
171
def test_top_path(self):
172
self.assertEqual(top_path('ab/b/c'), 'ab')
173
self.assertEqual(top_path('etc'), 'etc')
174
self.assertEqual(top_path('project-0.1'), 'project-0.1')
161
176
def test_common_directory(self):
162
177
self.assertEqual(common_directory(['ab/c/d', 'ab/c/e']), 'ab')
163
178
self.assertIs(common_directory(['ab/c/d', 'ac/c/e']), None)
164
self.assertIs(None, common_directory(['FEEDME']))
179
self.assertEqual('FEEDME', common_directory(['FEEDME']))
166
181
def test_untar(self):
167
182
def builder(fileobj, mode='w'):
205
220
archive_file = self.make_archive2(builder, subdir)
206
221
importer(tree, archive_file)
207
222
self.assertTrue(tree.path2id('README') is not None)
223
# Ensure the second version of the file is used.
224
self.assertEqual(tree.get_file_text(tree.path2id('README')),
208
226
self.assertTrue(not os.path.exists(tree.abspath('FEEDME')))
222
240
import_tar(tree, tar_file)
223
241
self.assertTrue(tree.path2id('README') is not None)
243
def test_no_crash_with_bzrdir(self):
244
tar_file = self.make_tar_with_bzrdir()
245
tree = BzrDir.create_standalone_workingtree('tree')
246
import_tar(tree, tar_file)
247
# So long as it did not crash, that should be ok
225
249
def test_suite():
226
250
return makeSuite(TestImport)