~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/test_baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-05-11 12:58:10 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060511125810-df593fe2bf83751d
Add import for standalone test (why?)

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
34
37
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
35
38
                               ResourcedTestCase)
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():
44
50
        from unittest import TestSuite
45
51
        return TestSuite()
46
52
    return TestLoader().loadTestsFromName(__name__)
47
 
 
 
53
 
48
54
 
49
55
class BazTreeResource(TestResource):
50
56
 
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
 
        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)
 
80
        self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag 
 
81
                                                 + '--base-0')
 
82
        self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag 
 
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(
86
91
        msg["summary"]="did a merge, yarh"
87
92
        tree.commit(msg)
88
93
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
89
 
 
 
94
        
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(
115
118
            os.path.join(self._tmpdir, 'tree'))
116
119
        from bzrlib.plugins.bzrtools.baz_import import add_file
117
 
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
 
120
        add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 
118
121
                 'this_id/needs%escaping')
119
122
        msg = tree.log_message()
120
123
        msg["summary"] = "commit something which needs escaping."
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)
135
 
        link_path = os.path.join(self._tmpdir, 'tree', 'alink')
136
 
        os.symlink('missing-file-name', link_path)
 
138
        os.symlink('missing-file-name',
 
139
                   os.path.join(self._tmpdir, 'tree', 'alink'))
137
140
        tree.add_tag('alink')
138
141
        id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
139
142
        id_file.write('symlink_tag\n')
141
144
        msg = tree.log_message()
142
145
        msg["summary"] = "Import with a symlink"
143
146
        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
147
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
152
148
 
153
149
    def make_empty_import(self):
154
150
        self._import = 'demo@DONOTUSE/c--import--0'
155
151
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
156
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
152
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
157
153
                               self._import)
158
154
        msg = tree.log_message()
159
155
        msg["summary"] = "I am importing now"
160
156
        tree.import_(msg)
161
157
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
162
158
 
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
159
    def make_missing_ancestor(self):
174
160
        self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
175
161
        self._archive = make_archive('demo-gone@DONOTUSE',
176
162
                                     str(self._archivegoneroot))
177
163
        self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
178
 
        self._missing_import_bzr = revision_id(self._missing_import
179
 
                                                 + '--base-0', None)
 
164
        self._missing_import_bzr = revision_id(self._missing_import 
 
165
                                                 + '--base-0')
180
166
        self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
181
 
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor
182
 
                                                 + '--base-0', None)
 
167
        self._missing_ancestor_bzr = revision_id(self._missing_ancestor 
 
168
                                                 + '--base-0')
183
169
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
184
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
170
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
185
171
                               self._missing_import)
186
172
        msg = tree.log_message()
187
173
        msg["summary"] = "I am importing now"
193
179
 
194
180
        # make an import for testing history-reuse logic.
195
181
        # note the use of a namespace layout here.
196
 
        self._missing_import_imported = os.path.join(self._tmpdir,
 
182
        self._missing_import_imported = os.path.join(self._tmpdir, 
197
183
                                                     'archivegone-bzr')
198
184
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
199
185
        os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
200
 
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
 
186
        import_version(os.path.join(self._tmpdir, 'archivegone-bzr', 
201
187
                                    'c', 'import'),
202
 
                       pybaz.Version(self._missing_import), None)
 
188
                       pybaz.Version(self._missing_import))
203
189
        # and make it inaccessible
204
190
        pybaz.Archive('demo-gone@DONOTUSE').unregister()
205
191
 
206
192
    def make_inbranch_continuation(self):
207
193
        self._inbranch_tag = 'demo@DONOTUSE/c--inbranch-tag--0'
208
194
        self._inbranch_tag_base = self._inbranch_tag + '--base-0'
209
 
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base,
210
 
                                                  None)
 
195
        self._inbranch_tag_base_bzr = revision_id(self._inbranch_tag_base)
211
196
        pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
212
197
            pybaz.Version(self._inbranch_tag))
213
198
        self._inbranch_tag_head = self._inbranch_tag + '--patch-1'
214
 
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head,
215
 
                                                  None)
 
199
        self._inbranch_tag_head_bzr = revision_id(self._inbranch_tag_head)
216
200
        pybaz.Revision(self._inbranch_tag_base).make_continuation(
217
201
            pybaz.Version(self._inbranch_tag))
218
202
 
