~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

Merged shell readline fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import tempfile
6
6
from unittest import makeSuite
7
7
 
8
 
from bzrlib import (
9
 
    osutils,
10
 
    revision as _mod_revision,
11
 
    transform
12
 
    )
 
8
from bzrlib import osutils
13
9
from bzrlib.bzrdir import BzrDir
14
 
from bzrlib.export import export
15
 
from bzrlib.plugins.bzrtools import errors
16
10
from bzrlib.plugins.bzrtools.upstream_import import (
17
11
    common_directory,
18
 
    get_archive_type,
19
12
    import_archive,
20
13
    import_tar,
21
14
    import_zip,
23
16
    top_path,
24
17
    ZipFileWrapper,
25
18
)
26
 
from bzrlib.tests import (
27
 
    TestCaseInTempDir,
28
 
    TestCaseWithTransport,
29
 
    )
30
 
try:
31
 
    from bzrlib.tests.features import UnicodeFilenameFeature
32
 
except ImportError: # bzr < 2.5
33
 
    from bzrlib.tests import UnicodeFilenameFeature
 
19
from bzrlib.tests import TestCaseInTempDir
34
20
 
35
21
 
36
22
def import_tar_broken(tree, tar_input):
260
246
        import_tar(tree, tar_file)
261
247
        # So long as it did not crash, that should be ok
262
248
 
263
 
    def test_get_archive_type(self):
264
 
        self.assertEqual(('tar', None), get_archive_type('foo.tar'))
265
 
        self.assertEqual(('zip', None), get_archive_type('foo.zip'))
266
 
        self.assertRaises(errors.NotArchiveType, get_archive_type, 'foo.gif')
267
 
        self.assertEqual(('tar', 'gz'), get_archive_type('foo.tar.gz'))
268
 
        self.assertRaises(errors.NotArchiveType, get_archive_type,
269
 
                          'foo.zip.gz')
270
 
        self.assertEqual(('tar', 'gz'), get_archive_type('foo.tgz'))
271
 
        self.assertEqual(('tar', 'lzma'), get_archive_type('foo.tar.lzma'))
272
 
        self.assertEqual(('tar', 'lzma'), get_archive_type('foo.tar.xz'))
273
 
        self.assertEqual(('tar', 'bz2'), get_archive_type('foo.tar.bz2'))
274
 
 
275
 
 
276
 
class TestWithStuff(TestCaseWithTransport):
277
 
 
278
 
    def transform_to_tar(self, tt):
279
 
        stream = StringIO()
280
 
        export(tt.get_preview_tree(), root='', fileobj=stream, format='tar',
281
 
               dest=None)
282
 
        return stream
283
 
 
284
 
    def get_empty_tt(self):
285
 
        b = self.make_repository('foo')
286
 
        null_tree = b.revision_tree(_mod_revision.NULL_REVISION)
287
 
        tt = transform.TransformPreview(null_tree)
288
 
        root = tt.new_directory('', transform.ROOT_PARENT, 'tree-root')
289
 
        tt.fixup_new_roots()
290
 
        self.addCleanup(tt.finalize)
291
 
        return tt
292
 
 
293
 
    def test_nonascii_paths(self):
294
 
        self.requireFeature(UnicodeFilenameFeature)
295
 
        tt = self.get_empty_tt()
296
 
        encoded_file = tt.new_file(
297
 
            u'\u1234file', tt.root, 'contents', 'new-file')
298
 
        encoded_file = tt.new_file(
299
 
            'other', tt.root, 'contents', 'other-file')
300
 
        tarfile = self.transform_to_tar(tt)
301
 
        tarfile.seek(0)
302
 
        tree = self.make_branch_and_tree('bar')
303
 
        import_tar(tree, tarfile)
304
 
        self.assertPathExists(u'bar/\u1234file')
305
 
 
306
 
 
307
249
def test_suite():
308
250
    return makeSuite(TestImport)