~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-16 05:48:38 UTC
  • mfrom: (321.2.5 bzrtools)
  • Revision ID: aaron.bentley@utoronto.ca-20060316054838-a59dfe944c17b493
Got push working with new-format branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
except ImportError:
23
23
    pybaz = None
24
24
import os
25
 
try:
26
 
    from bzrtools.baz_import import (import_version, revision_id,
27
 
                                     cmd_baz_import, make_archive, map_file_id)
28
 
except ImportError:
29
 
    from bzrlib.plugins.bzrtools.baz_import import (import_version, 
30
 
                                                    revision_id,
31
 
                                                    cmd_baz_import,
32
 
                                                    make_archive,
33
 
                                                    map_file_id)
 
25
from bzrlib.plugins.bzrtools.baz_import import (import_version, revision_id, 
 
26
                                                cmd_baz_import, make_archive)
 
27
from bzrlib.errors import NoSuchRevision
34
28
import shutil
35
29
from StringIO import StringIO
36
30
import tempfile
37
31
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
38
32
                               ResourcedTestCase)
39
33
    
40
 
import bzrlib
41
 
from bzrlib.errors import NoSuchRevision
42
 
try:
43
 
    from bzrtools.fai import namespace_previous
44
 
except ImportError:
45
 
    from bzrlib.plugins.bzrtools.fai import namespace_previous
 
34
from bzrlib.plugins.bzrtools.fai import namespace_previous
46
35
from bzrlib.branch import Branch
47
36
 
48
37
def test_suite():
135
124
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
136
125
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
137
126
                               self._import_symlink)
138
 
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
139
 
        os.symlink('missing-file-name', link_path)
 
127
        os.symlink('missing-file-name',
 
128
                   os.path.join(self._tmpdir, 'tree', 'alink'))
140
129
        tree.add_tag('alink')
141
130
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
142
131
        id_file.write('symlink_tag\n')
144
133
        msg = tree.log_message()
145
134
        msg["summary"] = "Import with a symlink"
146
135
        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)
154
136
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
155
137
 
156
138
    def make_empty_import(self):
185
167
            pybaz.Version(self._missing_ancestor))
186
168
 
187
169
        # make an import for testing history-reuse logic.
 
170
        def collect(text):
 
171
            pass
188
172
        # note the use of a namespace layout here.
189
173
        self._missing_import_imported = os.path.join(self._tmpdir, 
190
174
                                                     'archivegone-bzr')
192
176
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
193
177
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
194
178
                                    'c', 'import'),
195
 
                       pybaz.Version(self._missing_import))
 
179
                       pybaz.Version(self._missing_import),
 
180
                       collect)
196
181
        # and make it inaccessible
197
182
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
198
183
 
224
209
        TestCaseInTempDir.setUp(self)
225
210
        ResourcedTestCase.setUpResources(self)
226
211
        os.environ['HOME'] = self._baz._homedir
 
212
        self.output = StringIO()
227
213
 
228
214
    def tearDown(self):
229
215
        ResourcedTestCase.tearDownResources(self)
230
216
        TestCaseInTempDir.tearDown(self)
231
217
 
 
218
    def collect(self, text):
 
219
        self.output.write(text)
 
220
        self.output.write("\n")
 
221
 
232
222
    def test_import_empty(self):
233
 
        import_version('output', pybaz.Version(self._baz._import))
 
223
        import_version('output', pybaz.Version(self._baz._import), 
 
224
                       self.collect)
234
225
        # expected results:
235
226
        # one commit, no files, revision identifier of 
236
227
        # 'demo@DONOTUSE_c--import--0--base-0'
240
231
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
241
232
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
242
233
        # and again.
243
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
 
234
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
 
235
                       self.collect)
244
236
        branch2 = Branch.open('output2')
245
237
        repo2 = branch2.repository
246
238
        self.assertEqual(branch.revision_history(), branch2.revision_history())
255
247
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
256
248
 
257
249
    def test_empty_tagged(self):
258
 
        import_version('output', pybaz.Version(self._baz._empty_tag))
 
250
        import_version('output', pybaz.Version(self._baz._empty_tag),
 
251
                       self.collect)
259
252
        # expected results:
260
253
        # two commits, no files, revision identifiers of 