237
221
    def tearDown(self):
238
222
        ResourcedTestCase.tearDownResources(self)
239
223
        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
 
 
 
224
 
255
225
    def test_import_empty(self):
256
 
        import_version('output', pybaz.Version(self._baz._import), None)
 
226
        import_version('output', pybaz.Version(self._baz._import))
257
227
        # expected results:
258
 
        # one commit, no files, revision identifier of
 
228
        # one commit, no files, revision identifier of 
259
229
        # 'demo@DONOTUSE_c--import--0--base-0'
260
230
        branch = Branch.open('output')
261
231
        repo = branch.repository
263
233
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
264
234
        rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
265
235
        # and again.
266
 
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
267
 
                       None)
 
236
        import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'))
268
237
        branch2 = Branch.open('output2')
269
238
        repo2 = branch2.repository
270
239
        self.assertEqual(branch.revision_history(), branch2.revision_history())
279
248
                         "Arch-1:demo@DONOTUSE%c--import--0--base-0")
280
249
 
281
250
    def test_empty_tagged(self):
282
 
        import_version('output', pybaz.Version(self._baz._empty_tag), None)
 
251
        import_version('output', pybaz.Version(self._baz._empty_tag))
283
252
        # expected results:
284
 
        # two commits, no files, revision identifiers of
 
253
        # two commits, no files, revision identifiers of 
285
254
        # 'demo@DONOTUSE_c--import--0--base-0' and
286
255
        # self._baz._empty_tag_bzr
287
256
        branch = Branch.open('output')
290
259
                          self._baz._empty_tag_bzr])
291
260
        rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
292
261
        # and again.
293
 
        import_version('output2', pybaz.Version(self._baz._empty_tag), None)
 
262
        import_version('output2', pybaz.Version(self._baz._empty_tag))
294
263
        branch2 = Branch.open('output2')
295
264
        self.assertEqual(branch.revision_history(), branch2.revision_history())
296
265
        rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
299
268
 
300
269
        # and we should get some expected values:
301
270
        self.assertEqual(rev.committer, "Test User<test@example.org>")
302
 
        self.assertEqual(rev.message,
 
271
        self.assertEqual(rev.message, 
303
272
                         "tag of demo@DONOTUSE/c--import--0--base-0")
304
273
        self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
305
274
 
306
275
    def test_empty_merged_tagged(self):
307
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag),
308
 
                       None)
 
276
        import_version('output', pybaz.Version(self._baz._empty_merged_tag))
309
277
        # expected results:
310
 
        # two commits, no files, revision identifiers of
 
278
        # two commits, no files, revision identifiers of 
311
279
        # 'demo@DONOTUSE_c--import--0--base-0' and
312
280
        # self._baz._empty_merged_tag_bzr_base
313
281
        # self._baz._empty_merged_tag_bzr
320
288
                          self._baz._empty_merged_tag_bzr_base,
321
289
                          self._baz._empty_merged_tag_bzr])
322
290
        # and again.
323
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
324
 
                       None)
 
291
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag))
325
292
        branch2 = Branch.open('output2')
326
293
        repo2 = branch2.repository
327
294
        # and import what we should be merged up against for checking with.
328
 
        import_version('output3', pybaz.Version(self._baz._empty_tag), None)
 
295
        import_version('output3', pybaz.Version(self._baz._empty_tag))
329
296
        branch3 = Branch.open('output3')
330
 
 
 
297
        
331
298
        self.assertEqual(branch.revision_history(), branch2.revision_history())
332
 
        self.assertNotEqual(branch.revision_history(),
 
299
        self.assertNotEqual(branch.revision_history(), 
333
300
                            branch3.revision_history())
334
301
        # check revisions in the history.
335
302
        rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
338
305
        self.assertEqual(rev, rev2)
339
306
        # and we should get some expected values:
340
307
        self.assertEqual(rev.committer, "Test User<test@example.org>")
341
 
        self.assertEqual(rev.message,
 
308
        self.assertEqual(rev.message, 
342
309
                         "tag of demo@DONOTUSE/c--import--0--base-0")
343
310
        self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
344
311
        self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
357
324
                         self._baz._empty_merged_tag_bzr_base)
358
325
        self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
359
326
 
360
 
        # this tree should have nothing missing from that tree.
 
327
        # this tree should have nothing missing from that tree.   
361
328
        # FIXME there is no code for this right now.
362
329
        # self.assertEqual(branch.missing_revisions(branch3), [])
363
 
 
 
330
        
364
331
    def test_merge_branch_with_merges(self):
365
 
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
366
 
                       None)
 
