1
# Copyright (C) 2005 Canonical Limited
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.tests import TestCaseInTempDir, TestCase
19
from bzrlib.osutils import has_symlinks
25
from bzrlib.plugins.bzrtools.baz_import import (import_version, revision_id,
27
from bzrlib.errors import NoSuchRevision
29
from StringIO import StringIO
31
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
33
from bzrlib.plugins.bzrtools.fai import namespace_previous
34
from bzrlib.branch import Branch
38
return OptimisingTestSuite()
39
return TestLoader().loadTestsFromName(__name__)
42
class BazTreeResource(TestResource):
45
os.environ['HOME'] = self._oldhome
46
shutil.rmtree(self._tmpdir)
49
self._tmpdir = tempfile.mkdtemp()
50
self._homedir = os.path.join(self._tmpdir, 'home')
51
self._oldhome = os.environ['HOME']
52
os.mkdir(self._homedir)
53
os.environ['HOME'] = self._homedir
55
self._archiveroot = os.path.join(self._tmpdir, 'archive')
56
self._archive = pybaz.make_archive('demo@DONOTUSE', str(self._archiveroot))
57
pybaz.set_my_id("Test User<test@example.org>")
59
self.make_empty_import()
61
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
62
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
63
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
64
pybaz.Version(self._empty_tag))
66
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
67
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
69
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
71
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
72
pybaz.Version(self._empty_merged_tag))
73
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
74
os.path.join(self._tmpdir, 'tree'))
75
tree.star_merge(self._empty_tag,
76
pybaz.Version('demo@DONOTUSE/c--import--0'))
77
msg = tree.log_message()
78
msg["summary"]="did a merge, yarh"
80
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
82
# tree, two commits, includes merge of other branch
83
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
84
self._empty_merged_tag_2_bzr_base = revision_id(self._empty_merged_tag_2 + '--base-0')
85
self._empty_merged_tag_2_bzr = revision_id(self._empty_merged_tag_2 + '--patch-1')
86
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
87
pybaz.Version(self._empty_merged_tag_2))
88
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
89
os.path.join(self._tmpdir, 'tree'))
90
tree.star_merge(self._empty_merged_tag,
91
pybaz.Version('demo@DONOTUSE/c--import--0'))
92
msg = tree.log_message()
93
msg["summary"] = "merge in a merged tree."
95
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
97
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
98
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
99
self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
100
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
101
pybaz.Version(self._bad_id_tag))
102
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
103
os.path.join(self._tmpdir, 'tree'))
104
from bzrlib.plugins.bzrtools.baz_import import add_file
105
add_file(os.path.join(self._tmpdir,'tree/path'), 'text', 'this_id/needs%escaping')
106
msg = tree.log_message()
107
msg["summary"] = "commit something which needs escaping."
109
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
111
self.make_import_symlink()
112
self.make_missing_ancestor()
114
def make_import_symlink(self):
115
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
116
self._import_symlink_bzr = revision_id(self._import_symlink + '--base-0')
117
os.mkdir(os.path.join(self._tmpdir, 'tree'))
118
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
119
self._import_symlink)
120
os.symlink('missing-file-name',
121
os.path.join(self._tmpdir, 'tree', 'alink'))
122
tree.add_tag('alink')
123
id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
124
id_file.write('symlink_tag\n')
126
msg = tree.log_message()
127
msg["summary"] = "Import with a symlink"
129
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
131
def make_empty_import(self):
132
self._import = 'demo@DONOTUSE/c--import--0'
133
os.mkdir(os.path.join(self._tmpdir, 'tree'))
134
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
135
msg = tree.log_message()
136
msg["summary"] = "I am importing now"
138
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
140
def make_missing_ancestor(self):
141
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
142
self._archive = pybaz.make_archive('demo-gone@DONOTUSE',
143
str(self._archivegoneroot))
144
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
145
self._missing_import_bzr = revision_id(self._missing_import
147
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
148
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
150
os.mkdir(os.path.join(self._tmpdir, 'tree'))
151
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
152
self._missing_import)
153
msg = tree.log_message()
154
msg["summary"] = "I am importing now"
156
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
157
# tag into the kept archive
158
pybaz.Revision(self._missing_import + '--base-0').make_continuation(
159
pybaz.Version(self._missing_ancestor))
161
# make an import for testing history-reuse logic.
164
# note the use of a namespace layout here.
165
self._missing_import_imported = os.path.join(self._tmpdir,
167
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
168
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
169
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
171
pybaz.Version(self._missing_import),
173
# and make it inaccessible
174
pybaz.Archive('demo-gone@DONOTUSE').unregister()
177
def _makeResource(self):
178
return BazTreeResource()
181
def _cleanResource(self, resource):
185
class TestImportBranch(TestCaseInTempDir):
187
_resources = [("_baz", BazTreeResource)]
190
TestCaseInTempDir.setUp(self)
191
ResourcedTestCase.setUpResources(self)
192
os.environ['HOME'] = self._baz._homedir
193
self.output = StringIO()
196
ResourcedTestCase.tearDownResources(self)
197
TestCaseInTempDir.tearDown(self)
199
def collect(self, text):
200
self.output.write(text)
201
self.output.write("\n")
203
def test_import_empty(self):
204
import_version('output', pybaz.Version(self._baz._import), self.collect)
206
# one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
207
branch = Branch.open('output')
208
self.assertEqual(branch.revision_history(),
209
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
210
rev = branch.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
212
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
214
branch2 = Branch.open('output2')
215
self.assertEqual(branch.revision_history(), branch2.revision_history())
216
rev2 = branch2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
217
# they must be the same
218
self.assertEqual(rev, rev2)
220
# and we should get some expected values:
221
self.assertEqual(rev.committer, "Test User<test@example.org>")
222
self.assertEqual(rev.message, "I am importing now")
223
self.assertEqual(rev.revision_id,
224
"Arch-1:demo@DONOTUSE%c--import--0--base-0")
226
def test_empty_tagged(self):
227
import_version('output', pybaz.Version(self._baz._empty_tag),
230
# two commits, no files, revision identifiers of
231
# 'demo@DONOTUSE_c--import--0--base-0' and
232
# self._baz._empty_tag_bzr
233
branch = Branch.open('output')
234
self.assertEqual(branch.revision_history(),
235
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
236
self._baz._empty_tag_bzr])
237
rev = branch.get_revision(self._baz._empty_tag_bzr)
239
import_version('output2', pybaz.Version(self._baz._empty_tag),
241
branch2 = Branch.open('output2')
242
self.assertEqual(branch.revision_history(), branch2.revision_history())
243
rev2 = branch2.get_revision(self._baz._empty_tag_bzr)
244
# they must be the same
245
self.assertEqual(rev, rev2)
247
# and we should get some expected values:
248
self.assertEqual(rev.committer, "Test User<test@example.org>")
249
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
250
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
252
def test_empty_merged_tagged(self):
253
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
256
# two commits, no files, revision identifiers of
257
# 'demo@DONOTUSE_c--import--0--base-0' and
258
# self._baz._empty_merged_tag_bzr_base
259
# self._baz._empty_merged_tag_bzr
260
# and a merged revision from the latter of
261
# self._baz._empty_tag_bzr
262
branch = Branch.open('output')
263
self.assertEqual(branch.revision_history(),
264
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
265
self._baz._empty_merged_tag_bzr_base,
266
self._baz._empty_merged_tag_bzr])
268
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
270
branch2 = Branch.open('output2')
271
# and import what we should be merged up against for checking with.
272
import_version('output3', pybaz.Version(self._baz._empty_tag),
274
branch3 = Branch.open('output3')
276
self.assertEqual(branch.revision_history(), branch2.revision_history())
277
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
278
# check revisions in the history.
279
rev = branch.get_revision(self._baz._empty_merged_tag_bzr_base)
280
rev2 = branch2.get_revision(self._baz._empty_merged_tag_bzr_base)
281
# they must be the same
282
self.assertEqual(rev, rev2)
283
# and we should get some expected values:
284
self.assertEqual(rev.committer, "Test User<test@example.org>")
285
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
286
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
287
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
290
# check next revisions in the history.
291
rev = branch.get_revision(self._baz._empty_merged_tag_bzr)
292
rev2 = branch2.get_revision(self._baz._empty_merged_tag_bzr)
293
# they must be the same
294
self.assertEqual(rev, rev2)
295
# and we should get some expected values:
296
self.assertEqual(rev.committer, "Test User<test@example.org>")
297
self.assertEqual(rev.message, "did a merge, yarh")
298
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr)
299
self.assertEqual(rev.parent_ids[0],
300
self._baz._empty_merged_tag_bzr_base)
301
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
303
# this tree should have nothing missing from that tree.
304
# FIXME there is no code for this right now.
305
# self.assertEqual(branch.missing_revisions(branch3), [])
307
def test_merge_branch_with_merges(self):
308
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
311
# two commits, no files, revision identifiers of
312
# 'demo@DONOTUSE_c--import--0--base-0' and
313
# self._baz._empty_merged_tag_2_bzr_base
314
# self._baz._empty_merged_tag_2_bzr
315
# and a merged revision from the latter of
316
# self._baz._empty_merged_tag_bzr
317
branch = Branch.open('output')
318
self.assertEqual(branch.revision_history(),
319
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
320
self._baz._empty_merged_tag_2_bzr_base,
321
self._baz._empty_merged_tag_2_bzr])
323
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
325
branch2 = Branch.open('output2')
326
# and import what we should be merged up against for checking with.
327
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
329
branch3 = Branch.open('output3')
331
self.assertEqual(branch.revision_history(), branch2.revision_history())
332
self.assertNotEqual(branch.revision_history(), branch3.revision_history())
333
# check revisions in the history.
334
rev = branch.get_revision(self._baz._empty_merged_tag_2_bzr_base)
335
rev2 = branch2.get_revision(self._baz._empty_merged_tag_2_bzr_base)
336
# they must be the same
337
self.assertEqual(rev, rev2)
338
# and we should get some expected values:
339
self.assertEqual(rev.committer, "Test User<test@example.org>")
340
self.assertEqual(rev.message, "tag of demo@DONOTUSE/c--import--0--base-0")
341
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_2_bzr_base)
343
# check next revisions in the history.
344
rev = branch.get_revision(self._baz._empty_merged_tag_2_bzr)
345
rev2 = branch2.get_revision(self._baz._empty_merged_tag_2_bzr)
346
# they must be the same
347
self.assertEqual(rev, rev2)
348
# and we should get some expected values:
349
self.assertEqual(rev.committer, "Test User<test@example.org>")
350
self.assertEqual(rev.message, "merge in a merged tree.")
351
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_2_bzr)
352
self.assertEqual(rev.parent_ids[0],
353
self._baz._empty_merged_tag_2_bzr_base)
354
self.assertEqual(rev.parent_ids[1],
355
self._baz._empty_merged_tag_bzr)
357
# this tree should have nothing missing from that tree.
358
# FIXME there is no code for this right now.
359
# self.assertEqual(branch.missing_revisions(branch3), [])
361
def test_import_symlink(self):
362
import_version('output', pybaz.Version(self._baz._import_symlink),
365
# one commit, no files, revision identifier of 'demo@DONOTUSE_c--import--0--base-0'
366
branch = Branch.open('output')
367
self.assertEqual(branch.revision_history(),
368
[self._baz._import_symlink_bzr])
369
rev = branch.get_revision(self._baz._import_symlink_bzr)
371
import_version('output2', pybaz.Version(self._baz._import_symlink),
373
branch2 = Branch.open('output2')
374
self.assertEqual(branch.revision_history(), branch2.revision_history())
375
rev2 = branch2.get_revision(self._baz._import_symlink_bzr)
376
# they must be the same
377
self.assertEqual(rev, rev2)
379
# and we should get some expected values:
380
self.assertEqual(rev.committer, "Test User<test@example.org>")
381
self.assertEqual(rev.message, "Import with a symlink")
382
self.assertEqual(rev.revision_id, self._baz._import_symlink_bzr)
384
# and we want the symlink alink with target 'missing-file-name'
385
inv = branch.get_inventory(rev.revision_id)
386
self.assertEqual(inv.path2id('alink'), 'x_symlink_tag')
387
entry = inv['x_symlink_tag']
388
self.assertEqual(entry.kind, 'symlink')
389
self.assertEqual(entry.symlink_target, 'missing-file-name')
391
def test_missing_ancestor(self):
392
import_version('output', pybaz.Version(self._baz._missing_ancestor),
395
# one commits, no files, revision identifiers of
396
# 'demo@DONOTUSE_c--gone--0--base-0' and
397
# a merge of demo-gone@DONOTUSE%c--import--0
398
branch = Branch.open('output')
399
self.assertEqual(branch.revision_history(),
400
[self._baz._missing_ancestor_bzr])
401
rev = branch.get_revision(self._baz._missing_ancestor_bzr)
403
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
405
branch2 = Branch.open('output2')
406
self.assertEqual(branch.revision_history(), branch2.revision_history())
407
rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
408
# they must be the same
409
self.assertEqual(rev, rev2)
411
# and we should get some expected values:
412
self.assertEqual(rev.committer, "Test User<test@example.org>")
413
self.assertEqual(rev.message, "tag of demo-gone@DONOTUSE/c--import--0--base-0")
414
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
415
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
416
self.assertEqual(1, len(rev.parent_ids))
418
# must NOT be able to get the merged evision
419
self.assertRaises(NoSuchRevision, branch.get_revision,
420
self._baz._missing_import_bzr)
422
def test_missing_ancestor_reusing_history(self):
423
import_version('output', pybaz.Version(self._baz._missing_ancestor),
425
reuse_history_from=[self._baz._missing_import_imported])
427
# one commits, no files, revision identifiers of
428
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
429
# 'demo@DONOTUSE%c--gone--0--base-0'
430
branch = Branch.open('output')
431
self.assertEqual(branch.revision_history(),
432
[self._baz._missing_import_bzr,
433
self._baz._missing_ancestor_bzr])
434
rev = branch.get_revision(self._baz._missing_ancestor_bzr)
436
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
438
reuse_history_from=[self._baz._missing_import_imported])
439
branch2 = Branch.open('output2')
440
self.assertEqual(branch.revision_history(), branch2.revision_history())
441
rev2 = branch2.get_revision(self._baz._missing_ancestor_bzr)
442
# they must be the same
443
self.assertEqual(rev, rev2)
445
# must be able to get the missing base revision
446
branch.get_revision(self._baz._missing_import_bzr)
448
# and we should get some expected values:
449
self.assertEqual(rev.committer, "Test User<test@example.org>")
450
self.assertEqual(rev.message, "tag of demo-gone@DONOTUSE/c--import--0--base-0")
451
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
452
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
453
self.assertEqual(1, len(rev.parent_ids))
455
def test_bad_file_id(self):
456
import_version('output', pybaz.Version(self._baz._bad_id_tag),
459
# three commits, one files, revision identifiers of
460
# 'demo@DONOTUSE_c--import--0--base-0' ,
461
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
462
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
463
branch = Branch.open('output')
464
self.assertEqual(branch.revision_history(),
465
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
466
self._baz._bad_id_tag_bzr_base,
467
self._baz._bad_id_tag_bzr])
468
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
469
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
470
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
471
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
473
def test_appending_revisions_already_present(self):
474
import_version('output', pybaz.Version(self._baz._bad_id_tag),
475
self.collect, max_count=2)
477
# three commits, one files, revision identifiers of
478
# 'demo@DONOTUSE_c--import--0--base-0' ,
479
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
480
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
481
branch = Branch.open('output')
482
self.assertEqual(branch.revision_history(),
483
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
484
self._baz._bad_id_tag_bzr_base])
485
branch.set_revision_history(
486
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
488
branch = Branch.open('output')
489
self.assertEqual(branch.revision_history(),
490
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
492
import_version('output', pybaz.Version(self._baz._bad_id_tag),
494
branch = Branch.open('output')
495
self.assertEqual(branch.revision_history(),
496
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
497
self._baz._bad_id_tag_bzr_base,
498
self._baz._bad_id_tag_bzr])
499
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
500
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
501
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
502
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
504
def test_appending_revisions_all_already_present(self):
505
import_version('output', pybaz.Version(self._baz._bad_id_tag),
508
# three commits, one files, revision identifiers of
509
# 'demo@DONOTUSE_c--import--0--base-0' ,
510
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
511
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
512
branch = Branch.open('output')
513
self.assertEqual(branch.revision_history(),
514
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
515
self._baz._bad_id_tag_bzr_base,
516
self._baz._bad_id_tag_bzr])
517
branch.set_revision_history(
518
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
520
branch = Branch.open('output')
521
self.assertEqual(branch.revision_history(),
522
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
524
import_version('output', pybaz.Version(self._baz._bad_id_tag),
526
branch = Branch.open('output')
527
self.assertEqual(branch.revision_history(),
528
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
529
self._baz._bad_id_tag_bzr_base,
530
self._baz._bad_id_tag_bzr])
531
rev = branch.get_revision(self._baz._bad_id_tag_bzr)
532
inv = branch.get_inventory(self._baz._bad_id_tag_bzr)
533
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
534
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
537
class TestNamespacePrevious(TestCase):
541
self.version = pybaz.Version('foo@example.com/c--b--0')
543
def test_base0_none(self):
544
self.assertEqual(namespace_previous(self.version['base-0']), None)
546
def test_patch1_base0(self):
547
self.assertEqual(namespace_previous(self.version['patch-1']),
548
self.version['base-0'])
550
def test_patch3000_patch2999(self):
551
self.assertEqual(namespace_previous(self.version['patch-3000']),
552
self.version['patch-2999'])
554
def test_version0_raises(self):
555
self.assertRaises(RuntimeError, namespace_previous,
556
self.version['version-0'])
558
def test_version1_version0(self):
559
self.assertEqual(namespace_previous(self.version['versionfix-1']),
560
self.version['version-0'])
562
def test_version3000_patch2999(self):
563
self.assertEqual(namespace_previous(self.version['versionfix-3000']),
564
self.version['versionfix-2999'])
566
class TestNamespaceMapping(TestCase):
568
def test_namespace_mapping_branch(self):
569
from bzrlib.plugins.bzrtools.baz_import import map_namespace
570
branch = pybaz.Branch('foo@example.com/c--b')
571
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, branch)
572
self.assertEqual('c/b', map_namespace(branch['0']))
573
self.assertEqual('c/0.1/b', map_namespace(branch['0.1']))
575
def test_namespace_mapping_no_branch(self):
576
from bzrlib.plugins.bzrtools.baz_import import map_namespace
577
category = pybaz.Category('foo@example.com/c')
578
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
579
self.assertEqual('c/+trunk',
580
map_namespace(pybaz.Version("%s--0" % category)))
581
self.assertEqual('c/0.1/+trunk',
582
map_namespace(pybaz.Version('%s--0.1' % category)))
585
class TestFileIdMapping(TestCase):
587
def test_slash(self):
588
from bzrlib.plugins.bzrtools.baz_import import map_file_id
589
self.assertEqual('c%2fc', map_file_id('c/c'))
590
self.assertEqual('c%25c', map_file_id('c%c'))
593
class TestImport(TestCaseInTempDir):
596
TestCaseInTempDir.setUp(self)
597
self._oldhome = os.environ['HOME']
598
self._tmpdir = tempfile.mkdtemp()
599
self._homedir = os.path.join(self._tmpdir, 'home')
600
os.mkdir(self._homedir)
601
os.environ['HOME'] = self._homedir
602
self._archiveroot = os.path.join(self._tmpdir, 'archive')
603
self._archive = pybaz.make_archive('demo@DONOTUSE',
604
str(self._archiveroot))
607
os.environ['HOME'] = self._oldhome
608
shutil.rmtree(self._tmpdir)
609
TestCaseInTempDir.tearDown(self)
611
def make_import(self, namespace):
612
self._import = 'demo@DONOTUSE/%s' % namespace
613
os.mkdir(os.path.join(self._tmpdir, 'tree'))
614
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'), self._import)
615
msg = tree.log_message()
616
msg["summary"] = "I am importing now"
618
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
620
def test_cmd_exists(self):
621
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
623
def test_empty_archive(self):
624
command = cmd_baz_import()
625
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
626
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
628
len(list(os.walk(os.path.join(self._tmpdir,'output')))))
630
def test_two_branches(self):
631
self.make_import('c--0')
632
self.make_import('c1--branch--0.2')
633
command = cmd_baz_import()
634
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
635
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
636
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c','+trunk')))
637
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output', 'c1', '0.2','branch')))
639
len(list(os.walk(os.path.join(self._tmpdir,'output')))))
641
def test_run_twice(self):
642
self.make_import('c--0')
643
command = cmd_baz_import()
644
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
645
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
647
def test_accepts_reuse_history(self):
648
self.make_import('c--0')
649
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
650
'demo@DONOTUSE', '.', '.')
652
def test_does_not_need_reuse_history(self):
653
self.make_import('c--0')
654
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),