/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1034 by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron
1
# (C) 2005 Canonical Ltd
2
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
from bzrlib.selftest import InTempDir
18
19
20
def make_branches():
21
    from bzrlib.branch import Branch
22
    from bzrlib.commit import commit
23
    import os
24
    os.mkdir("branch1")
25
    br1 = Branch("branch1", init=True)
26
    commit(br1, "Commit one")
27
    commit(br1, "Commit two")
28
    commit(br1, "Commit three")
29
30
    os.mkdir("branch2")
31
    br2 = Branch("branch2", init=True)
32
    br2.update_revisions(br1)
33
    commit(br2, "Commit four")
34
    commit(br2, "Commit five")
35
    revisions_2 = br2.revision_history()
36
    br1.add_pending_merge(revisions_2[4])
37
    commit(br1, "Commit six")
38
    return br1, br2
39
40
41
class TestIsAncestor(InTempDir):
1102 by Martin Pool
- merge test refactoring from robertc
42
43
    def test_is_ancestor(self):
44
        """Test checking whether a revision is an ancestor of another revision"""
1034 by Martin Pool
- merge bzrlib.revision.is_ancestor from aaron
45
        from bzrlib.revision import is_ancestor, MultipleRevisionSources
46
        from bzrlib.errors import NoSuchRevision
47
        br1, br2 = make_branches()
48
        revisions = br1.revision_history()
49
        revisions_2 = br2.revision_history()
50
        sources = MultipleRevisionSources(br1, br2)
51
52
        assert is_ancestor(revisions[0], revisions[0], sources)
53
        assert is_ancestor(revisions[1], revisions[0], sources)
54
        assert not is_ancestor(revisions[0], revisions[1], sources)
55
        assert is_ancestor(revisions_2[3], revisions[0], sources)
56
        self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
57
                          revisions[0], br1)        
58
        assert is_ancestor(revisions[3], revisions_2[4], sources)
59
        assert is_ancestor(revisions[3], revisions_2[4], br1)
60
        assert is_ancestor(revisions[3], revisions_2[3], sources)
61
        assert not is_ancestor(revisions[3], revisions_2[3], br1)
62
63
64
TEST_CLASSES = [
65
    TestIsAncestor,
66
    ]