~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-08-28 17:34:34 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060828173434-05b293d593e55dbf
Note that EmptyTree is no longer used

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
from bzrlib.tests import TestCaseInTempDir, TestCase
 
19
from bzrlib import repository
19
20
from bzrlib.osutils import has_symlinks
20
21
try:
21
22
    import pybaz
23
24
    pybaz = None
24
25
import os
25
26
try:
 
27
    from bzrtools import cmd_baz_import
26
28
    from bzrtools.baz_import import (import_version, revision_id,
27
 
                                     cmd_baz_import, make_archive, map_file_id)
 
29
                                      make_archive, map_file_id)
28
30
except ImportError:
 
31
    from bzrlib.plugins.bzrtools import cmd_baz_import 
29
32
    from bzrlib.plugins.bzrtools.baz_import import (import_version, 
30
33
                                                    revision_id,
31
 
                                                    cmd_baz_import,
32
34
                                                    make_archive,
33
35
                                                    map_file_id)
34
 
from bzrlib.errors import NoSuchRevision
35
36
import shutil
36
37
from StringIO import StringIO
37
38
import tempfile
38
39
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
39
40
                               ResourcedTestCase)
40
41
    
 
42
import bzrlib
 
43
from bzrlib.errors import NoSuchRevision
41
44
try:
42
45
    from bzrtools.fai import namespace_previous
43
46
except ImportError:
134
137
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
135
138
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
136
139
                               self._import_symlink)
137
 
        os.symlink('missing-file-name',
138
 
                   os.path.join(self._tmpdir, 'tree', 'alink'))
 
140
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
 
141
        os.symlink('missing-file-name', link_path)
139
142
        tree.add_tag('alink')
140
143
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
141
144
        id_file.write('symlink_tag\n')
143
146
        msg = tree.log_message()
144
147
        msg["summary"] = "Import with a symlink"
145
148
        tree.import_(msg)
 
149
        os.unlink(link_path)
 
150
        f = file(link_path, 'w')
 
151
        f.write('Not a symlink no more!')
 
152
        f.close()
 
153
        msg = tree.log_message()
 
154
        msg["summary"] = "Turn a symlink into a file"
 
155
        tree.commit(msg)
146
156
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
147
157
 
148
158
    def make_empty_import(self):
177
187
            pybaz.Version(self._missing_ancestor))
178
188
 
179
189
        # make an import for testing history-reuse logic.
180
 
        def collect(text):
181
 
            pass
182
190
        # note the use of a namespace layout here.
183
191
        self._missing_import_imported = os.path.join(self._tmpdir, 
184
192
                                                     'archivegone-bzr')
186
194
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
187
195
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
188
196
                                    'c', 'import'),
189
 
                       pybaz.Version(self._missing_import),
190
 
                       collect)
 
197
                       pybaz.Version(self._missing_import))
191
198
        # and make it inaccessible
192
199
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
193
200
 
219
226
        TestCaseInTempDir.setUp(self)
220
227
        ResourcedTestCase.setUpResources(self)
221
228
        os.environ['HOME'] = self._baz._homedir
222
 
        self.output = StringIO()
223
229
 
224
230
    def tearDown(self):
225
231
        ResourcedTestCase.tearDownResources(self)
226
232
        TestCaseInTempDir.tearDown(self)
227
233
 
228
 
    def collect(self, text):
229
 
        self.output.write(text)
230
 
        self.output.write("\n")
231
 
 
232
234
    def test_import_empty(self):
233
 
        import_version('output', pybaz.Version(self._baz._import), 
234
 
                       self.collect)
 
235
        import_version('output', pybaz.Version(self._baz._import))
235
236
        # expected results:
236
237
        # one commit, no files, revision identifier of 
237
238
        # 'demo@DONOTUSE_c--import--0--base-0'
241
242
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
242
243
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
243
244
        # and again.
244
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
245
 
                       self.collect)
 
245
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
246
246
        branch2 = Branch.open('output2')
247
247
        repo2 = branch2.repository
248
248
        self.assertEqual(branch.revision_history(), branch2.revision_history())
257
257
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
258
258
 
259
259
    def test_empty_tagged(self):
260
 
        import_version('output', pybaz.Version(self._baz._empty_tag),
261
 
                       self.collect)
 
260
        import_version('output', pybaz.Version(self._baz._empty_tag))
262
261
        # expected results:
263
262
        # two commits, no files, revision identifiers of 
264
263
        # 'demo@DONOTUSE_c--import--0--base-0' and
