1
# Copyright (C) 2007, 2009-2012, 2016 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 Branch.get_rev_id."""
19
from breezy.errors import RevnoOutOfBounds
20
from breezy.revision import NULL_REVISION
21
from breezy.tests import TestCaseWithTransport
24
class TestGetRevid(TestCaseWithTransport):
26
def test_empty_branch(self):
27
# on an empty branch we want (0, NULL_REVISION)
28
branch = self.make_branch('branch')
29
self.assertEqual(NULL_REVISION, branch.get_rev_id(0))
30
self.assertRaises(RevnoOutOfBounds, branch.get_rev_id, 1)
31
self.assertRaises(RevnoOutOfBounds, branch.get_rev_id, -1)
33
def test_non_empty_branch(self):
34
# after the second commit we want (2, 'second-revid')
35
tree = self.make_branch_and_tree('branch')
36
revid1 = tree.commit('1st post')
37
revid2 = tree.commit('2st post', allow_pointless=True)
38
self.assertEqual(revid2, tree.branch.get_rev_id(2))
39
self.assertEqual(revid1, tree.branch.get_rev_id(1))
40
self.assertRaises(RevnoOutOfBounds, tree.branch.get_rev_id, 3)