~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2007-03-07 17:34:37 UTC
  • mfrom: (517.1.2 bzrtools-0.15)
  • Revision ID: abentley@panoramicfeedback.com-20070307173437-mr9o9u21rxm94dq2
Merge 0.15.1 update

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
from bzrlib.bzrdir import BzrDir
10
10
from bzrlib.plugins.bzrtools.upstream_import import (
11
11
    common_directory,
12
 
    import_archive,
13
12
    import_tar,
14
13
    import_zip,
15
14
    import_dir,
16
 
    top_path,
17
 
    ZipFileWrapper,
 
15
    top_directory,
 
16
    ZipFileWrapper, 
18
17
)
19
18
from bzrlib.tests import TestCaseInTempDir
20
19
 
21
 
 
22
 
def import_tar_broken(tree, tar_input):
23
 
    """
24
 
    Import a tarfile with names that that end in //, e.g. Feisty Python 2.5
25
 
    """
26
 
    tar_file = tarfile.open('lala', 'r', tar_input)
27
 
    for member in tar_file.members:
28
 
        if member.name.endswith('/'):
29
 
            member.name += '/'
30
 
    import_archive(tree, tar_file)
31
 
 
32
 
 
33
20
class DirFileWriter(object):
34
21
 
35
22
    def __init__(self, fileobj, mode):
81
68
                os.chdir('project-0.1')
82
69
            os.mkdir(prefix + 'junk')
83
70
            archive_file.add(prefix + 'junk')
84
 
 
 
71
            
85
72
            f = file(prefix + 'README', 'wb')
86
73
            f.write('What?')
87
74
            f.close()
111
98
            else:
112
99
                prefix=''
113
100
                os.chdir('project-0.2')
114
 
 
 
101
            
115
102
            os.mkdir(prefix + 'junk')
116
103
            archive_file.add(prefix + 'junk')
117
104
 
139
126
 
140
127
        os.mkdir('project-0.2')
141
128
        tar_file.add('project-0.2')
142
 
 
 
129
        
143
130
        f = file('project-0.1/README', 'wb')
144
131
        f.write('What?')
145
132
        f.close()
154
141
            return ZipFileWrapper(fileobj, 'w')
155
142
        return self.make_archive(maker)
156
143
 
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'), '/')
161
147
 
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']))
166
152
 
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)
171
157
 
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)
176
 
 
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) 
219
200
 
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) 
225
206
 
226
207
def test_suite():
227
208
    return makeSuite(TestImport)