~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-07-18 20:57:43 UTC
  • mfrom: (419.1.1 bzrtools.win32)
  • Revision ID: abentley@panoramicfeedback.com-20060718205743-f2f5055504731722
Merge shelf win32 fix

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:
134
135
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
135
136
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
136
137
                               self._import_symlink)
137
 
        os.symlink('missing-file-name',
138
 
                   os.path.join(self._tmpdir, 'tree', 'alink'))
 
138
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
 
139
        os.symlink('missing-file-name', link_path)
139
140
        tree.add_tag('alink')
140
141
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
141
142
        id_file.write('symlink_tag\n')
143
144
        msg = tree.log_message()
144
145
        msg["summary"] = "Import with a symlink"
145
146
        tree.import_(msg)
 
147
        os.unlink(link_path)
 
148
        f = file(link_path, 'w')
 
149
        f.write('Not a symlink no more!')
 
150
        f.close()
 
151
        msg = tree.log_message()
 
152
        msg["summary"] = "Turn a symlink into a file"
 
153
        tree.commit(msg)
146
154
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
147
155
 
148
156
    def make_empty_import(self):
177
185
            pybaz.Version(self._missing_ancestor))
178
186
 
179
187
        # make an import for testing history-reuse logic.
180
 
        def collect(text):
181
 
            pass
182
188
        # note the use of a namespace layout here.
183
189
        self._missing_import_imported = os.path.join(self._tmpdir, 
184
190
                                                     'archivegone-bzr')
186
192
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
187
193
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
188
194
                                    'c', 'import'),
189
 
                       pybaz.Version(self._missing_import),
190
 
                       collect)
 
195
                       pybaz.Version(self._missing_import))
191
196
        # and make it inaccessible
192
197
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
193
198
 
219
224
        TestCaseInTempDir.setUp(self)
220
225
        ResourcedTestCase.setUpResources(self)
221
226
        os.environ['HOME'] = self._baz._homedir
222
 
        self.output = StringIO()
223
227
 
224
228
    def tearDown(self):
225
229
        ResourcedTestCase.tearDownResources(self)
226
230
        TestCaseInTempDir.tearDown(self)
227
231
 
228
 
    def collect(self, text):
229
 
        self.output.write(text)
230
 
        self.output.write("\n")
231
 
 
232
232
    def test_import_empty(self):
233
 
        import_version('output', pybaz.Version(self._baz._import), 
234
 
                       self.collect)
 
233
        import_version('output', pybaz.Version(self._baz._import))
235
234
        # expected results:
236
235
        # one commit, no files, revision identifier of 
237
236
        # 'demo@DONOTUSE_c--import--0--base-0'
241
240
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
242
241
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
243
242
        # and again.
244
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
245
 
                       self.collect)
 
243
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
246
244
        branch2 = Branch.open('output2')
247
245
        repo2 = branch2.repository
248
246
        self.assertEqual(branch.revision_history(), branch2.revision_history())
257
255
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
258
256
 
259
257
    def test_empty_tagged(self):
260
 
        import_version('output', pybaz.Version(self._baz._empty_tag),
261
 
                       self.collect)
 
258
        import_version('output', pybaz.Version(self._baz._empty_tag))
262
259
        # expected results:
263
260
        # two commits, no files, revision identifiers of 
264
261
        # 'demo@DONOTUSE_c--import--0--base-0' and
269
266
                          self._baz._empty_tag_bzr])
270
267
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
271
268
        # and again.
272
 
        import_version('output2', pybaz.Version(self._baz._empty_tag),
273
 
                       self.collect)
 
269
        import_version('output2', pybaz.Version(self._baz._empty_tag))
274
270
        branch2 = Branch.open('output2')
275
271
        self.assertEqual(branch.revision_history(), branch2.revision_history())
276
272
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
284
280
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
285
281
 
286
282
    def test_empty_merged_tagged(self):
287
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
288
 
                       self.collect)
 
283
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
289
284
        # expected results:
290
285
        # two commits, no files, revision identifiers of 
291
286
        # 'demo@DONOTUSE_c--import--0--base-0' and
300
295
                          self._baz._empty_merged_tag_bzr_base,
301
296
                          self._baz._empty_merged_tag_bzr])
302
297
        # and again.
303
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
304
 
                       self.collect)
 
298
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
305
299
        branch2 = Branch.open('output2')
306
300
        repo2 = branch2.repository
307
301
        # 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)
 
302
        import_version('output3', pybaz.Version(self._baz._empty_tag))
310
303
        branch3 = Branch.open('output3')
311
304
        
312
305
        self.assertEqual(branch.revision_history(), branch2.revision_history())
343
336
        # self.assertEqual(branch.missing_revisions(branch3), [])
344
337
        
345
338
    def test_merge_branch_with_merges(self):
346
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
347
 
                       self.collect)
 
339
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
348
340
        # expected results:
349
341
        # two commits, no files, revision identifiers of 
350
342
        # 'demo@DONOTUSE_c--import--0--base-0' and
359
351
                          self._baz._empty_merged_tag_2_bzr_base,
360
352
                          self._baz._empty_merged_tag_2_bzr])
361
353
        # and again.
362
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
363
 
                       self.collect)
 
354
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
364
355
        branch2 = Branch.open('output2')
365
356
        repo2 = branch2.repository
366
357
        # 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)
 
358
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
369
359
        branch3 = Branch.open('output3')
370
360
        
371
361
        self.assertEqual(branch.revision_history(), branch2.revision_history())
402
392
        # self.assertEqual(branch.missing_revisions(branch3), [])
403
393
        
404
394
    def test_import_symlink(self):
405
 
        import_version('output', pybaz.Version(self._baz._import_symlink),
406
 
                       self.collect)
 
