~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Robert Collins
  • Date: 2006-04-24 01:35:08 UTC
  • mto: (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 366.
  • Revision ID: robertc@robertcollins.net-20060424013508-2d37e47814d9493e
Support importing into empty branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
                                                    cmd_baz_import,
32
32
                                                    make_archive,
33
33
                                                    map_file_id)
34
 
from bzrlib.errors import NoSuchRevision
35
34
import shutil
36
35
from StringIO import StringIO
37
36
import tempfile
38
37
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
39
38
                               ResourcedTestCase)
40
39
    
 
40
import bzrlib
 
41
from bzrlib.errors import NoSuchRevision
41
42
try:
42
43
    from bzrtools.fai import namespace_previous
43
44
except ImportError:
177
178
            pybaz.Version(self._missing_ancestor))
178
179
 
179
180
        # make an import for testing history-reuse logic.
180
 
        def collect(text):
181
 
            pass
182
181
        # note the use of a namespace layout here.
183
182
        self._missing_import_imported = os.path.join(self._tmpdir, 
184
183
                                                     'archivegone-bzr')
186
185
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
187
186
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
188
187
                                    'c', 'import'),
189
 
                       pybaz.Version(self._missing_import),
190
 
                       collect)
 
188
                       pybaz.Version(self._missing_import))
191
189
        # and make it inaccessible
192
190
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
193
191
 
219
217
        TestCaseInTempDir.setUp(self)
220
218
        ResourcedTestCase.setUpResources(self)
221
219
        os.environ['HOME'] = self._baz._homedir
222
 
        self.output = StringIO()
223
220
 
224
221
    def tearDown(self):
225
222
        ResourcedTestCase.tearDownResources(self)
226
223
        TestCaseInTempDir.tearDown(self)
227
224
 
228
 
    def collect(self, text):
229
 
        self.output.write(text)
230
 
        self.output.write("\n")
231
 
 
232
225
    def test_import_empty(self):
233
 
        import_version('output', pybaz.Version(self._baz._import), 
234
 
                       self.collect)
 
226
        import_version('output', pybaz.Version(self._baz._import))
235
227
        # expected results:
236
228
        # one commit, no files, revision identifier of 
237
229
        # 'demo@DONOTUSE_c--import--0--base-0'
241
233
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
242
234
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
243
235
        # and again.
244
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
245
 
                       self.collect)
 
236
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
246
237
        branch2 = Branch.open('output2')
247
238
        repo2 = branch2.repository
248
239
        self.assertEqual(branch.revision_history(), branch2.revision_history())
257
248
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
258
249
 
259
250
    def test_empty_tagged(self):
260
 
        import_version('output', pybaz.Version(self._baz._empty_tag),
261
 
                       self.collect)
 
251
        import_version('output', pybaz.Version(self._baz._empty_tag))
262
252
        # expected results:
263
253
        # two commits, no files, revision identifiers of 
264
254
        # 'demo@DONOTUSE_c--import--0--base-0' and
269
259
                          self._baz._empty_tag_bzr])
270
260
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
271
261
        # and again.
272
 
        import_version('output2', pybaz.Version(self._baz._empty_tag),
273
 
                       self.collect)
 
262
        import_version('output2', pybaz.Version(self._baz._empty_tag))
274
263
        branch2 = Branch.open('output2')
275
264
        self.assertEqual(branch.revision_history(), branch2.revision_history())
276
265
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
284
273
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
285
274
 
286
275
    def test_empty_merged_tagged(self):
287
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
288
 
                       self.collect)
 
276
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
289
277
        # expected results:
290
278
        # two commits, no files, revision identifiers of 
291
279
        # 'demo@DONOTUSE_c--import--0--base-0' and
300
288
                          self._baz._empty_merged_tag_bzr_base,
301
289
                          self._baz._empty_merged_tag_bzr])
302
290
        # and again.
303
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
304
 
                       self.collect)
 
291
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
305
292
        branch2 = Branch.open('output2')
306
293
        repo2 = branch2.repository
307
294
        # 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)
 
295
        import_version('output3', pybaz.Version(self._baz._empty_tag))
310
296
        branch3 = Branch.open('output3')
311
297
        
312
298
        self.assertEqual(branch.revision_history(), branch2.revision_history())
343
329
        # self.assertEqual(branch.missing_revisions(branch3), [])
344
330
        
345
331
    def test_merge_branch_with_merges(self):
346
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
347
 
                       self.collect)
 
332
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
348
333
        # expected results:
349
334
        # two commits, no files, revision identifiers of 
350
335
        # 'demo@DONOTUSE_c--import--0--base-0' and
359
344
                          self._baz._empty_merged_tag_2_bzr_base,
360
345
                          self._baz._empty_merged_tag_2_bzr])
361
346
        # and again.
362
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
363
 
                       self.collect)
 
347
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
364
348
        branch2 = Branch.open('output2')
365
349
        repo2 = branch2.repository
366
350
        # 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)
 
351
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
369
352
        branch3 = Branch.open('output3')
370
353
        
371
354
        self.assertEqual(branch.revision_history(), branch2.revision_history())
402
385
        # self.assertEqual(branch.missing_revisions(branch3), [])
403
386
        
