~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2011-04-12 04:51:37 UTC
  • Revision ID: aaron@aaronbentley.com-20110412045137-ni3eart33v4wnlst
Allow zap --branch --store if no uncommitted changes.

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_directory,
 
16
    top_path,
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()
123
122
 
124
 
            archive_file = builder(result, 'a')
 
123
            f = file(prefix + 'README', 'wb')
 
124
            f.write('Wow?')
 
125
            f.close()
 
126
            # Add a second entry for README with different contents.
125
127
            archive_file.add(prefix + 'README')
126
128
            archive_file.close()
127
129
 
154
156
            return ZipFileWrapper(fileobj, 'w')
155
157
        return self.make_archive(maker)
156
158
 
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):
 
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')
160
175
 
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']))
165
180
 
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')),
 
225
                             'Wow?')
208
226
            self.assertTrue(not os.path.exists(tree.abspath('FEEDME')))
209
227
        finally:
210
228
            tree.unlock()
222
240
        import_tar(tree, tar_file)
223
241
        self.assertTrue(tree.path2id('README') is not None)
224
242
 
 
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
 
225
249
def test_suite():
226
250
    return makeSuite(TestImport)