332
        import_version('output', pybaz.Version(self._baz._empty_merged_tag_2))
367
333
        # expected results:
368
 
        # two commits, no files, revision identifiers of
 
334
        # two commits, no files, revision identifiers of 
369
335
        # 'demo@DONOTUSE_c--import--0--base-0' and
370
336
        # self._baz._empty_merged_tag_2_bzr_base
371
337
        # self._baz._empty_merged_tag_2_bzr
378
344
                          self._baz._empty_merged_tag_2_bzr_base,
379
345
                          self._baz._empty_merged_tag_2_bzr])
380
346
        # and again.
381
 
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
382
 
                       None)
 
347
        import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2))
383
348
        branch2 = Branch.open('output2')
384
349
        repo2 = branch2.repository
385
350
        # 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)
 
351
        import_version('output3', pybaz.Version(self._baz._empty_merged_tag))
388
352
        branch3 = Branch.open('output3')
389
 
 
 
353
        
390
354
        self.assertEqual(branch.revision_history(), branch2.revision_history())
391
 
        self.assertNotEqual(branch.revision_history(),
 
355
        self.assertNotEqual(branch.revision_history(), 
392
356
                            branch3.revision_history())
393
357
        # check revisions in the history.
394
358
        rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
397
361
        self.assertEqual(rev, rev2)
398
362
        # and we should get some expected values:
399
363
        self.assertEqual(rev.committer, "Test User<test@example.org>")
400
 
        self.assertEqual(rev.message,
 
364
        self.assertEqual(rev.message, 
401
365
                         "tag of demo@DONOTUSE/c--import--0--base-0")
402
 
        self.assertEqual(rev.revision_id,
 
366
        self.assertEqual(rev.revision_id, 
403
367
                         self._baz._empty_merged_tag_2_bzr_base)
404
368
 
405
369
        # check next revisions in the history.
416
380
        self.assertEqual(rev.parent_ids[1],
417
381
                         self._baz._empty_merged_tag_bzr)
418
382
 
419
 
        # this tree should have nothing missing from that tree.
 
383
        # this tree should have nothing missing from that tree.   
420
384
        # FIXME there is no code for this right now.
421
385
        # self.assertEqual(branch.missing_revisions(branch3), [])
422
 
 
 
386
        
423
387
    def test_import_symlink(self):
424
 
        import_version('output', pybaz.Version(self._baz._import_symlink),
425
 
                       None, max_count=1)
 
388
        import_version('output', pybaz.Version(self._baz._import_symlink))
426
389
        # expected results:
427
 
        # two commits, no files, revision identifier of
 
390
        # one commit, no files, revision identifier of 
428
391
        # 'demo@DONOTUSE_c--import--0--base-0'
429
392
        branch = Branch.open('output')
430
393
        self.assertEqual(branch.revision_history(),
431
394
                         [self._baz._import_symlink_bzr])
432
395
        rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
433
396
        # and again.
434
 
        import_version('output2', pybaz.Version(self._baz._import_symlink),
435
 
                       None, max_count=1)
 
397
        import_version('output2', pybaz.Version(self._baz._import_symlink))
436
398
        branch2 = Branch.open('output2')
437
399
        self.assertEqual(branch.revision_history(), branch2.revision_history())
438
400
        rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
451
413
        self.assertEqual(entry.kind, 'symlink')
452
414
        self.assertEqual(entry.symlink_target, 'missing-file-name')
453
415
 
454
 
        # Test kind change for import
455
 
        import_version('output3', pybaz.Version(self._baz._import_symlink),
456
 
                       None)
457
 
 
458
416
    def test_missing_ancestor(self):
459
 
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
460
 
                       None)
 
417
        import_version('output', pybaz.Version(self._baz._missing_ancestor))
461
418
        # expected results:
462
 
        # one commits, no files, revision identifiers of
 
419
        # one commits, no files, revision identifiers of 
463
420
        # 'demo@DONOTUSE_c--gone--0--base-0' and
464
421
        # a merge of demo-gone@DONOTUSE%c--import--0
465
422
        branch = Branch.open('output')
467
424
                         [self._baz._missing_ancestor_bzr])
468
425
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
469
426
        # and again.
470
 
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
471
 
                       None)
 