404
387
    def test_import_symlink(self):
405
 
        import_version('output', pybaz.Version(self._baz._import_symlink),
406
 
                       self.collect)
 
388
        import_version('output', pybaz.Version(self._baz._import_symlink))
407
389
        # expected results:
408
390
        # one commit, no files, revision identifier of 
409
391
        # 'demo@DONOTUSE_c--import--0--base-0'
412
394
                         [self._baz._import_symlink_bzr])
413
395
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
414
396
        # and again.
415
 
        import_version('output2', pybaz.Version(self._baz._import_symlink),
416
 
                       self.collect)
 
397
        import_version('output2', pybaz.Version(self._baz._import_symlink))
417
398
        branch2 = Branch.open('output2')
418
399
        self.assertEqual(branch.revision_history(), branch2.revision_history())
419
400
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
433
414
        self.assertEqual(entry.symlink_target, 'missing-file-name')
434
415
 
435
416
    def test_missing_ancestor(self):
436
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
437
 
                       self.collect)
 
417
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
438
418
        # expected results:
439
419
        # one commits, no files, revision identifiers of 
440
420
        # 'demo@DONOTUSE_c--gone--0--base-0' and
444
424
                         [self._baz._missing_ancestor_bzr])
445
425
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
446
426
        # and again.
447
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
448
 
                       self.collect)
 
427
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
449
428
        branch2 = Branch.open('output2')
450
429
        self.assertEqual(branch.revision_history(), branch2.revision_history())
451
430
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
466
445
 
467
446
    def test_missing_ancestor_reusing_history(self):
468
447
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
469
 
                       self.collect,
470
448
                       reuse_history_from=[self._baz._missing_import_imported])
471
449
        # expected results:
472
450
        # one commits, no files, revision identifiers of 
479
457
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
480
458
        # and again.
481
459
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
482
 
                       self.collect,
483
460
                       reuse_history_from=[self._baz._missing_import_imported])
484
461
        branch2 = Branch.open('output2')
485
462
        self.assertEqual(branch.revision_history(), branch2.revision_history())
499
476
        self.assertEqual(1, len(rev.parent_ids))
500
477
 
501
478
    def test_bad_file_id(self):
502
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
503
 
                       self.collect)
 
479
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
504
480
        # expected results:
505
481
        # three commits, one files, revision identifiers of 
506
482
        # 'demo@DONOTUSE_c--import--0--base-0' ,
518
494
 
519
495
    def test_appending_revisions_already_present(self):
520
496
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
521
 
                       self.collect, max_count=2)
 
497
                       max_count=2)
522
498
        # expected results:
523
499
        # three commits, one files, revision identifiers of 
524
500
        # 'demo@DONOTUSE_c--import--0--base-0' ,
535
511
        self.assertEqual(branch.revision_history(),
536
512
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
537
513
        del branch
538
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
539
 
                       self.collect)
 
514
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
540
515
        branch = Branch.open('output')
541
516
        self.assertEqual(branch.revision_history(),
542
517
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
548
523
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
549
524
 
550
525
    def test_appending_revisions_all_already_present(self):
551
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
552
 
                       self.collect)
 
526
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
553
527
        # expected results:
554
528
        # three commits, one files, revision identifiers of 
555
529
        # 'demo@DONOTUSE_c--import--0--base-0' ,
567
541
        self.assertEqual(branch.revision_history(),
568
542
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
569
543
        del branch
570
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
571
 
                       self.collect)
 
544
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
572
545
        branch = Branch.open('output')
573
546
        self.assertEqual(branch.revision_history(),
574
547
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
580
553
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
581
554
 
582
555
    def test_inbranch_conversion(self):
583
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag),
584
 
                       self.collect)
 
556
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
585
557
        # expected results:
586
558
        # three commits, no files, revision identifiers of 
587
559
        # 'demo@DONOTUSE_c--import--0--base-0' and
594
566
                          self._baz._inbranch_tag_base_bzr,
595
567
                          self._baz._inbranch_tag_head_bzr])
596
568
        # and again.
597
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag),
598
 
                       self.collect)
 
569
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
599
570
        branch2 = Branch.open('output2')
600
571
        
601
572
        self.assertEqual(branch.revision_history(), branch2.revision_history())
621
592
        self.assertEqual(rev.parent_ids,
622
593
                         [self._baz._inbranch_tag_base_bzr])
623
594
 
 
595
    def test_no_commits_same_as_missing(self):
 
596
        path = 'output'
 
597
        os.mkdir(path)
 
598
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
 
599
        import_version(path, pybaz.Version(self._baz._import))
 
600
        # expected results:
 
601
        # one commit, revision identifier of 
 
602
        # 'demo@DONOTUSE_c--import--0--base-0'
 
603
        self.assertEqual(branch.revision_history(),
 
604
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
 
605
 
624
606
 
625
607
class TestNamespacePrevious(TestCase):
626
608
 
651
633
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
652
634
                         self.version['versionfix-2999'])
653
635
 
 
636
 
654
637
class TestNamespaceMapping(TestCase):
655
638
 
656
639
    def test_namespace_mapping_branch(self):
742
725
        self.make_import('c--0')
743
726
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
744
727
                     'demo@DONOTUSE')
 
728