~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-24 19:01:30 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060324190130-2208c693486a8b33
Added apache index scraping to the branches command

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)
 
34
from bzrlib.errors import NoSuchRevision
31
35
import shutil
32
36
from StringIO import StringIO
33
37
import tempfile
34
38
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
35
39
                               ResourcedTestCase)
36
 
 
37
 
import bzrlib
38
 
from bzrlib.errors import NoSuchRevision
39
 
from bzrlib.plugins.bzrtools.fai import namespace_previous
 
40
    
 
41
try:
 
42
    from bzrtools.fai import namespace_previous
 
43
except ImportError:
 
44
    from bzrlib.plugins.bzrtools.fai import namespace_previous
40
45
from bzrlib.branch import Branch
41
46
 
42
47
def test_suite():
44
49
        from unittest import TestSuite
45
50
        return TestSuite()
46
51
    return TestLoader().loadTestsFromName(__name__)
47
 
 
 
52
 
48
53
 
49
54
class BazTreeResource(TestResource):
50
55
 
64
69
        pybaz.set_my_id("Test User<test@example.org>")
65
70
 
66
71
        self.make_empty_import()
67
 
        self.make_utf8_log()
68
72
 
69
73
        self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
70
 
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0', None)
 
74
        self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
71
75
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
72
76
            pybaz.Version(self._empty_tag))
73
77
 
74
78
        self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
75
 
        self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
76
 
                                                 + '--base-0', None)
77
 
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
78
 
                                                 + '--patch-1', None)
 
79
        self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag 
 
80
                                                 + '--base-0')
 
81
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag 
 
82
                                                 + '--patch-1')
79
83
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
80
84
            pybaz.Version(self._empty_merged_tag))
81
85
        tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
86
90
        msg["summary"]="did a merge, yarh"
87
91
        tree.commit(msg)
88
92
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
89
 
 
 
93
        
90
94
        # tree, two commits, includes merge of other branch
91
95
        self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
92
96
        self._empty_merged_tag_2_bzr_base = revision_id(
93
 
            self._empty_merged_tag_2 + '--base-0', None)
 
97
            self._empty_merged_tag_2 + '--base-0')
94
98
        self._empty_merged_tag_2_bzr = revision_id(
95
 
            self._empty_merged_tag_2 + '--patch-1', None)
 
99
            self._empty_merged_tag_2 + '--patch-1')
96
100
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
97
101
            pybaz.Version(self._empty_merged_tag_2))
98
102
        tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
105
109
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
106
110
 
107
111
        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)
 
112
        self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
 
113
        self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
112
114
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
113
115
            pybaz.Version(self._bad_id_tag))
114
116
        tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
115
117
            os.path.join(self._tmpdir, 'tree'))
116
118
        from bzrlib.plugins.bzrtools.baz_import import add_file
117
 
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
 
119
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 
118
120
                 'this_id/needs%escaping')
119
121
        msg = tree.log_message()
120
122
        msg["summary"] = "commit something which needs escaping."
128
130
    def make_import_symlink(self):
129
131
        self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
130
132
        self._import_symlink_bzr = revision_id(
131
 
            self._import_symlink + '--base-0', None)
 
133
            self._import_symlink + '--base-0')
132
134
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
133
135
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
134
136
                               self._import_symlink)
135
 
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
136
 
        os.symlink('missing-file-name', link_path)
 
137
        os.symlink('missing-file-name',
 
138
                   os.path.join(self._tmpdir, 'tree', 'alink'))
137
139
        tree.add_tag('alink')
138
140
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
139
141
        id_file.write('symlink_tag\n')
141
143
        msg = tree.log_message()
142
144
        msg["summary"] = "Import with a symlink"
143
145
        tree.import_(msg)
144
 
        os.unlink(link_path)
145
 
        f = file(link_path, 'w')
146
 
        f.write('Not a symlink no more!')
