~jelmer/ubuntu/maverick/bzr/2.2.5

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_repository/test_get_parent_map.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-03-10 14:11:59 UTC
  • mfrom: (1.2.1 upstream) (3.1.68 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090310141159-lwzzo5c1fwrtzgj4
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008 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
"""Tests for the get_parent_map API."""
 
18
 
 
19
from bzrlib import revision
 
20
from bzrlib.tests.per_repository import TestCaseWithRepository
 
21
 
 
22
 
 
23
class TestGetParentMap(TestCaseWithRepository):
 
24
 
 
25
    def test_missing_revision(self):
 
26
        tree = self.make_branch_and_tree('.')
 
27
        repo = tree.branch.repository
 
28
        repo.lock_read()
 
29
        self.addCleanup(repo.unlock)
 
30
        self.assertEqual({}, repo.get_parent_map(['non-existant']))
 
31
 
 
32
    def test_multiple_parents(self):
 
33
        tree = self.make_branch_and_tree('.')
 
34
        rev1 = tree.commit('first')
 
35
        rev2 = tree.commit('second')
 
36
        tree.set_parent_ids([rev1, rev2])
 
37
        tree.branch.set_last_revision_info(1, rev1)
 
38
        rev3 = tree.commit('third')
 
39
        repo = tree.branch.repository
 
40
        repo.lock_read()
 
41
        self.addCleanup(repo.unlock)
 
42
        self.assertEqual({rev3:(rev1, rev2)},
 
43
                         repo.get_parent_map([rev3]))
 
44
        self.assertEqual({rev1:(revision.NULL_REVISION,),
 
45
                          rev2:(rev1,),
 
46
                          rev3:(rev1, rev2),
 
47
                         }, repo.get_parent_map([rev1, rev2, rev3]))
 
48
 
 
49
    def test_no_parents(self):
 
50
        tree = self.make_branch_and_tree('.')
 
51
        rev1 = tree.commit('first')
 
52
        repo = tree.branch.repository
 
53
        repo.lock_read()
 
54
        self.addCleanup(repo.unlock)
 
55
        self.assertEqual({rev1:(revision.NULL_REVISION,)},
 
56
                         repo.get_parent_map([rev1]))
 
57
 
 
58
    def test_none(self):
 
59
        tree = self.make_branch_and_tree('.')
 
60
        rev1 = tree.commit('first')
 
61
        repo = tree.branch.repository
 
62
        repo.lock_read()
 
63
        self.addCleanup(repo.unlock)
 
64
        self.assertRaises(ValueError,
 
65
                          repo.get_parent_map, [None])
 
66
 
 
67
    def test_null_revision(self):
 
68
        tree = self.make_branch_and_tree('.')
 
69
        repo = tree.branch.repository
 
70
        repo.lock_read()
 
71
        self.addCleanup(repo.unlock)
 
72
        self.assertEqual({revision.NULL_REVISION:()},
 
73
                         repo.get_parent_map([revision.NULL_REVISION]))