261
254
        # 'demo@DONOTUSE_c--import--0--base-0' and
266
259
                          self._baz._empty_tag_bzr])
267
260
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
268
261
        # and again.
269
 
        import_version('output2', pybaz.Version(self._baz._empty_tag))
 
262
        import_version('output2', pybaz.Version(self._baz._empty_tag),
 
263
                       self.collect)
270
264
        branch2 = Branch.open('output2')
271
265
        self.assertEqual(branch.revision_history(), branch2.revision_history())
272
266
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
280
274
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
281
275
 
282
276
    def test_empty_merged_tagged(self):
283
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
 
277
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
 
278
                       self.collect)
284
279
        # expected results:
285
280
        # two commits, no files, revision identifiers of 
286
281
        # 'demo@DONOTUSE_c--import--0--base-0' and
295
290
                          self._baz._empty_merged_tag_bzr_base,
296
291
                          self._baz._empty_merged_tag_bzr])
297
292
        # and again.
298
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
 
293
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
 
294
                       self.collect)
299
295
        branch2 = Branch.open('output2')
300
296
        repo2 = branch2.repository
301
297
        # and import what we should be merged up against for checking with.
302
 
        import_version('output3', pybaz.Version(self._baz._empty_tag))
 
298
        import_version('output3', pybaz.Version(self._baz._empty_tag),
 
299
                       self.collect)
303
300
        branch3 = Branch.open('output3')
304
301
        
305
302
        self.assertEqual(branch.revision_history(), branch2.revision_history())
336
333
        # self.assertEqual(branch.missing_revisions(branch3), [])
337
334
        
338
335
    def test_merge_branch_with_merges(self):
339
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
 
336
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
 
337
                       self.collect)
340
338
        # expected results:
341
339
        # two commits, no files, revision identifiers of 
342
340
        # 'demo@DONOTUSE_c--import--0--base-0' and
351
349
                          self._baz._empty_merged_tag_2_bzr_base,
352
350
                          self._baz._empty_merged_tag_2_bzr])
353
351
        # and again.
354
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
 
352
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
 
353
                       self.collect)
355
354
        branch2 = Branch.open('output2')
356
355
        repo2 = branch2.repository
357
356
        # and import what we should be merged up against for checking with.
358
 
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
 
357
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
 
358
                       self.collect)
359
359
        branch3 = Branch.open('output3')
360
360
        
361
361
        self.assertEqual(branch.revision_history(), branch2.revision_history())
392
392
        # self.assertEqual(branch.missing_revisions(branch3), [])
393
393
        
394
394
    def test_import_symlink(self):
395
 
        import_version('output', pybaz.Version(self._baz._import_symlink), 
396
 
                       max_count=1)
 
395
        import_version('output', pybaz.Version(self._baz._import_symlink),
 
396
                       self.collect)
397
397
        # expected results:
398
 
        # two commits, no files, revision identifier of 
 
398
        # one commit, no files, revision identifier of 
399
399
        # 'demo@DONOTUSE_c--import--0--base-0'
400
400
        branch = Branch.open('output')
401
401
        self.assertEqual(branch.revision_history(),
403
403
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
404
404
        # and again.
405
405
        import_version('output2', pybaz.Version(self._baz._import_symlink),
406
 
                       max_count=1)
 
406
                       self.collect)
407
407
        branch2 = Branch.open('output2')
408
408
        self.assertEqual(branch.revision_history(), branch2.revision_history())
409
409
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
422
422
        self.assertEqual(entry.kind, 'symlink')
423
423
        self.assertEqual(entry.symlink_target, 'missing-file-name')
424
424
 
425
 
        # current bzr doesn't handle type changes
426
 
        self.assertRaises(AssertionError, import_version, 'output3',
427
 
                          pybaz.Version(self._baz._import_symlink))
428
 
 
429
425
    def test_missing_ancestor(self):
430
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
 
426
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
 
427
                       self.collect)
431
428
        # expected results:
432
429
        # one commits, no files, revision identifiers of 
433
430
        # 'demo@DONOTUSE_c--gone--0--base-0' and
437
434
                         [self._baz._missing_ancestor_bzr])
438
435
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
439
436
        # and again.
440
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
 
437
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
 