147
 
        f.close()
148
 
        msg = tree.log_message()
149
 
        msg["summary"] = "Turn a symlink into a file"
150
 
        tree.commit(msg)
151
146
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
152
147
 
153
148
    def make_empty_import(self):
154
149
        self._import = 'demo@DONOTUSE/c--import--0'
155
150
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
156
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
151
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
157
152
                               self._import)
158
153
        msg = tree.log_message()
159
154
        msg["summary"] = "I am importing now"
160
155
        tree.import_(msg)
161
156
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
162
157
 
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
158
    def make_missing_ancestor(self):
174
159
        self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
175
160
        self._archive = make_archive('demo-gone@DONOTUSE',
176
161
                                     str(self._archivegoneroot))
177
162
        self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
 
        self._missing_import_bzr = revision_id(self._missing_import
179
 
                                                 + '--base-0', None)
 
163
        self._missing_import_bzr = revision_id(self._missing_import 
 
164
                                                 + '--base-0')
180
165
        self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
 
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor
182
 
                                                 + '--base-0', None)
 
166
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor 
 
167
                                                 + '--base-0')
183
168
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
169
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
185
170
                               self._missing_import)
186
171
        msg = tree.log_message()
187
172
        msg["summary"] = "I am importing now"
192
177
            pybaz.Version(self._missing_ancestor))
193
178
 
194
179
        # make an import for testing history-reuse logic.
 
180
        def collect(text):
 
181
            pass
195
182
        # note the use of a namespace layout here.
196
 
        self._missing_import_imported = os.path.join(self._tmpdir,
 
183
        self._missing_import_imported = os.path.join(self._tmpdir, 
197
184
                                                     'archivegone-bzr')
198
185
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
199
186
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
 
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
 
187
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
201
188
                                    'c', 'import'),
202
 
                       pybaz.Version(self._missing_import), None)
 
189
                       pybaz.Version(self._missing_import),
 
190
                       collect)
203
191
        # and make it inaccessible
204
192
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
205
193
 
206
194
    def make_inbranch_continuation(self):
207
195
        self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
196
        self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
 
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
210
 
                                                  None)
 
197
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
211
198
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
199
            pybaz.Version(self._inbranch_tag))
213
200
        self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
214
 
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
215
 
                                                  None)
 
201
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
216
202
        pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
203
            pybaz.Version(self._inbranch_tag))
218
204
 
233
219
        TestCaseInTempDir.setUp(self)
234
220
        ResourcedTestCase.setUpResources(self)
235
221
        os.environ['HOME'] = self._baz._homedir
 
222
        self.output = StringIO()
236
223
 
237
224
    def tearDown(self):
238
225
        ResourcedTestCase.tearDownResources(self)
239
226
        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
 
 
 
227
 
 
228
    def collect(self, text):
 
229
        self.output.write(text)
 
230
        self.output.write("\n")
 
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), 
 
234
                       self.collect)
257
235
        # expected results:
258
 
        # one commit, no files, revision identifier of
 
236
        # one commit, no files, revision identifier of 
259
237
        # 'demo@DONOTUSE_c--import--0--base-0'
260
238
        branch = Branch.open('output')
261
239
        repo = branch.repository
264
242
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
265
243
        # and again.
266
244
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
267
 
                       None)
 
245
                       self.collect)
268
246
        branch2 = Branch.open('output2')
269
247
        repo2 = branch2.repository
270
248
        self.assertEqual(branch.revision_history(), branch2.revision_history())
279
257
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
280
258
 
281
259
    def test_empty_tagged(self):
282
 
        import_version('output', pybaz.Version(self._baz._empty_tag), None)
 
260
        import_version('output', pybaz.Version(self._baz._empty_tag),
 
261
                       self.collect)
283
262
        # expected results:
284
 
        # two commits, no files, revision identifiers of
 
263
        # two commits, no files, revision identifiers of 
