~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-13 13:25:20 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060713132520-2fabfab51affb82f
Update clean-tree docs

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
20
19
from bzrlib.osutils import has_symlinks
21
20
try:
22
21
    import pybaz
23
22
except ImportError:
24
23
    pybaz = None
25
24
import os
26
 
from bzrlib.plugins.bzrtools import cmd_baz_import 
27
 
from bzrlib.plugins.bzrtools.baz_import import (import_version, 
28
 
                                                revision_id,
29
 
                                                make_archive,
30
 
                                                map_file_id)
 
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)
31
34
import shutil
32
35
from StringIO import StringIO
33
36
import tempfile
36
39
    
37
40
import bzrlib
38
41
from bzrlib.errors import NoSuchRevision
39
 
from bzrlib.plugins.bzrtools.fai import namespace_previous
 
42
try:
 
43
    from bzrtools.fai import namespace_previous
 
44
except ImportError:
 
45
    from bzrlib.plugins.bzrtools.fai import namespace_previous
40
46
from bzrlib.branch import Branch
41
47
 
42
48
def test_suite():
64
70
        pybaz.set_my_id("Test User<test@example.org>")
65
71
 
66
72
        self.make_empty_import()
67
 
        self.make_utf8_log()
68
73
 
69
74
        self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
70
 
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
 
75
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
71
76
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
72
77
            pybaz.Version(self._empty_tag))
73
78
 
74
79
        self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
75
80
        self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag 
76
 
                                                 + '--base-0', None)
 
81
                                                 + '--base-0')
77
82
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag 
78
 
                                                 + '--patch-1', None)
 
83
                                                 + '--patch-1')
79
84
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
85
            pybaz.Version(self._empty_merged_tag))
81
86
        tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
90
95
        # tree, two commits, includes merge of other branch
91
96
        self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
92
97
        self._empty_merged_tag_2_bzr_base = revision_id(
93
 
            self._empty_merged_tag_2 + '--base-0', None)
 
98
            self._empty_merged_tag_2 + '--base-0')
94
99
        self._empty_merged_tag_2_bzr = revision_id(
95
 
            self._empty_merged_tag_2 + '--patch-1', None)
 
100
            self._empty_merged_tag_2 + '--patch-1')
96
101
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
97
102
            pybaz.Version(self._empty_merged_tag_2))
98
103
        tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
105
110
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
106
111
 
107
112
        self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
108
 
        self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0',
109
 
                                                None)
110
 
        self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1',
111
 
                                           None)
 
113
        self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
 
114
        self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
112
115
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
113
116
            pybaz.Version(self._bad_id_tag))
114
117
        tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
128
131
    def make_import_symlink(self):
129
132
        self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
130
133
        self._import_symlink_bzr = revision_id(
131
 
            self._import_symlink + '--base-0', None)
 
134
            self._import_symlink + '--base-0')
132
135
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
133
136
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
134
137
                               self._import_symlink)
160
163
        tree.import_(msg)
161
164
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
162
165
 
163
 
    def make_utf8_log(self):
164
 
        self._utf8 = 'demo@DONOTUSE/c--utf8--0'
165
 
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
166
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
167
 
                               self._utf8)
168
 
        msg = tree.log_message()
169
 
        msg["summary"] = u"I am importing now\u1234".encode('utf-8')
170
 
        tree.import_(msg)
171
 
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
172
 
 
173
166
    def make_missing_ancestor(self):
174
167
        self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
175
168
        self._archive = make_archive('demo-gone@DONOTUSE',
176
169
                                     str(self._archivegoneroot))
177
170
        self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
171
        self._missing_import_bzr = revision_id(self._missing_import 
179
 
                                                 + '--base-0', None)
 
172
                                                 + '--base-0')
180
173
        self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
174
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor 
182
 
                                                 + '--base-0', None)
 
175
                                                 + '--base-0')
183
176
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
177
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
185
178
                               self._missing_import)
199
192
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
193
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
201
194
                                    'c', 'import'),
