~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2008-10-17 15:10:31 UTC
  • Revision ID: aaron@aaronbentley.com-20081017151031-v9ygg3lvr31evpof
Rename shelve/unshelve to shelve1/unshelve1, alias to old names

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
    import_tar,
14
14
    import_zip,
15
15
    import_dir,
16
 
    top_path,
 
16
    top_directory,
17
17
    ZipFileWrapper,
18
18
)
19
19
from bzrlib.tests import TestCaseInTempDir
119
119
            f.write('Now?')
120
120
            f.close()
121
121
            archive_file.add(prefix + 'README')
 
122
            archive_file.close()
122
123
 
123
 
            f = file(prefix + 'README', 'wb')
124
 
            f.write('Wow?')
125
 
            f.close()
126
 
            # Add a second entry for README with different contents.
 
124
            archive_file = builder(result, 'a')
127
125
            archive_file.add(prefix + 'README')
128
126
            archive_file.close()
129
127
 
156
154
            return ZipFileWrapper(fileobj, 'w')
157
155
        return self.make_archive(maker)
158
156
 
159
 
    def make_tar_with_bzrdir(self):
160
 
        result = StringIO()
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')
166
 
        tar_file.close()
167
 
        rmtree('toplevel-dir')
168
 
        result.seek(0)
169
 
        return result
170
 
 
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')
 
157
    def test_top_directory(self):
 
158
        self.assertEqual(top_directory('ab/b/c'), 'ab')
 
159
        self.assertEqual(top_directory('/etc'), '/')
175
160
 
176
161
    def test_common_directory(self):
177
162
        self.assertEqual(common_directory(['ab/c/d', 'ab/c/e']), 'ab')
178
163
        self.assertIs(common_directory(['ab/c/d', 'ac/c/e']), None)
179
 
        self.assertEqual('FEEDME', common_directory(['FEEDME']))
 
164
        self.assertIs(None, common_directory(['FEEDME']))
180
165
 
181
166
    def test_untar(self):
182
167
        def builder(fileobj, mode='w'):
220
205
            archive_file = self.make_archive2(builder, subdir)
221
206
            importer(tree, archive_file)
222
207
            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')),
225
 
                             'Wow?')
226
208
            self.assertTrue(not os.path.exists(tree.abspath('FEEDME')))
227
209
        finally:
228
210
            tree.unlock()
240
222
        import_tar(tree, tar_file)
241
223
        self.assertTrue(tree.path2id('README') is not None)
242
224
 
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
248
 
 
249
225
def test_suite():
250
226
    return makeSuite(TestImport)