285
264
        # 'demo@DONOTUSE_c--import--0--base-0' and
286
265
        # self._baz._empty_tag_bzr
287
266
        branch = Branch.open('output')
290
269
                          self._baz._empty_tag_bzr])
291
270
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
292
271
        # and again.
293
 
        import_version('output2', pybaz.Version(self._baz._empty_tag), None)
 
272
        import_version('output2', pybaz.Version(self._baz._empty_tag),
 
273
                       self.collect)
294
274
        branch2 = Branch.open('output2')
295
275
        self.assertEqual(branch.revision_history(), branch2.revision_history())
296
276
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
299
279
 
300
280
        # and we should get some expected values:
301
281
        self.assertEqual(rev.committer, "Test User<test@example.org>")
302
 
        self.assertEqual(rev.message,
 
282
        self.assertEqual(rev.message, 
303
283
                         "tag of demo@DONOTUSE/c--import--0--base-0")
304
284
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
305
285
 
306
286
    def test_empty_merged_tagged(self):
307
287
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
308
 
                       None)
 
288
                       self.collect)
309
289
        # expected results:
310
 
        # two commits, no files, revision identifiers of
 
290
        # two commits, no files, revision identifiers of 
311
291
        # 'demo@DONOTUSE_c--import--0--base-0' and
312
292
        # self._baz._empty_merged_tag_bzr_base
313
293
        # self._baz._empty_merged_tag_bzr
321
301
                          self._baz._empty_merged_tag_bzr])
322
302
        # and again.
323
303
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
324
 
                       None)
 
304
                       self.collect)
325
305
        branch2 = Branch.open('output2')
326
306
        repo2 = branch2.repository
327
307
        # and import what we should be merged up against for checking with.
328
 
        import_version('output3', pybaz.Version(self._baz._empty_tag), None)
 
308
        import_version('output3', pybaz.Version(self._baz._empty_tag),
 
309
                       self.collect)
329
310
        branch3 = Branch.open('output3')
330
 
 
 
311
        
331
312
        self.assertEqual(branch.revision_history(), branch2.revision_history())
332
 
        self.assertNotEqual(branch.revision_history(),
 
313
        self.assertNotEqual(branch.revision_history(), 
333
314
                            branch3.revision_history())
334
315
        # check revisions in the history.
335
316
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
338
319
        self.assertEqual(rev, rev2)
339
320
        # and we should get some expected values:
340
321
        self.assertEqual(rev.committer, "Test User<test@example.org>")
341
 
        self.assertEqual(rev.message,
 
322
        self.assertEqual(rev.message, 
342
323
                         "tag of demo@DONOTUSE/c--import--0--base-0")
343
324
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
344
325
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
357
338
                         self._baz._empty_merged_tag_bzr_base)
358
339
        self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
359
340
 
360
 
        # this tree should have nothing missing from that tree.
 
341
        # this tree should have nothing missing from that tree.   
361
342
        # FIXME there is no code for this right now.
362
343
        # self.assertEqual(branch.missing_revisions(branch3), [])
363
 
 
 
344
        
364
345
    def test_merge_branch_with_merges(self):
365
346
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
366
 
                       None)
 
347
                       self.collect)
367
348
        # expected results:
368
 
        # two commits, no files, revision identifiers of
 
349
        # two commits, no files, revision identifiers of 
369
350
        # 'demo@DONOTUSE_c--import--0--base-0' and
370
351
        # self._baz._empty_merged_tag_2_bzr_base
371
352
        # self._baz._empty_merged_tag_2_bzr
379
360
                          self._baz._empty_merged_tag_2_bzr])
380
361
        # and again.
381
362
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
382
 
                       None)
 
363
                       self.collect)
383
364
        branch2 = Branch.open('output2')
384
365
        repo2 = branch2.repository
385
366
        # and import what we should be merged up against for checking with.
386
367
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
387
 
                       None)
 
