1
# Copyright (C) 2008 Canonical Ltd
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for the get_parent_map API."""
19
from bzrlib import revision
20
from bzrlib.tests.per_repository import TestCaseWithRepository
23
class TestGetParentMap(TestCaseWithRepository):
25
def test_missing_revision(self):
26
tree = self.make_branch_and_tree('.')
27
repo = tree.branch.repository
29
self.addCleanup(repo.unlock)
30
self.assertEqual({}, repo.get_parent_map(['non-existant']))
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
41
self.addCleanup(repo.unlock)
42
self.assertEqual({rev3:(rev1, rev2)},
43
repo.get_parent_map([rev3]))
44
self.assertEqual({rev1:(revision.NULL_REVISION,),
47
}, repo.get_parent_map([rev1, rev2, rev3]))
49
def test_no_parents(self):
50
tree = self.make_branch_and_tree('.')
51
rev1 = tree.commit('first')
52
repo = tree.branch.repository
54
self.addCleanup(repo.unlock)
55
self.assertEqual({rev1:(revision.NULL_REVISION,)},
56
repo.get_parent_map([rev1]))
59
tree = self.make_branch_and_tree('.')
60
rev1 = tree.commit('first')
61
repo = tree.branch.repository
63
self.addCleanup(repo.unlock)
64
self.assertRaises(ValueError,
65
repo.get_parent_map, [None])
67
def test_null_revision(self):
68
tree = self.make_branch_and_tree('.')
69
repo = tree.branch.repository
71
self.addCleanup(repo.unlock)
72
self.assertEqual({revision.NULL_REVISION:()},
73
repo.get_parent_map([revision.NULL_REVISION]))