~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-03-22 22:18:19 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060322221819-0e627e73d1232926
Added zap command

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