368
                       self.collect)
388
369
        branch3 = Branch.open('output3')
389
 
 
 
370
        
390
371
        self.assertEqual(branch.revision_history(), branch2.revision_history())
391
 
        self.assertNotEqual(branch.revision_history(),
 
372
        self.assertNotEqual(branch.revision_history(), 
392
373
                            branch3.revision_history())
393
374
        # check revisions in the history.
394
375
        rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
397
378
        self.assertEqual(rev, rev2)
398
379
        # and we should get some expected values:
399
380
        self.assertEqual(rev.committer, "Test User<test@example.org>")
400
 
        self.assertEqual(rev.message,
 
381
        self.assertEqual(rev.message, 
401
382
                         "tag of demo@DONOTUSE/c--import--0--base-0")
402
 
        self.assertEqual(rev.revision_id,
 
383
        self.assertEqual(rev.revision_id, 
403
384
                         self._baz._empty_merged_tag_2_bzr_base)
404
385
 
405
386
        # check next revisions in the history.
416
397
        self.assertEqual(rev.parent_ids[1],
417
398
                         self._baz._empty_merged_tag_bzr)
418
399
 
419
 
        # this tree should have nothing missing from that tree.
 
400
        # this tree should have nothing missing from that tree.   
420
401
        # FIXME there is no code for this right now.
421
402
        # self.assertEqual(branch.missing_revisions(branch3), [])
422
 
 
 
403
        
423
404
    def test_import_symlink(self):
424
405
        import_version('output', pybaz.Version(self._baz._import_symlink),
425
 
                       None, max_count=1)
 
406
                       self.collect)
426
407
        # expected results:
427
 
        # two commits, no files, revision identifier of
 
408
        # one commit, no files, revision identifier of 
428
409
        # 'demo@DONOTUSE_c--import--0--base-0'
429
410
        branch = Branch.open('output')
430
411
        self.assertEqual(branch.revision_history(),
432
413
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
433
414
        # and again.
434
415
        import_version('output2', pybaz.Version(self._baz._import_symlink),
435
 
                       None, max_count=1)
 
416
                       self.collect)
436
417
        branch2 = Branch.open('output2')
437
418
        self.assertEqual(branch.revision_history(), branch2.revision_history())
438
419
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
451
432
        self.assertEqual(entry.kind, 'symlink')
452
433
        self.assertEqual(entry.symlink_target, 'missing-file-name')
453
434
 
454
 
        # Test kind change for import
455
 
        import_version('output3', pybaz.Version(self._baz._import_symlink),
456
 
                       None)
457
 
 
458
435
    def test_missing_ancestor(self):
459
436
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
460
 
                       None)
 
437
                       self.collect)
461
438
        # expected results:
462
 
        # one commits, no files, revision identifiers of
 
439
        # one commits, no files, revision identifiers of 
463
440
        # 'demo@DONOTUSE_c--gone--0--base-0' and
464
441
        # a merge of demo-gone@DONOTUSE%c--import--0
465
442
        branch = Branch.open('output')
468
445
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
469
446
        # and again.
470
447
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
471
 
                       None)
 
448
                       self.collect)
472
449
        branch2 = Branch.open('output2')
473
450
        self.assertEqual(branch.revision_history(), branch2.revision_history())
474
451
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
477
454
 
478
455
        # and we should get some expected values:
479
456
        self.assertEqual(rev.committer, "Test User<test@example.org>")
