~cjwatson/brz-loom/breezy-3.0.0

« back to all changes in this revision

Viewing changes to tests/test_branch.py

  • Committer: Robert Collins
  • Date: 2006-06-20 08:55:26 UTC
  • Revision ID: robertc@robertcollins.net-20060620085526-52a3d22a579958c8
Start loom.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Loom, a plugin for bzr to assist in developing focused patches.
 
2
# Copyright (C) 2006 Canonical Limited.
 
3
 
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.
 
8
 
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.
 
13
 
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
 
17
 
18
 
 
19
 
 
20
"""Tests of the loom Branch related routines."""
 
21
 
 
22
 
 
23
import bzrlib
 
24
import bzrlib.revision
 
25
from bzrlib.tests import TestCaseWithTransport
 
26
 
 
27
 
 
28
class TestFormat(TestCaseWithTransport):
 
29
 
 
30
    def test_take_over_branch(self):
 
31
        branch = self.make_branch('.')
 
32
        format = bzrlib.plugins.loom.branch.BzrBranchLoomFormat1()
 
33
        branch.lock_write()
 
34
        try:
 
35
            format.take_over(branch)
 
36
        finally:
 
37
            branch.unlock()
 
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())
 
44
 
 
45
 
 
46
class TestLoom(TestCaseWithTransport):
 
47
 
 
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())
 
56
        self.assertEqual(
 
57
            [('foo', bzrlib.revision.NULL_REVISION)],
 
58
            branch.get_threads())
 
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())
 
63
        self.assertEqual(
 
64
            [('foo', bzrlib.revision.NULL_REVISION),
 
65
             ('bar', bzrlib.revision.NULL_REVISION)],
 
66
            branch.get_threads())
 
67
 
 
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())
 
77
 
 
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')
 
86
        self.assertEqual(
 
87
            [('foo', rev_id)],
 
88
            branch.get_threads())