202
 
                       pybaz.Version(self._missing_import), None)
 
195
                       pybaz.Version(self._missing_import))
203
196
        # and make it inaccessible
204
197
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
205
198
 
206
199
    def make_inbranch_continuation(self):
207
200
        self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
201
        self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
 
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base, 
210
 
                                                  None)
 
202
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
211
203
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
204
            pybaz.Version(self._inbranch_tag))
213
205
        self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
214
 
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
215
 
                                                  None)
 
206
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
216
207
        pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
208
            pybaz.Version(self._inbranch_tag))
218
209
 
237
228
    def tearDown(self):
238
229
        ResourcedTestCase.tearDownResources(self)
239
230
        TestCaseInTempDir.tearDown(self)
240
 
 
241
 
    def test_import_utf8(self):
242
 
        import_version('output', pybaz.Version(self._baz._utf8), None)
243
 
        branch = Branch.open('output')
244
 
        plain_revid = 'Arch-1:demo@DONOTUSE%c--utf8--0--base-0'
245
 
        self.assertEqual([plain_revid], branch.revision_history())
246
 
        self.assertEqual(u'I am importing now\ufffd\ufffd\ufffd',
247
 
                         branch.repository.get_revision(plain_revid).message)
248
 
        import_version('output2', pybaz.Version(self._baz._utf8), 'utf-8')
249
 
        branch2 = Branch.open('output2')
250
 
        utf8_revid = 'Arch-1-utf-8:demo@DONOTUSE%c--utf8--0--base-0'
251
 
        self.assertEqual([utf8_revid], branch2.revision_history())
252
 
        self.assertEqual(u'I am importing now\u1234',
253
 
                         branch2.repository.get_revision(utf8_revid).message)
254
 
 
 
231
 
255
232
    def test_import_empty(self):
256
 
        import_version('output', pybaz.Version(self._baz._import), None)
 
233
        import_version('output', pybaz.Version(self._baz._import))
257
234
        # expected results:
258
235
        # one commit, no files, revision identifier of 
259
236
        # 'demo@DONOTUSE_c--import--0--base-0'
263
240
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
264
241
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
265
242
        # and again.
266
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
267
 
                       None)
 
243
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
268
244
        branch2 = Branch.open('output2')
269
245
        repo2 = branch2.repository
270
246
        self.assertEqual(branch.revision_history(), branch2.revision_history())
279
255
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
280
256
 
281
257
    def test_empty_tagged(self):
282
 
        import_version('output', pybaz.Version(self._baz._empty_tag), None)
 
258
        import_version('output', pybaz.Version(self._baz._empty_tag))
283
259
        # expected results:
284
260
        # two commits, no files, revision identifiers of 
285
261
        # 'demo@DONOTUSE_c--import--0--base-0' and
290
266
                          self._baz._empty_tag_bzr])
291
267
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
292
268
        # and again.
293
 
        import_version('output2', pybaz.Version(self._baz._empty_tag), None)
 
269
        import_version('output2', pybaz.Version(self._baz._empty_tag))
294
270
        branch2 = Branch.open('output2')
295
271
        self.assertEqual(branch.revision_history(), branch2.revision_history())
296
272
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
304
280
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
305
281
 
306
282
    def test_empty_merged_tagged(self):
307
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag), 
308
 
                       None)
 
283
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
309
284
        # expected results:
310
285
        # two commits, no files, revision identifiers of 
311
286
        # 'demo@DONOTUSE_c--import--0--base-0' and
320
295
                          self._baz._empty_merged_tag_bzr_base,
321
296
                          self._baz._empty_merged_tag_bzr])
322
297
        # and again.
323
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag), 
324
 
                       None)
 
298
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
325
299
        branch2 = Branch.open('output2')
326
300
        repo2 = branch2.repository
327
301
        # and import what we should be merged up against for checking with.
328
 
        import_version('output3', pybaz.Version(self._baz._empty_tag), None)
 
302
        import_version('output3', pybaz.Version(self._baz._empty_tag))