480
 
        self.assertEqual(rev.message,
 
457
        self.assertEqual(rev.message, 
481
458
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
482
459
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
483
460
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
484
461
        self.assertEqual(1, len(rev.parent_ids))
485
462
 
486
463
        # must NOT be able to get the merged evision
487
 
        self.assertRaises(NoSuchRevision, branch.repository.get_revision,
 
464
        self.assertRaises(NoSuchRevision, branch.repository.get_revision, 
488
465
                          self._baz._missing_import_bzr)
489
466
 
490
467
    def test_missing_ancestor_reusing_history(self):
491
468
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
492
 
                       None,
 
469
                       self.collect,
493
470
                       reuse_history_from=[self._baz._missing_import_imported])
494
471
        # expected results:
495
 
        # one commits, no files, revision identifiers of
496
 
        # 'demo-gone@DONOTUSE%c--import--0--base-0' and
 
472
        # one commits, no files, revision identifiers of 
 
473
        # 'demo-gone@DONOTUSE%c--import--0--base-0' and 
497
474
        # 'demo@DONOTUSE%c--gone--0--base-0'
498
475
        branch = Branch.open('output')
499
476
        self.assertEqual(branch.revision_history(),
502
479
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
503
480
        # and again.
504
481
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
505
 
                       None,
 
482
                       self.collect,
506
483
                       reuse_history_from=[self._baz._missing_import_imported])
507
484
        branch2 = Branch.open('output2')
508
485
        self.assertEqual(branch.revision_history(), branch2.revision_history())
515
492
 
516
493
        # and we should get some expected values:
517
494
        self.assertEqual(rev.committer, "Test User<test@example.org>")
518
 
        self.assertEqual(rev.message,
 
495
        self.assertEqual(rev.message, 
519
496
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
520
497
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
521
498
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
522
499
        self.assertEqual(1, len(rev.parent_ids))
523
500
 
524
501
    def test_bad_file_id(self):
525
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
502
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
503
                       self.collect)
526
504
        # expected results:
527
 
        # three commits, one files, revision identifiers of
 
505
        # three commits, one files, revision identifiers of 
528
506
        # 'demo@DONOTUSE_c--import--0--base-0' ,
529
507
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
530
508
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
539
517
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
540
518
 
541
519
    def test_appending_revisions_already_present(self):
542
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
543
 
                       max_count=2)
 
520
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
521
                       self.collect, max_count=2)
544
522
        # expected results:
545
 
        # three commits, one files, revision identifiers of
 
523
        # three commits, one files, revision identifiers of 
546
524
        # 'demo@DONOTUSE_c--import--0--base-0' ,
547
525
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
548
526
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
557
535
        self.assertEqual(branch.revision_history(),
558
536
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
559
537
        del branch
560
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
538
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
539
                       self.collect)
561
540
        branch = Branch.open('output')
562
541
        self.assertEqual(branch.revision_history(),
563
542
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
569
548
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
570
549
 
571
550
    def test_appending_revisions_all_already_present(self):
572
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
551
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
552
                       self.collect)
573
553
        # expected results:
574
 
        # three commits, one files, revision identifiers of
 
554
        # three commits, one files, revision identifiers of 
575
555
        # 'demo@DONOTUSE_c--import--0--base-0' ,
576
556
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
577
557
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
587
567
        self.assertEqual(branch.revision_history(),
588
568
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
589
569
        del branch
590
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
570
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
 
571
                       self.collect)
591
572
        branch = Branch.open('output')
592
573
        self.assertEqual(branch.revision_history(),
593
574
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
599
580
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
600
581
 
601
582
    def test_inbranch_conversion(self):
602
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
 
583
        import_version('output', pybaz.Version(self._baz._inbranch_tag),
 
584
                       self.collect)
603
585
        # expected results:
604
 
        # three commits, no files, revision identifiers of
 
586
        # three commits, no files, revision identifiers of 
605
587
        # 'demo@DONOTUSE_c--import--0--base-0' and
606
588
        # self._baz._inbranch_tag_base_bzr
607
589
        # self._baz._inbranch_tag_head_bzr
612
594
                          self._baz._inbranch_tag_base_bzr,
613
595
                          self._baz._inbranch_tag_head_bzr])
614
596
        # and again.
615
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
 
597
        import_version('output2', pybaz.Version(self._baz._inbranch_tag),
 
598
                       self.collect)