269
268
                          self._baz._empty_tag_bzr])
270
269
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
271
270
        # and again.
272
 
        import_version('output2', pybaz.Version(self._baz._empty_tag),
273
 
                       self.collect)
 
271
        import_version('output2', pybaz.Version(self._baz._empty_tag))
274
272
        branch2 = Branch.open('output2')
275
273
        self.assertEqual(branch.revision_history(), branch2.revision_history())
276
274
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
284
282
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
285
283
 
286
284
    def test_empty_merged_tagged(self):
287
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
288
 
                       self.collect)
 
285
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
289
286
        # expected results:
290
287
        # two commits, no files, revision identifiers of 
291
288
        # 'demo@DONOTUSE_c--import--0--base-0' and
300
297
                          self._baz._empty_merged_tag_bzr_base,
301
298
                          self._baz._empty_merged_tag_bzr])
302
299
        # and again.
303
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
304
 
                       self.collect)
 
300
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
305
301
        branch2 = Branch.open('output2')
306
302
        repo2 = branch2.repository
307
303
        # and import what we should be merged up against for checking with.
308
 
        import_version('output3', pybaz.Version(self._baz._empty_tag),
309
 
                       self.collect)
 
304
        import_version('output3', pybaz.Version(self._baz._empty_tag))
310
305
        branch3 = Branch.open('output3')
311
306
        
312
307
        self.assertEqual(branch.revision_history(), branch2.revision_history())
343
338
        # self.assertEqual(branch.missing_revisions(branch3), [])
344
339
        
345
340
    def test_merge_branch_with_merges(self):
346
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
347
 
                       self.collect)
 
341
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
348
342
        # expected results:
349
343
        # two commits, no files, revision identifiers of 
350
344
        # 'demo@DONOTUSE_c--import--0--base-0' and
359
353
                          self._baz._empty_merged_tag_2_bzr_base,
360
354
                          self._baz._empty_merged_tag_2_bzr])
361
355
        # and again.
362
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
363
 
                       self.collect)
 
356
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
364
357
        branch2 = Branch.open('output2')
365
358
        repo2 = branch2.repository
366
359
        # and import what we should be merged up against for checking with.
367
 
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
368
 
                       self.collect)
 
360
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
369
361
        branch3 = Branch.open('output3')
370
362
        
371
363
        self.assertEqual(branch.revision_history(), branch2.revision_history())
402
394
        # self.assertEqual(branch.missing_revisions(branch3), [])
403
395
        
404
396
    def test_import_symlink(self):
405
 
        import_version('output', pybaz.Version(self._baz._import_symlink),
406
 
                       self.collect)
 
397
        import_version('output', pybaz.Version(self._baz._import_symlink), 
 
398
                       max_count=1)
407
399
        # expected results:
408
 
        # one commit, no files, revision identifier of 
 
400
        # two commits, no files, revision identifier of 
409
401
        # 'demo@DONOTUSE_c--import--0--base-0'
410
402
        branch = Branch.open('output')
411
403
        self.assertEqual(branch.revision_history(),
413
405
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
414
406
        # and again.
415
407
        import_version('output2', pybaz.Version(self._baz._import_symlink),
416
 
                       self.collect)
 
408
                       max_count=1)
417
409
        branch2 = Branch.open('output2')
418
410
        self.assertEqual(branch.revision_history(), branch2.revision_history())
419
411
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
432
424
        self.assertEqual(entry.kind, 'symlink')
433
425
        self.assertEqual(entry.symlink_target, 'missing-file-name')
434
426
 
 
427
        # current bzr doesn't handle type changes
 
428
        self.assertRaises(AssertionError, import_version, 'output3',
 
429
                          pybaz.Version(self._baz._import_symlink))
 
430
 
435
431
    def test_missing_ancestor(self):
436
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
437
 
                       self.collect)
 
432
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
438
433
        # expected results:
439
434
        # one commits, no files, revision identifiers of 
440
435
        # 'demo@DONOTUSE_c--gone--0--base-0' and
444
439
                         [self._baz._missing_ancestor_bzr])
445
440
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
446
441
        # and again.
447
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
448
 
                       self.collect)
 
442
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
449
443
        branch2 = Branch.open('output2')
450
444
        self.assertEqual(branch.revision_history(), branch2.revision_history())
451
445
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
466
460
 
467
461
    def test_missing_ancestor_reusing_history(self):
468
462
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
469
 
                       self.collect,