438
                       self.collect)
441
439
        branch2 = Branch.open('output2')
442
440
        self.assertEqual(branch.revision_history(), branch2.revision_history())
443
441
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
458
456
 
459
457
    def test_missing_ancestor_reusing_history(self):
460
458
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
 
459
                       self.collect,
461
460
                       reuse_history_from=[self._baz._missing_import_imported])
462
461
        # expected results:
463
462
        # one commits, no files, revision identifiers of 
470
469
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
471
470
        # and again.
472
471
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
 
472
                       self.collect,
473
473
                       reuse_history_from=[self._baz._missing_import_imported])
474
474
        branch2 = Branch.open('output2')
475
475
        self.assertEqual(branch.revision_history(), branch2.revision_history())
489
489
        self.assertEqual(1, len(rev.parent_ids))
490
490
 
491
491
    def test_bad_file_id(self):
492
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
492
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
493
                       self.collect)
493
494
        # expected results:
494
495
        # three commits, one files, revision identifiers of 
495
496
        # 'demo@DONOTUSE_c--import--0--base-0' ,
507
508
 
508
509
    def test_appending_revisions_already_present(self):
509
510
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
510
 
                       max_count=2)
 
511
                       self.collect, max_count=2)
511
512
        # expected results:
512
513
        # three commits, one files, revision identifiers of 
513
514
        # 'demo@DONOTUSE_c--import--0--base-0' ,
524
525
        self.assertEqual(branch.revision_history(),
525
526
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
526
527
        del branch
527
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
528
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
529
                       self.collect)
528
530
        branch = Branch.open('output')
529
531
        self.assertEqual(branch.revision_history(),
530
532
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
536
538
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
537
539
 
538
540
    def test_appending_revisions_all_already_present(self):
539
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
541
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
542
                       self.collect)
540
543
        # expected results:
541
544
        # three commits, one files, revision identifiers of 
542
545
        # 'demo@DONOTUSE_c--import--0--base-0' ,
554
557
        self.assertEqual(branch.revision_history(),
555
558
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
556
559
        del branch
557
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
 
560
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
561
                       self.collect)
558
562
        branch = Branch.open('output')
559
563
        self.assertEqual(branch.revision_history(),
560
564
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
566
570
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
567
571
 
568
572
    def test_inbranch_conversion(self):
569
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
 
573
        import_version('output', pybaz.Version(self._baz._inbranch_tag),
 
574
                       self.collect)
570
575
        # expected results:
571
576
        # three commits, no files, revision identifiers of 
572
577
        # 'demo@DONOTUSE_c--import--0--base-0' and
579
584
                          self._baz._inbranch_tag_base_bzr,
580
585
                          self._baz._inbranch_tag_head_bzr])
581
586
        # and again.
582
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
 
587
        import_version('output2', pybaz.Version(self._baz._inbranch_tag),
 
588
                       self.collect)
583
589
        branch2 = Branch.open('output2')
584
590
        
585
591
        self.assertEqual(branch.revision_history(), branch2.revision_history())
605
611
        self.assertEqual(rev.parent_ids,
606
612
                         [self._baz._inbranch_tag_base_bzr])
607
613
 
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
 
 
619
614
 
620
615
class TestNamespacePrevious(TestCase):
621
616
 
646
641
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
647
642
                         self.version['versionfix-2999'])
648
643
 
649
 
 
650
644
class TestNamespaceMapping(TestCase):
651
645
 
652
646
    def test_namespace_mapping_branch(self):
669
663
class TestFileIdMapping(TestCase):
670
664
 
671
665
    def test_slash(self):
 
666
        from bzrlib.plugins.bzrtools.baz_import import map_file_id
672
667
        self.assertEqual('c%2fc', map_file_id('c/c'))
673
668
        self.assertEqual('c%25c', map_file_id('c%c'))
674
669
 
721
716
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
722
717
                                                    'c1', '0.2','branch')))
723
718
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
724
 
        self.assertEqual(20, walk_len)
 
719
        self.assertEqual(22, walk_len)
725
720
 
726
721
    def test_run_twice(self):
727
722
        self.make_import('c--0')
738
733
        self.make_import('c--0')
739
734
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
740
735
                     'demo@DONOTUSE')
741