329
303
        branch3 = Branch.open('output3')
330
304
        
331
305
        self.assertEqual(branch.revision_history(), branch2.revision_history())
362
336
        # self.assertEqual(branch.missing_revisions(branch3), [])
363
337
        
364
338
    def test_merge_branch_with_merges(self):
365
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2), 
366
 
                       None)
 
339
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
367
340
        # expected results:
368
341
        # two commits, no files, revision identifiers of 
369
342
        # 'demo@DONOTUSE_c--import--0--base-0' and
378
351
                          self._baz._empty_merged_tag_2_bzr_base,
379
352
                          self._baz._empty_merged_tag_2_bzr])
380
353
        # and again.
381
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
382
 
                       None)
 
354
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
383
355
        branch2 = Branch.open('output2')
384
356
        repo2 = branch2.repository
385
357
        # and import what we should be merged up against for checking with.
386
 
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
387
 
                       None)
 
358
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
388
359
        branch3 = Branch.open('output3')
389
360
        
390
361
        self.assertEqual(branch.revision_history(), branch2.revision_history())
422
393
        
423
394
    def test_import_symlink(self):
424
395
        import_version('output', pybaz.Version(self._baz._import_symlink), 
425
 
                       None, max_count=1)
 
396
                       max_count=1)
426
397
        # expected results:
427
398
        # two commits, no files, revision identifier of 
428
399
        # 'demo@DONOTUSE_c--import--0--base-0'
432
403
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
433
404
        # and again.
434
405
        import_version('output2', pybaz.Version(self._baz._import_symlink),
435
 
                       None, max_count=1)
 
406
                       max_count=1)
436
407
        branch2 = Branch.open('output2')
437
408
        self.assertEqual(branch.revision_history(), branch2.revision_history())
438
409
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
451
422
        self.assertEqual(entry.kind, 'symlink')
452
423
        self.assertEqual(entry.symlink_target, 'missing-file-name')
453
424
 
454
 
        # Test kind change for import
455
 
        import_version('output3', pybaz.Version(self._baz._import_symlink),
456
 
                       None)
 
425
        # current bzr doesn't handle type changes
 
426
        self.assertRaises(AssertionError, import_version, 'output3',
 
427
                          pybaz.Version(self._baz._import_symlink))
457
428
 
458
429
    def test_missing_ancestor(self):
459
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
460
 
                       None)
 
430
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
461
431
        # expected results:
462
432
        # one commits, no files, revision identifiers of 
463
433
        # 'demo@DONOTUSE_c--gone--0--base-0' and
467
437
                         [self._baz._missing_ancestor_bzr])
468
438
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
469
439
        # and again.
470
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor), 
471
 
                       None)
 
440
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
472
441
        branch2 = Branch.open('output2')
473
442
        self.assertEqual(branch.revision_history(), branch2.revision_history())
474
443
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
489
458
 
490
459
    def test_missing_ancestor_reusing_history(self):
491
460
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
492
 
                       None,
493
461
                       reuse_history_from=[self._baz._missing_import_imported])
494
462
        # expected results:
495
463
        # one commits, no files, revision identifiers of 
502
470
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
503
471
        # and again.
504
472
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
505
 
                       None,
506
473
                       reuse_history_from=[self._baz._missing_import_imported])
507
474
        branch2 = Branch.open('output2')
508
475
        self.assertEqual(branch.revision_history(), branch2.revision_history())
522
489
        self.assertEqual(1, len(rev.parent_ids))
523
490
 
524
491
    def test_bad_file_id(self):
525
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
492
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
526
493
        # expected results:
527
494
        # three commits, one files, revision identifiers of 
528
495
        # 'demo@DONOTUSE_c--import--0--base-0' ,
539
506
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
540
507
 
541
508
    def test_appending_revisions_already_present(self):
542
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
 
509
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
543
510
                       max_count=2)
544
511
        # expected results:
545
512
        # three commits, one files, revision identifiers of 