470
463
                       reuse_history_from=[self._baz._missing_import_imported])
471
464
        # expected results:
472
465
        # one commits, no files, revision identifiers of 
479
472
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
480
473
        # and again.
481
474
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
482
 
                       self.collect,
483
475
                       reuse_history_from=[self._baz._missing_import_imported])
484
476
        branch2 = Branch.open('output2')
485
477
        self.assertEqual(branch.revision_history(), branch2.revision_history())
499
491
        self.assertEqual(1, len(rev.parent_ids))
500
492
 
501
493
    def test_bad_file_id(self):
502
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
503
 
                       self.collect)
 
494
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
504
495
        # expected results:
505
496
        # three commits, one files, revision identifiers of 
506
497
        # 'demo@DONOTUSE_c--import--0--base-0' ,
518
509
 
519
510
    def test_appending_revisions_already_present(self):
520
511
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
521
 
                       self.collect, max_count=2)
 
512
                       max_count=2)
522
513
        # expected results:
523
514
        # three commits, one files, revision identifiers of 
524
515
        # 'demo@DONOTUSE_c--import--0--base-0' ,
535
526
        self.assertEqual(branch.revision_history(),
536
527
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
537
528
        del branch
538
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
539
 
                       self.collect)
 
529
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
540
530
        branch = Branch.open('output')
541
531
        self.assertEqual(branch.revision_history(),
542
532
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
548
538
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
549
539
 
550
540
    def test_appending_revisions_all_already_present(self):
551
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
552
 
                       self.collect)
 
541
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
553
542
        # expected results:
554
543
        # three commits, one files, revision identifiers of 
555
544
        # 'demo@DONOTUSE_c--import--0--base-0' ,
567
556
        self.assertEqual(branch.revision_history(),
568
557
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
569
558
        del branch
570
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
571
 
                       self.collect)
 
559
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
572
560
        branch = Branch.open('output')
573
561
        self.assertEqual(branch.revision_history(),
574
562
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
580
568
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
581
569
 
582
570
    def test_inbranch_conversion(self):
583
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag),
584
 
                       self.collect)
 
571
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
585
572
        # expected results:
586
573
        # three commits, no files, revision identifiers of 
587
574
        # 'demo@DONOTUSE_c--import--0--base-0' and
594
581
                          self._baz._inbranch_tag_base_bzr,
595
582
                          self._baz._inbranch_tag_head_bzr])
596
583
        # and again.
597
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag),
598
 
                       self.collect)
 
584
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
599
585
        branch2 = Branch.open('output2')
600
586
        
601
587
        self.assertEqual(branch.revision_history(), branch2.revision_history())
621
607
        self.assertEqual(rev.parent_ids,
622
608
                         [self._baz._inbranch_tag_base_bzr])
623
609
 
 
610
    def test_no_commits_same_as_missing(self):
 
611
        path = 'output'
 
612
        os.mkdir(path)
 
613
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
 
614
        import_version(path, pybaz.Version(self._baz._import))
 
615
        # expected results:
 
616
        # one commit, revision identifier of 
 
617
        # 'demo@DONOTUSE_c--import--0--base-0'
 
618
        self.assertEqual(branch.revision_history(),
 
619
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
 
620
 
624
621
 
625
622
class TestNamespacePrevious(TestCase):
626
623
 
651
648
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
652
649
                         self.version['versionfix-2999'])
653
650
 
 
651
 
654
652
class TestNamespaceMapping(TestCase):
655
653
 
656
654
    def test_namespace_mapping_branch(self):
705
703
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
706
704
 
707
705
    def test_cmd_exists(self):
708
 
        from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
 
706
        from bzrlib.plugins.bzrtools import cmd_baz_import
709
707
 
710
708
    def test_empty_archive(self):
711
709
        command = cmd_baz_import()
724
722
                                       'c','+trunk')))
725
723
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
726
724
                                                    'c1', '0.2','branch')))
 
725
        default_format = repository.RepositoryFormat.get_default_format()
 
726
        if getattr(default_format, 'rich_root_data', False):
 
727
            num_files = 21
 
728
        else:
 
729
            num_files = 20
727
730
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
728
 
        self.assertEqual(22, walk_len)
 
731
        self.assertEqual(num_files, walk_len)
729
732
 
730
733
    def test_run_twice(self):
731
734
        self.make_import('c--0')
742
745
        self.make_import('c--0')
743
746
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
744
747
                     'demo@DONOTUSE')
 
748