427
        import_version('output2', pybaz.Version(self._baz._missing_ancestor))
472
428
        branch2 = Branch.open('output2')
473
429
        self.assertEqual(branch.revision_history(), branch2.revision_history())
474
430
        rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
477
433
 
478
434
        # and we should get some expected values:
479
435
        self.assertEqual(rev.committer, "Test User<test@example.org>")
480
 
        self.assertEqual(rev.message,
 
436
        self.assertEqual(rev.message, 
481
437
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
482
438
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
483
439
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
484
440
        self.assertEqual(1, len(rev.parent_ids))
485
441
 
486
442
        # must NOT be able to get the merged evision
487
 
        self.assertRaises(NoSuchRevision, branch.repository.get_revision,
 
443
        self.assertRaises(NoSuchRevision, branch.repository.get_revision, 
488
444
                          self._baz._missing_import_bzr)
489
445
 
490
446
    def test_missing_ancestor_reusing_history(self):
491
447
        import_version('output', pybaz.Version(self._baz._missing_ancestor),
492
 
                       None,
493
448
                       reuse_history_from=[self._baz._missing_import_imported])
494
449
        # expected results:
495
 
        # one commits, no files, revision identifiers of
496
 
        # 'demo-gone@DONOTUSE%c--import--0--base-0' and
 
450
        # one commits, no files, revision identifiers of 
 
451
        # 'demo-gone@DONOTUSE%c--import--0--base-0' and 
497
452
        # 'demo@DONOTUSE%c--gone--0--base-0'
498
453
        branch = Branch.open('output')
499
454
        self.assertEqual(branch.revision_history(),
502
457
        rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
503
458
        # and again.
504
459
        import_version('output2', pybaz.Version(self._baz._missing_ancestor),
505
 
                       None,
506
460
                       reuse_history_from=[self._baz._missing_import_imported])
507
461
        branch2 = Branch.open('output2')
508
462
        self.assertEqual(branch.revision_history(), branch2.revision_history())
515
469
 
516
470
        # and we should get some expected values:
517
471
        self.assertEqual(rev.committer, "Test User<test@example.org>")
518
 
        self.assertEqual(rev.message,
 
472
        self.assertEqual(rev.message, 
519
473
                         "tag of demo-gone@DONOTUSE/c--import--0--base-0")
520
474
        self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
521
475
        self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
522
476
        self.assertEqual(1, len(rev.parent_ids))
523
477
 
524
478
    def test_bad_file_id(self):
525
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
479
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
526
480
        # expected results:
527
 
        # three commits, one files, revision identifiers of
 
481
        # three commits, one files, revision identifiers of 
528
482
        # 'demo@DONOTUSE_c--import--0--base-0' ,
529
483
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
530
484
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
539
493
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
540
494
 
541
495
    def test_appending_revisions_already_present(self):
542
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None,
 
496
        import_version('output', pybaz.Version(self._baz._bad_id_tag),
543
497
                       max_count=2)
544
498
        # expected results:
545
 
        # three commits, one files, revision identifiers of
 
499
        # three commits, one files, revision identifiers of 
546
500
        # 'demo@DONOTUSE_c--import--0--base-0' ,
547
501
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
548
502
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
557
511
        self.assertEqual(branch.revision_history(),
558
512
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
559
513
        del branch
560
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
514
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
561
515
        branch = Branch.open('output')
562
516
        self.assertEqual(branch.revision_history(),
563
517
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
569
523
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
570
524
 
571
525
    def test_appending_revisions_all_already_present(self):
572
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
526
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
573
527
        # expected results:
574
 
        # three commits, one files, revision identifiers of
 
528
        # three commits, one files, revision identifiers of 
575
529
        # 'demo@DONOTUSE_c--import--0--base-0' ,
576
530
        # 'demo@DONOTUSE/c--bad-id--0--base-0' ,
577
531
        # ''demo@DONOTUSE/c--bad-id--0--patch-1'
587
541
        self.assertEqual(branch.revision_history(),
588
542
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
589
543
        del branch
590
 
        import_version('output', pybaz.Version(self._baz._bad_id_tag), None)
 
544
        import_version('output', pybaz.Version(self._baz._bad_id_tag))
591
545
        branch = Branch.open('output')
592
546
        self.assertEqual(branch.revision_history(),
593
547
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0',
599
553
        self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
600
554
 
601
555
    def test_inbranch_conversion(self):
602
 
        import_version('output', pybaz.Version(self._baz._inbranch_tag), None)
 
556
        import_version('output', pybaz.Version(self._baz._inbranch_tag))
603
557
        # expected results:
604
 
        # three commits, no files, revision identifiers of
 
558
        # three commits, no files, revision identifiers of 
605
559
        # 'demo@DONOTUSE_c--import--0--base-0' and
606
560
        # self._baz._inbranch_tag_base_bzr
607
561
        # self._baz._inbranch_tag_head_bzr
612
566
                          self._baz._inbranch_tag_base_bzr,
613
567
                          self._baz._inbranch_tag_head_bzr])
614
568
        # and again.
615
 
        import_version('output2', pybaz.Version(self._baz._inbranch_tag), None)
 
569
        import_version('output2', pybaz.Version(self._baz._inbranch_tag))
616
570
        branch2 = Branch.open('output2')
617
 
 
 
571
        
618
572
        self.assertEqual(branch.revision_history(), branch2.revision_history())
619
573
        # check revisions in the history.
620
574
        rev = branch.repository.get_revision(self._baz._inbranch_tag_base_bzr)
642
596
        path = 'output'
643
597
        os.mkdir(path)
644
598
        branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(path)
645
 
        import_version(path, pybaz.Version(self._baz._import), None)
 
599
        import_version(path, pybaz.Version(self._baz._import))
646
600
        # expected results:
647
 
        # one commit, revision identifier of
 
601
        # one commit, revision identifier of 
648
602
        # 'demo@DONOTUSE_c--import--0--base-0'
649
603
        self.assertEqual(branch.revision_history(),
650
604
                         ['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
662
616
    def test_patch1_base0(self):
663
617
        self.assertEqual(namespace_previous(self.version['patch-1']),
664
618
                         self.version['base-0'])
665
 
 
 
619
        
666
620
    def test_patch3000_patch2999(self):
667
621
        self.assertEqual(namespace_previous(self.version['patch-3000']),
668
622
                         self.version['patch-2999'])
669
 
 
 
623
        
670
624
    def test_version0_raises(self):
671
625
        self.assertRaises(RuntimeError, namespace_previous,
672
626
                          self.version['version-0'])
693
647
        from bzrlib.plugins.bzrtools.baz_import import map_namespace
694
648
        category = pybaz.Category('foo@example.com/c')
695
649
        self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
696
 
        self.assertEqual('c/+trunk',
 
650
        self.assertEqual('c/+trunk', 
697
651
                         map_namespace(pybaz.Version("%s--0" % category)))
698
652
        self.assertEqual('c/0.1/+trunk',
699
653
                         map_namespace(pybaz.Version('%s--0.1' % category)))
726
680
    def make_import(self, namespace):
727
681
        self._import = 'demo@DONOTUSE/%s' % namespace
728
682
        os.mkdir(os.path.join(self._tmpdir, 'tree'))
729
 
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
 
683
        tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), 
730
684
                               self._import)
731
685
        msg = tree.log_message()
732
686
        msg["summary"] = "I am importing now"
734
688
        shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
735
689
 
736
690
    def test_cmd_exists(self):
737
 
        from bzrlib.plugins.bzrtools import cmd_baz_import
 
691
        from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
738
692
 
739
693
    def test_empty_archive(self):
740
694
        command = cmd_baz_import()
749
703
        command = cmd_baz_import()
750
704
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
751
705
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
752
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
 
706
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
753
707
                                       'c','+trunk')))
754
 
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
 
708
        self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 
755
709
                                                    '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
710
        walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
762
 
        self.assertEqual(num_files, walk_len)
 
711
        self.assertEqual(20, walk_len)
763
712
 
764
713
    def test_run_twice(self):
765
714
        self.make_import('c--0')
766
715
        command = cmd_baz_import()
767
716
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
768
717
        command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
769
 
 
 
718
        
770
719
    def test_accepts_reuse_history(self):
771
720
        self.make_import('c--0')
772
721
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
773
722
                     '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())
 
723
        
 
724
    def test_does_not_need_reuse_history(self):
 
725
        self.make_import('c--0')
 
726
        self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
 
727
                     'demo@DONOTUSE')
 
728