~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2011-05-10 01:44:18 UTC
  • Revision ID: aaron@aaronbentley.com-20110510014418-lroa0d6po8h800dn
Fix non-ascii tarball handling

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 osutils
 
8
from bzrlib import (
 
9
    osutils,
 
10
    revision as _mod_revision,
 
11
    transform
 
12
    )
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 (
11
16
    common_directory,
12
17
    import_archive,
16
21
    top_path,
17
22
    ZipFileWrapper,
18
23
)
19
 
from bzrlib.tests import TestCaseInTempDir
 
24
from bzrlib.tests import (
 
25
    TestCaseInTempDir,
 
26
    TestCaseWithTransport,
 
27
    )
20
28
 
21
29
 
22
30
def import_tar_broken(tree, tar_input):
246
254
        import_tar(tree, tar_file)
247
255
        # So long as it did not crash, that should be ok
248
256
 
 
257
 
 
258
class TestWithStuff(TestCaseWithTransport):
 
259
 
 
260
    def transform_to_tar(self, tt):
 
261
        stream = StringIO()
 
262
        tarball = tarfile.open(None, 'w|', stream)
 
263
        export_tarball(tt.get_preview_tree(), tarball, '')
 
264
        return stream
 
265
 
 
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')
 
271
        tt.fixup_new_roots()
 
272
        self.addCleanup(tt.finalize)
 
273
        return tt
 
274
 
 
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)
 
282
        tarfile.seek(0)
 
283
        tree = self.make_branch_and_tree('bar')
 
284
        import_tar(tree, tarfile)
 
285
        self.assertPathExists(u'bar/\u1234file')
 
286
 
 
287
 
249
288
def test_suite():
250
289
    return makeSuite(TestImport)