1
# Loom, a plugin for bzr to assist in developing focused patches.
2
# Copyright (C) 2006 Canonical Limited.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
"""Tests of the loom Branch related routines."""
24
import bzrlib.revision
25
from bzrlib.tests import TestCaseWithTransport
28
class TestFormat(TestCaseWithTransport):
30
def test_take_over_branch(self):
31
branch = self.make_branch('.')
32
format = bzrlib.plugins.loom.branch.BzrBranchLoomFormat1()
35
format.take_over(branch)
38
# a loomed branch opens with a different format
39
branch = bzrlib.branch.Branch.open('.')
40
self.assertIsInstance(branch, bzrlib.plugins.loom.branch.LoomBranch)
41
# and it should have recorded loom content so we can do
42
self.assertFileEqual('', '.bzr/branch/last-loom')
43
self.assertEqual([], branch.loom_parents())
46
class TestLoom(TestCaseWithTransport):
48
def test_new_thread_empty_branch(self):
49
branch = self.make_branch('.')
50
format = bzrlib.plugins.loom.branch.BzrBranchLoomFormat1()
51
format.take_over(branch)
52
branch = bzrlib.branch.Branch.open('.')
53
loom_rev_id = branch.new_thread('foo')
54
self.assertNotEqual(None, loom_rev_id)
55
self.assertEqual([loom_rev_id], branch.loom_parents())
57
[('foo', bzrlib.revision.NULL_REVISION)],
59
loom_rev_id_2 = branch.new_thread('bar')
60
self.assertNotEqual(loom_rev_id, loom_rev_id_2)
61
self.assertNotEqual(None, loom_rev_id_2)
62
self.assertEqual([loom_rev_id_2], branch.loom_parents())
64
[('foo', bzrlib.revision.NULL_REVISION),
65
('bar', bzrlib.revision.NULL_REVISION)],
68
def test_new_thread_no_duplicate_names(self):
69
branch = self.make_branch('.')
70
format = bzrlib.plugins.loom.branch.BzrBranchLoomFormat1()
71
format.take_over(branch)
72
branch = bzrlib.branch.Branch.open('.')
73
branch.new_thread('foo')
74
self.assertRaises(bzrlib.plugins.loom.branch.DuplicateThreadName,
75
branch.new_thread, 'foo')
76
self.assertEqual([('foo', bzrlib.revision.NULL_REVISION)], branch.get_threads())
78
def test_new_thread_with_commits(self):
79
"""Test converting a branch to a loom once it has commits."""
80
tree = self.make_branch_and_tree('.')
81
rev_id = tree.commit('first post')
82
format = bzrlib.plugins.loom.branch.BzrBranchLoomFormat1()
83
format.take_over(tree.branch)
84
branch = bzrlib.branch.Branch.open('.')
85
branch.new_thread('foo')