395
        import_version('output', pybaz.Version(self._baz._import_symlink), 
 
396
                       max_count=1)
407
397
        # expected results:
408
 
        # one commit, no files, revision identifier of 
 
398
        # two commits, no files, revision identifier of 
409
399
        # 'demo@DONOTUSE_c--import--0--base-0'
410
400
        branch = Branch.open('output')
411
401
        self.assertEqual(branch.revision_history(),
413
403
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
414
404
        # and again.
415
405
        import_version('output2', pybaz.Version(self._baz._import_symlink),
416
 
                       self.collect)
 
406
                       max_count=1)
417
407
        branch2 = Branch.open('output2')
418
408
        self.assertEqual(branch.revision_history(), branch2.revision_history())
419
409
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
432
422
        self.assertEqual(entry.kind, 'symlink')
433
423
        self.assertEqual(entry.symlink_target, 'missing-file-name')
434
424
 
 
425
        # current bzr doesn't handle type changes
 
426
        self.assertRaises(AssertionError, import_version, 'output3',
 
427
                          pybaz.Version(self._baz._import_symlink))
 
428
 
435
429
    def test_missing_ancestor(self):
436
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
437
 
                       self.collect)
 
430
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
438
431
        # expected results:
439
432
        # one commits, no files, revision identifiers of 
440
433
        # 'demo@DONOTUSE_c--gone--0--base-0' and
444
437
                         [self._baz._missing_ancestor_bzr])
445
438
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
446
439
        # and again.
447
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
448
 
                       self.collect)
 
440
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
449
441
        branch2 = Branch.open('output2')
450
442
        self.assertEqual(branch.revision_history(), branch2.revision_history())
451
443
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
466
458
 
467
459
    def test_missing_ancestor_reusing_history(self):
468
460
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
469
 
                       self.collect,
470
461
                       reuse_history_from=[self._baz._missing_import_imported])
471
462
        # expected results:
472
463
        # one commits, no files, revision identifiers of 
479
470
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
480
471
        # and again.
481
472
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
482
 
                       self.collect,
483
473
                       reuse_history_from=[self._baz._missing_import_imported])
484
474
        branch2 = Branch.open('output2')
485
475
        self.assertEqual(branch.revision_history(), branch2.revision_history())
499
489
        self.assertEqual(1, len(rev.parent_ids))
500
490
 
501
491
    def test_bad_file_id(self):
502
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
503
 
                       self.collect)
 
492
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
504
493
        # expected results:
505
494
        # three commits, one files, revision identifiers of 
506
495
        # 'demo@DONOTUSE_c--import--0--base-0' ,
518
507
 
519
508
    def test_appending_revisions_already_present(self):
520
509
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
521
 
                       self.collect, max_count=2)
 
510
                       max_count=2)
522
511
        # expected results:
523
512
        # three commits, one files, revision identifiers of 
524
513
        # 'demo@DONOTUSE_c--import--0--base-0' ,
535
524
        self.assertEqual(branch.revision_history(),
536
525
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
537
526
        del branch
538
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
539
 
                       self.collect)
 
527
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
540
528
        branch = Branch.open('output')
541
529
        self.assertEqual(branch.revision_history(),
542
530
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
548
536
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
549
537
 
550
538
    def test_appending_revisions_all_already_present(self):
551
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
552
 
                       self.collect)
 
539
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
553
540
        # expected results:
554
541
        # three commits, one files, revision identifiers of 
555
542
        # 'demo@DONOTUSE_c--import--0--base-0' ,
567
554
        self.assertEqual(branch.revision_history(),
568
555
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
569
556
        del branch
570
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
571
 
                       self.collect)
 
557
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
572
558
        branch = Branch.open('output')
573
559
        self.assertEqual(branch.revision_history(),
574
560
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
580
566
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
581
567
 
582
568
    def test_inbranch_conversion(self):
583
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag),
584
 
                       self.collect)
 
569
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
585
570
        # expected results:
586
571
        # three commits, no files, revision identifiers of 
587
572
        # 'demo@DONOTUSE_c--import--0--base-0' and
594
579
                          self._baz._inbranch_tag_base_bzr,
595
580
                          self._baz._inbranch_tag_head_bzr])
596
581
        # and again.
597
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag),
598
 
                       self.collect)
 
582
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
599
583
        branch2 = Branch.open('output2')
600
584
        
601
585
        self.assertEqual(branch.revision_history(), branch2.revision_history())
621
605
        self.assertEqual(rev.parent_ids,
622
606
                         [self._baz._inbranch_tag_base_bzr])
623
607
 
 
608
    def test_no_commits_same_as_missing(self):
 
609
        path = 'output'
 
610
        os.mkdir(path)
 
611
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
 
612
        import_version(path, pybaz.Version(self._baz._import))
 
613
        # expected results:
 
614
        # one commit, revision identifier of 
 
615
        # 'demo@DONOTUSE_c--import--0--base-0'
 
616
        self.assertEqual(branch.revision_history(),
 
617
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
 
618
 
624
619
 
625
620
class TestNamespacePrevious(TestCase):
626
621
 
651
646
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
652
647
                         self.version['versionfix-2999'])
653
648
 
 
649
 
654
650
class TestNamespaceMapping(TestCase):
655
651
 
656
652
    def test_namespace_mapping_branch(self):
725
721
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
726
722
                                                    'c1', '0.2','branch')))
727
723
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
728
 
        self.assertEqual(22, walk_len)
 
724
        self.assertEqual(20, walk_len)
729
725
 
730
726
    def test_run_twice(self):
731
727
        self.make_import('c--0')
742
738
        self.make_import('c--0')
743
739
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
744
740
                     'demo@DONOTUSE')
 
741