557
524
        self.assertEqual(branch.revision_history(),
558
525
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
559
526
        del branch
560
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
527
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
561
528
        branch = Branch.open('output')
562
529
        self.assertEqual(branch.revision_history(),
563
530
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
569
536
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
570
537
 
571
538
    def test_appending_revisions_all_already_present(self):
572
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
539
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
573
540
        # expected results:
574
541
        # three commits, one files, revision identifiers of 
575
542
        # 'demo@DONOTUSE_c--import--0--base-0' ,
587
554
        self.assertEqual(branch.revision_history(),
588
555
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
589
556
        del branch
590
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
557
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
591
558
        branch = Branch.open('output')
592
559
        self.assertEqual(branch.revision_history(),
593
560
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
599
566
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
600
567
 
601
568
    def test_inbranch_conversion(self):
602
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
 
569
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
603
570
        # expected results:
604
571
        # three commits, no files, revision identifiers of 
605
572
        # 'demo@DONOTUSE_c--import--0--base-0' and
612
579
                          self._baz._inbranch_tag_base_bzr,
613
580
                          self._baz._inbranch_tag_head_bzr])
614
581
        # and again.
615
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
 
582
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
616
583
        branch2 = Branch.open('output2')
617
584
        
618
585
        self.assertEqual(branch.revision_history(), branch2.revision_history())
642
609
        path = 'output'
643
610
        os.mkdir(path)
644
611
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
 
        import_version(path, pybaz.Version(self._baz._import), None)
 
612
        import_version(path, pybaz.Version(self._baz._import))
646
613
        # expected results:
647
614
        # one commit, revision identifier of 
648
615
        # 'demo@DONOTUSE_c--import--0--base-0'
734
701
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
735
702
 
736
703
    def test_cmd_exists(self):
737
 
        from bzrlib.plugins.bzrtools import cmd_baz_import
 
704
        from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
738
705
 
739
706
    def test_empty_archive(self):
740
707
        command = cmd_baz_import()
753
720
                                       'c','+trunk')))
754
721
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
755
722
                                                    'c1', '0.2','branch')))
756
 
        default_format = repository.RepositoryFormat.get_default_format()
757
 
        if getattr(default_format, 'rich_root_data', False):
758
 
            num_files = 21
759
 
        else:
760
 
            num_files = 20
761
723
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
762
 
        self.assertEqual(num_files, walk_len)
 
724
        self.assertEqual(20, walk_len)
763
725
 
764
726
    def test_run_twice(self):
765
727
        self.make_import('c--0')
777
739
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
778
740
                     'demo@DONOTUSE')
779
741
 
780
 
    def test_does_not_need_reuse_history(self):
781
 
        self.make_import('c--0')
782
 
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
783
 
                     'demo@DONOTUSE')
784
 
 
785
 
    def test_encoding_flag(self):
786
 
        self.make_import('c--0')
787
 
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
788
 
                     'demo@DONOTUSE')
789
 
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'], 
790
 
                         Branch.open(os.path.join(self._tmpdir, 
791
 
                                     'output/c/+trunk')).revision_history())
792
 
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output2'),
793
 
                     'demo@DONOTUSE', '--encoding', 'utf-8')
794
 
        self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'], 
795
 
                         Branch.open(os.path.join(self._tmpdir, 
796
 
                                     'output2/c/+trunk')).revision_history())
797
 
        self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 'output3'),
798
 
                     'demo@DONOTUSE/c--0')
799
 
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--0--base-0'], 
800
 
                         Branch.open(os.path.join(self._tmpdir, 
801
 
                                     'output3')).revision_history())
802
 
        self.run_bzr('baz-import-branch', os.path.join(self._tmpdir, 
803
 
                      'output4'), 'demo@DONOTUSE/c--0', '--encoding', 'utf-8')
804
 
        self.assertEqual(['Arch-1-utf-8:demo@DONOTUSE%c--0--base-0'], 
805
 
                         Branch.open(os.path.join(self._tmpdir, 
806
 
                                     'output4')).revision_history())