616
599
        branch2 = Branch.open('output2')
617
 
 
 
600
        
618
601
        self.assertEqual(branch.revision_history(), branch2.revision_history())
619
602
        # check revisions in the history.
620
603
        rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
638
621
        self.assertEqual(rev.parent_ids,
639
622
                         [self._baz._inbranch_tag_base_bzr])
640
623
 
641
 
    def test_no_commits_same_as_missing(self):
642
 
        path = 'output'
643
 
        os.mkdir(path)
644
 
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
 
        import_version(path, pybaz.Version(self._baz._import), None)
646
 
        # expected results:
647
 
        # one commit, revision identifier of
648
 
        # 'demo@DONOTUSE_c--import--0--base-0'
649
 
        self.assertEqual(branch.revision_history(),
650
 
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
651
 
 
652
624
 
653
625
class TestNamespacePrevious(TestCase):
654
626
 
662
634
    def test_patch1_base0(self):
663
635
        self.assertEqual(namespace_previous(self.version['patch-1']),
664
636
                         self.version['base-0'])
665
 
 
 
637
        
666
638
    def test_patch3000_patch2999(self):
667
639
        self.assertEqual(namespace_previous(self.version['patch-3000']),
668
640
                         self.version['patch-2999'])
669
 
 
 
641
        
670
642
    def test_version0_raises(self):
671
643
        self.assertRaises(RuntimeError, namespace_previous,
672
644
                          self.version['version-0'])
679
651
        self.assertEqual(namespace_previous(self.version['versionfix-3000']),
680
652
                         self.version['versionfix-2999'])
681
653
 
682
 
 
683
654
class TestNamespaceMapping(TestCase):
684
655
 
685
656
    def test_namespace_mapping_branch(self):
693
664
        from bzrlib.plugins.bzrtools.baz_import import map_namespace
694
665
        category = pybaz.Category('foo@example.com/c')
695
666
        self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
696
 
        self.assertEqual('c/+trunk',
 
667
        self.assertEqual('c/+trunk', 
697
668
                         map_namespace(pybaz.Version("%s--0" % category)))
698
669
        self.assertEqual('c/0.1/+trunk',
699
670
                         map_namespace(pybaz.Version('%s--0.1' % category)))
726
697
    def make_import(self, namespace):
727
698
        self._import = 'demo@DONOTUSE/%s' % namespace
728
699
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
729
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
700
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
730
701
                               self._import)
731
702
        msg = tree.log_message()
732
703
        msg["summary"] = "I am importing now"
734
705
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
735
706
 
736
707
    def test_cmd_exists(self):
737
 
        from bzrlib.plugins.bzrtools import cmd_baz_import
 
708
        from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
738
709
 
739
710
    def test_empty_archive(self):
740
711
        command = cmd_baz_import()
749
720
        command = cmd_baz_import()
750
721
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
751
722
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
752
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
 
723
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
753
724
                                       'c','+trunk')))
754
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
 
725
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
755
726
                                                    '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
727
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
762
 
        self.assertEqual(num_files, walk_len)
 
728
        self.assertEqual(22, walk_len)
763
729
 
764
730
    def test_run_twice(self):
765
731
        self.make_import('c--0')
766
732
        command = cmd_baz_import()
767
733
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
768
734
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
769
 
 
 
735
        
770
736
    def test_accepts_reuse_history(self):
771
737
        self.make_import('c--0')
772
738
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
773
739
                     'demo@DONOTUSE', '.', '.')
774
 
 
775
 
    def test_does_not_need_reuse_history(self):
776
 
        self.make_import('c--0')
777
 
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
778
 
                     'demo@DONOTUSE')
779
 
 
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())
 
740
        
 
741
    def test_does_not_need_reuse_history(self):
 
742
        self.make_import('c--0')
 
743
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
 
744
                     'demo@DONOTUSE')