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,
26
cmd_baz_import, make_archive)
27
from bzrlib.errors import NoSuchRevision
29
from StringIO import StringIO
31
from testresources import (TestResource, TestLoader, OptimisingTestSuite,
34
from bzrlib.plugins.bzrtools.fai import namespace_previous
35
from bzrlib.branch import Branch
39
from unittest import TestSuite
41
return TestLoader().loadTestsFromName(__name__)
44
class BazTreeResource(TestResource):
47
os.environ['HOME'] = self._oldhome
48
shutil.rmtree(self._tmpdir)
51
self._tmpdir = tempfile.mkdtemp()
52
self._homedir = os.path.join(self._tmpdir, 'home')
53
self._oldhome = os.environ['HOME']
54
os.mkdir(self._homedir)
55
os.environ['HOME'] = self._homedir
57
self._archiveroot = os.path.join(self._tmpdir, 'archive')
58
self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
59
pybaz.set_my_id("Test User<test@example.org>")
61
self.make_empty_import()
63
self._empty_tag = 'demo@DONOTUSE/c--empty-tag--0'
64
self._empty_tag_bzr = revision_id(self._empty_tag + '--base-0')
65
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
66
pybaz.Version(self._empty_tag))
68
self._empty_merged_tag = 'demo@DONOTUSE/c--empty-merged-tag--0'
69
self._empty_merged_tag_bzr_base = revision_id(self._empty_merged_tag
71
self._empty_merged_tag_bzr = revision_id(self._empty_merged_tag
73
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
74
pybaz.Version(self._empty_merged_tag))
75
tree = pybaz.Revision(self._empty_merged_tag + '--base-0').get(
76
os.path.join(self._tmpdir, 'tree'))
77
tree.star_merge(self._empty_tag,
78
pybaz.Version('demo@DONOTUSE/c--import--0'))
79
msg = tree.log_message()
80
msg["summary"]="did a merge, yarh"
82
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
84
# tree, two commits, includes merge of other branch
85
self._empty_merged_tag_2 = 'demo@DONOTUSE/c--empty-tag-2--0'
86
self._empty_merged_tag_2_bzr_base = revision_id(
87
self._empty_merged_tag_2 + '--base-0')
88
self._empty_merged_tag_2_bzr = revision_id(
89
self._empty_merged_tag_2 + '--patch-1')
90
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
91
pybaz.Version(self._empty_merged_tag_2))
92
tree = pybaz.Revision(self._empty_merged_tag_2 + '--base-0').get (
93
os.path.join(self._tmpdir, 'tree'))
94
tree.star_merge(self._empty_merged_tag,
95
pybaz.Version('demo@DONOTUSE/c--import--0'))
96
msg = tree.log_message()
97
msg["summary"] = "merge in a merged tree."
99
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
101
self._bad_id_tag = 'demo@DONOTUSE/c--bad-id--0'
102
self._bad_id_tag_bzr_base = revision_id(self._bad_id_tag + '--base-0')
103
self._bad_id_tag_bzr = revision_id(self._bad_id_tag + '--patch-1')
104
pybaz.Revision('demo@DONOTUSE/c--import--0--base-0').make_continuation(
105
pybaz.Version(self._bad_id_tag))
106
tree = pybaz.Revision(self._bad_id_tag + '--base-0').get(
107
os.path.join(self._tmpdir, 'tree'))
108
from bzrlib.plugins.bzrtools.baz_import import add_file
109
add_file(os.path.join(self._tmpdir,'tree/path'), 'text',
110
'this_id/needs%escaping')
111
msg = tree.log_message()
112
msg["summary"] = "commit something which needs escaping."
114
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
116
self.make_import_symlink()
117
self.make_missing_ancestor()
119
def make_import_symlink(self):
120
self._import_symlink = 'demo@DONOTUSE/c--import-symlink--0'
121
self._import_symlink_bzr = revision_id(
122
self._import_symlink + '--base-0')
123
os.mkdir(os.path.join(self._tmpdir, 'tree'))
124
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
125
self._import_symlink)
126
os.symlink('missing-file-name',
127
os.path.join(self._tmpdir, 'tree', 'alink'))
128
tree.add_tag('alink')
129
id_file = open(os.path.join(tree, '.arch-ids', 'alink.id'), 'w')
130
id_file.write('symlink_tag\n')
132
msg = tree.log_message()
133
msg["summary"] = "Import with a symlink"
135
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
137
def make_empty_import(self):
138
self._import = 'demo@DONOTUSE/c--import--0'
139
os.mkdir(os.path.join(self._tmpdir, 'tree'))
140
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
142
msg = tree.log_message()
143
msg["summary"] = "I am importing now"
145
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
147
def make_missing_ancestor(self):
148
self._archivegoneroot = os.path.join(self._tmpdir, 'archivegone')
149
self._archive = make_archive('demo-gone@DONOTUSE',
150
str(self._archivegoneroot))
151
self._missing_import = 'demo-gone@DONOTUSE/c--import--0'
152
self._missing_import_bzr = revision_id(self._missing_import
154
self._missing_ancestor = 'demo@DONOTUSE/c--gone--0'
155
self._missing_ancestor_bzr = revision_id(self._missing_ancestor
157
os.mkdir(os.path.join(self._tmpdir, 'tree'))
158
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
159
self._missing_import)
160
msg = tree.log_message()
161
msg["summary"] = "I am importing now"
163
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
164
# tag into the kept archive
165
pybaz.Revision(self._missing_import + '--base-0').make_continuation(
166
pybaz.Version(self._missing_ancestor))
168
# make an import for testing history-reuse logic.
171
# note the use of a namespace layout here.
172
self._missing_import_imported = os.path.join(self._tmpdir,
174
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr'))
175
os.mkdir(os.path.join(self._tmpdir, 'archivegone-bzr', 'c'))
176
import_version(os.path.join(self._tmpdir, 'archivegone-bzr',
178
pybaz.Version(self._missing_import),
180
# and make it inaccessible
181
pybaz.Archive('demo-gone@DONOTUSE').unregister()
184
def _makeResource(self):
185
return BazTreeResource()
188
def _cleanResource(self, resource):
192
class TestImportBranch(TestCaseInTempDir):
194
_resources = [("_baz", BazTreeResource)]
197
TestCaseInTempDir.setUp(self)
198
ResourcedTestCase.setUpResources(self)
199
os.environ['HOME'] = self._baz._homedir
200
self.output = StringIO()
203
ResourcedTestCase.tearDownResources(self)
204
TestCaseInTempDir.tearDown(self)
206
def collect(self, text):
207
self.output.write(text)
208
self.output.write("\n")
210
def test_import_empty(self):
211
import_version('output', pybaz.Version(self._baz._import),
214
# one commit, no files, revision identifier of
215
# 'demo@DONOTUSE_c--import--0--base-0'
216
branch = Branch.open('output')
217
repo = branch.repository
218
self.assertEqual(branch.revision_history(),
219
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
220
rev = repo.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
222
import_version('output2', pybaz.Version('demo@DONOTUSE/c--import--0'),
224
branch2 = Branch.open('output2')
225
repo2 = branch2.repository
226
self.assertEqual(branch.revision_history(), branch2.revision_history())
227
rev2 = repo2.get_revision('Arch-1:demo@DONOTUSE%c--import--0--base-0')
228
# they must be the same
229
self.assertEqual(rev, rev2)
231
# and we should get some expected values:
232
self.assertEqual(rev.committer, "Test User<test@example.org>")
233
self.assertEqual(rev.message, "I am importing now")
234
self.assertEqual(rev.revision_id,
235
"Arch-1:demo@DONOTUSE%c--import--0--base-0")
237
def test_empty_tagged(self):
238
import_version('output', pybaz.Version(self._baz._empty_tag),
241
# two commits, no files, revision identifiers of
242
# 'demo@DONOTUSE_c--import--0--base-0' and
243
# self._baz._empty_tag_bzr
244
branch = Branch.open('output')
245
self.assertEqual(branch.revision_history(),
246
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
247
self._baz._empty_tag_bzr])
248
rev = branch.repository.get_revision(self._baz._empty_tag_bzr)
250
import_version('output2', pybaz.Version(self._baz._empty_tag),
252
branch2 = Branch.open('output2')
253
self.assertEqual(branch.revision_history(), branch2.revision_history())
254
rev2 = branch2.repository.get_revision(self._baz._empty_tag_bzr)
255
# they must be the same
256
self.assertEqual(rev, rev2)
258
# and we should get some expected values:
259
self.assertEqual(rev.committer, "Test User<test@example.org>")
260
self.assertEqual(rev.message,
261
"tag of demo@DONOTUSE/c--import--0--base-0")
262
self.assertEqual(rev.revision_id, self._baz._empty_tag_bzr)
264
def test_empty_merged_tagged(self):
265
import_version('output', pybaz.Version(self._baz._empty_merged_tag),
268
# two commits, no files, revision identifiers of
269
# 'demo@DONOTUSE_c--import--0--base-0' and
270
# self._baz._empty_merged_tag_bzr_base
271
# self._baz._empty_merged_tag_bzr
272
# and a merged revision from the latter of
273
# self._baz._empty_tag_bzr
274
branch = Branch.open('output')
275
repo = branch.repository
276
self.assertEqual(branch.revision_history(),
277
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
278
self._baz._empty_merged_tag_bzr_base,
279
self._baz._empty_merged_tag_bzr])
281
import_version('output2', pybaz.Version(self._baz._empty_merged_tag),
283
branch2 = Branch.open('output2')
284
repo2 = branch2.repository
285
# and import what we should be merged up against for checking with.
286
import_version('output3', pybaz.Version(self._baz._empty_tag),
288
branch3 = Branch.open('output3')
290
self.assertEqual(branch.revision_history(), branch2.revision_history())
291
self.assertNotEqual(branch.revision_history(),
292
branch3.revision_history())
293
# check revisions in the history.
294
rev = repo.get_revision(self._baz._empty_merged_tag_bzr_base)
295
rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr_base)
296
# they must be the same
297
self.assertEqual(rev, rev2)
298
# and we should get some expected values:
299
self.assertEqual(rev.committer, "Test User<test@example.org>")
300
self.assertEqual(rev.message,
301
"tag of demo@DONOTUSE/c--import--0--base-0")
302
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr_base)
303
self.assertEqual(['Arch-1:demo@DONOTUSE%c--import--0--base-0'],
306
# check next revisions in the history.
307
rev = repo.get_revision(self._baz._empty_merged_tag_bzr)
308
rev2 = repo2.get_revision(self._baz._empty_merged_tag_bzr)
309
# they must be the same
310
self.assertEqual(rev, rev2)
311
# and we should get some expected values:
312
self.assertEqual(rev.committer, "Test User<test@example.org>")
313
self.assertEqual(rev.message, "did a merge, yarh")
314
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_bzr)
315
self.assertEqual(rev.parent_ids[0],
316
self._baz._empty_merged_tag_bzr_base)
317
self.assertEqual(rev.parent_ids[1], self._baz._empty_tag_bzr)
319
# this tree should have nothing missing from that tree.
320
# FIXME there is no code for this right now.
321
# self.assertEqual(branch.missing_revisions(branch3), [])
323
def test_merge_branch_with_merges(self):
324
import_version('output', pybaz.Version(self._baz._empty_merged_tag_2),
327
# two commits, no files, revision identifiers of
328
# 'demo@DONOTUSE_c--import--0--base-0' and
329
# self._baz._empty_merged_tag_2_bzr_base
330
# self._baz._empty_merged_tag_2_bzr
331
# and a merged revision from the latter of
332
# self._baz._empty_merged_tag_bzr
333
branch = Branch.open('output')
334
repo = branch.repository
335
self.assertEqual(branch.revision_history(),
336
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
337
self._baz._empty_merged_tag_2_bzr_base,
338
self._baz._empty_merged_tag_2_bzr])
340
import_version('output2', pybaz.Version(self._baz._empty_merged_tag_2),
342
branch2 = Branch.open('output2')
343
repo2 = branch2.repository
344
# and import what we should be merged up against for checking with.
345
import_version('output3', pybaz.Version(self._baz._empty_merged_tag),
347
branch3 = Branch.open('output3')
349
self.assertEqual(branch.revision_history(), branch2.revision_history())
350
self.assertNotEqual(branch.revision_history(),
351
branch3.revision_history())
352
# check revisions in the history.
353
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr_base)
354
rev2 = repo2.get_revision(self._baz._empty_merged_tag_2_bzr_base)
355
# they must be the same
356
self.assertEqual(rev, rev2)
357
# and we should get some expected values:
358
self.assertEqual(rev.committer, "Test User<test@example.org>")
359
self.assertEqual(rev.message,
360
"tag of demo@DONOTUSE/c--import--0--base-0")
361
self.assertEqual(rev.revision_id,
362
self._baz._empty_merged_tag_2_bzr_base)
364
# check next revisions in the history.
365
rev = repo.get_revision(self._baz._empty_merged_tag_2_bzr)
366
rev2 = repo2.get_revision(self._baz._empty_merged_tag_2_bzr)
367
# they must be the same
368
self.assertEqual(rev, rev2)
369
# and we should get some expected values:
370
self.assertEqual(rev.committer, "Test User<test@example.org>")
371
self.assertEqual(rev.message, "merge in a merged tree.")
372
self.assertEqual(rev.revision_id, self._baz._empty_merged_tag_2_bzr)
373
self.assertEqual(rev.parent_ids[0],
374
self._baz._empty_merged_tag_2_bzr_base)
375
self.assertEqual(rev.parent_ids[1],
376
self._baz._empty_merged_tag_bzr)
378
# this tree should have nothing missing from that tree.
379
# FIXME there is no code for this right now.
380
# self.assertEqual(branch.missing_revisions(branch3), [])
382
def test_import_symlink(self):
383
import_version('output', pybaz.Version(self._baz._import_symlink),
386
# one commit, no files, revision identifier of
387
# 'demo@DONOTUSE_c--import--0--base-0'
388
branch = Branch.open('output')
389
self.assertEqual(branch.revision_history(),
390
[self._baz._import_symlink_bzr])
391
rev = branch.repository.get_revision(self._baz._import_symlink_bzr)
393
import_version('output2', pybaz.Version(self._baz._import_symlink),
395
branch2 = Branch.open('output2')
396
self.assertEqual(branch.revision_history(), branch2.revision_history())
397
rev2 = branch2.repository.get_revision(self._baz._import_symlink_bzr)
398
# they must be the same
399
self.assertEqual(rev, rev2)
401
# and we should get some expected values:
402
self.assertEqual(rev.committer, "Test User<test@example.org>")
403
self.assertEqual(rev.message, "Import with a symlink")
404
self.assertEqual(rev.revision_id, self._baz._import_symlink_bzr)
406
# and we want the symlink alink with target 'missing-file-name'
407
inv = branch.repository.get_inventory(rev.revision_id)
408
self.assertEqual(inv.path2id('alink'), 'x_symlink_tag')
409
entry = inv['x_symlink_tag']
410
self.assertEqual(entry.kind, 'symlink')
411
self.assertEqual(entry.symlink_target, 'missing-file-name')
413
def test_missing_ancestor(self):
414
import_version('output', pybaz.Version(self._baz._missing_ancestor),
417
# one commits, no files, revision identifiers of
418
# 'demo@DONOTUSE_c--gone--0--base-0' and
419
# a merge of demo-gone@DONOTUSE%c--import--0
420
branch = Branch.open('output')
421
self.assertEqual(branch.revision_history(),
422
[self._baz._missing_ancestor_bzr])
423
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
425
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
427
branch2 = Branch.open('output2')
428
self.assertEqual(branch.revision_history(), branch2.revision_history())
429
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
430
# they must be the same
431
self.assertEqual(rev, rev2)
433
# and we should get some expected values:
434
self.assertEqual(rev.committer, "Test User<test@example.org>")
435
self.assertEqual(rev.message,
436
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
437
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
438
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
439
self.assertEqual(1, len(rev.parent_ids))
441
# must NOT be able to get the merged evision
442
self.assertRaises(NoSuchRevision, branch.repository.get_revision,
443
self._baz._missing_import_bzr)
445
def test_missing_ancestor_reusing_history(self):
446
import_version('output', pybaz.Version(self._baz._missing_ancestor),
448
reuse_history_from=[self._baz._missing_import_imported])
450
# one commits, no files, revision identifiers of
451
# 'demo-gone@DONOTUSE%c--import--0--base-0' and
452
# 'demo@DONOTUSE%c--gone--0--base-0'
453
branch = Branch.open('output')
454
self.assertEqual(branch.revision_history(),
455
[self._baz._missing_import_bzr,
456
self._baz._missing_ancestor_bzr])
457
rev = branch.repository.get_revision(self._baz._missing_ancestor_bzr)
459
import_version('output2', pybaz.Version(self._baz._missing_ancestor),
461
reuse_history_from=[self._baz._missing_import_imported])
462
branch2 = Branch.open('output2')
463
self.assertEqual(branch.revision_history(), branch2.revision_history())
464
rev2 = branch2.repository.get_revision(self._baz._missing_ancestor_bzr)
465
# they must be the same
466
self.assertEqual(rev, rev2)
468
# must be able to get the missing base revision
469
branch.repository.get_revision(self._baz._missing_import_bzr)
471
# and we should get some expected values:
472
self.assertEqual(rev.committer, "Test User<test@example.org>")
473
self.assertEqual(rev.message,
474
"tag of demo-gone@DONOTUSE/c--import--0--base-0")
475
self.assertEqual(rev.revision_id, self._baz._missing_ancestor_bzr)
476
self.assertEqual(rev.parent_ids[0], self._baz._missing_import_bzr)
477
self.assertEqual(1, len(rev.parent_ids))
479
def test_bad_file_id(self):
480
import_version('output', pybaz.Version(self._baz._bad_id_tag),
483
# three commits, one files, revision identifiers of
484
# 'demo@DONOTUSE_c--import--0--base-0' ,
485
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
486
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
487
branch = Branch.open('output')
488
self.assertEqual(branch.revision_history(),
489
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
490
self._baz._bad_id_tag_bzr_base,
491
self._baz._bad_id_tag_bzr])
492
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
493
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
494
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
495
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
497
def test_appending_revisions_already_present(self):
498
import_version('output', pybaz.Version(self._baz._bad_id_tag),
499
self.collect, max_count=2)
501
# three commits, one files, revision identifiers of
502
# 'demo@DONOTUSE_c--import--0--base-0' ,
503
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
504
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
505
branch = Branch.open('output')
506
self.assertEqual(branch.revision_history(),
507
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
508
self._baz._bad_id_tag_bzr_base])
509
branch.set_revision_history(
510
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
512
branch = Branch.open('output')
513
self.assertEqual(branch.revision_history(),
514
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
516
import_version('output', pybaz.Version(self._baz._bad_id_tag),
518
branch = Branch.open('output')
519
self.assertEqual(branch.revision_history(),
520
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
521
self._baz._bad_id_tag_bzr_base,
522
self._baz._bad_id_tag_bzr])
523
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
524
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
525
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
526
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
528
def test_appending_revisions_all_already_present(self):
529
import_version('output', pybaz.Version(self._baz._bad_id_tag),
532
# three commits, one files, revision identifiers of
533
# 'demo@DONOTUSE_c--import--0--base-0' ,
534
# 'demo@DONOTUSE/c--bad-id--0--base-0' ,
535
# ''demo@DONOTUSE/c--bad-id--0--patch-1'
536
branch = Branch.open('output')
537
self.assertEqual(branch.revision_history(),
538
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
539
self._baz._bad_id_tag_bzr_base,
540
self._baz._bad_id_tag_bzr])
541
branch.set_revision_history(
542
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
544
branch = Branch.open('output')
545
self.assertEqual(branch.revision_history(),
546
['Arch-1:demo@DONOTUSE%c--import--0--base-0'])
548
import_version('output', pybaz.Version(self._baz._bad_id_tag),
550
branch = Branch.open('output')
551
self.assertEqual(branch.revision_history(),
552
['Arch-1:demo@DONOTUSE%c--import--0--base-0',
553
self._baz._bad_id_tag_bzr_base,
554
self._baz._bad_id_tag_bzr])
555
rev = branch.repository.get_revision(self._baz._bad_id_tag_bzr)
556
inv = branch.repository.get_inventory(self._baz._bad_id_tag_bzr)
557
self.assertEqual(inv.path2id('path'), 'x_this_id%2fneeds%25escaping')
558
self.assertEqual('path', inv.id2path('x_this_id%2fneeds%25escaping'))
561
class TestNamespacePrevious(TestCase):
565
self.version = pybaz.Version('foo@example.com/c--b--0')
567
def test_base0_none(self):
568
self.assertEqual(namespace_previous(self.version['base-0']), None)
570
def test_patch1_base0(self):
571
self.assertEqual(namespace_previous(self.version['patch-1']),
572
self.version['base-0'])
574
def test_patch3000_patch2999(self):
575
self.assertEqual(namespace_previous(self.version['patch-3000']),
576
self.version['patch-2999'])
578
def test_version0_raises(self):
579
self.assertRaises(RuntimeError, namespace_previous,
580
self.version['version-0'])
582
def test_version1_version0(self):
583
self.assertEqual(namespace_previous(self.version['versionfix-1']),
584
self.version['version-0'])
586
def test_version3000_patch2999(self):
587
self.assertEqual(namespace_previous(self.version['versionfix-3000']),
588
self.version['versionfix-2999'])
590
class TestNamespaceMapping(TestCase):
592
def test_namespace_mapping_branch(self):
593
from bzrlib.plugins.bzrtools.baz_import import map_namespace
594
branch = pybaz.Branch('foo@example.com/c--b')
595
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, branch)
596
self.assertEqual('c/b', map_namespace(branch['0']))
597
self.assertEqual('c/0.1/b', map_namespace(branch['0.1']))
599
def test_namespace_mapping_no_branch(self):
600
from bzrlib.plugins.bzrtools.baz_import import map_namespace
601
category = pybaz.Category('foo@example.com/c')
602
self.assertRaises(pybaz.errors.NamespaceError, map_namespace, category)
603
self.assertEqual('c/+trunk',
604
map_namespace(pybaz.Version("%s--0" % category)))
605
self.assertEqual('c/0.1/+trunk',
606
map_namespace(pybaz.Version('%s--0.1' % category)))
609
class TestFileIdMapping(TestCase):
611
def test_slash(self):
612
from bzrlib.plugins.bzrtools.baz_import import map_file_id
613
self.assertEqual('c%2fc', map_file_id('c/c'))
614
self.assertEqual('c%25c', map_file_id('c%c'))
617
class TestImport(TestCaseInTempDir):
620
TestCaseInTempDir.setUp(self)
621
self._oldhome = os.environ['HOME']
622
self._tmpdir = tempfile.mkdtemp()
623
self._homedir = os.path.join(self._tmpdir, 'home')
624
os.mkdir(self._homedir)
625
os.environ['HOME'] = self._homedir
626
self._archiveroot = os.path.join(self._tmpdir, 'archive')
627
self._archive = make_archive('demo@DONOTUSE', str(self._archiveroot))
630
os.environ['HOME'] = self._oldhome
631
shutil.rmtree(self._tmpdir)
632
TestCaseInTempDir.tearDown(self)
634
def make_import(self, namespace):
635
self._import = 'demo@DONOTUSE/%s' % namespace
636
os.mkdir(os.path.join(self._tmpdir, 'tree'))
637
tree = pybaz.init_tree(os.path.join(self._tmpdir, 'tree'),
639
msg = tree.log_message()
640
msg["summary"] = "I am importing now"
642
shutil.rmtree(os.path.join(self._tmpdir, 'tree'))
644
def test_cmd_exists(self):
645
from bzrlib.plugins.bzrtools.baz_import import cmd_baz_import
647
def test_empty_archive(self):
648
command = cmd_baz_import()
649
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
650
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
651
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
652
self.assertEqual(1, walk_len)
654
def test_two_branches(self):
655
self.make_import('c--0')
656
self.make_import('c1--branch--0.2')
657
command = cmd_baz_import()
658
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
659
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output')))
660
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
662
self.failUnless(os.path.exists(os.path.join(self._tmpdir,'output',
663
'c1', '0.2','branch')))
664
walk_len = len(list(os.walk(os.path.join(self._tmpdir,'output'))))
665
self.assertEqual(14, walk_len)
667
def test_run_twice(self):
668
self.make_import('c--0')
669
command = cmd_baz_import()
670
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
671
command.run(os.path.join(self._tmpdir, 'output'), 'demo@DONOTUSE')
673
def test_accepts_reuse_history(self):
674
self.make_import('c--0')
675
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),
676
'demo@DONOTUSE', '.', '.')
678
def test_does_not_need_reuse_history(self):
679
self.make_import('c--0')
680
self.run_bzr('baz-import', os.path.join(self._tmpdir, 'output'),