1
# Copyright (C) 2004, 2005, 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
19
from bzrlib.tests import TestNotApplicable
20
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
21
from bzrlib.branch import Branch
22
from bzrlib import inventory
23
from bzrlib.revision import Revision
27
class TestBasisInventory(TestCaseWithWorkingTree):
29
def test_create(self):
30
# This test is not applicable to DirState based trees: the basis is
31
# not separate is mandatory.
32
if isinstance(self.workingtree_format,
33
bzrlib.workingtree_4.DirStateWorkingTreeFormat):
34
raise TestNotApplicable("not applicable to %r"
35
% (self.workingtree_format,))
36
# TODO: jam 20051218 this probably should add more than just
37
# a couple files to the inventory
39
# Make sure the basis file is created by a commit
40
t = self.make_branch_and_tree('.')
42
open('a', 'wb').write('a\n')
44
t.commit('a', rev_id='r1')
46
self.assertTrue(t._transport.has('basis-inventory-cache'))
48
basis_inv = t.basis_tree().inventory
49
self.assertEquals('r1', basis_inv.revision_id)
51
store_inv = b.repository.get_inventory('r1')
52
self.assertEqual([], store_inv._make_delta(basis_inv))
54
open('b', 'wb').write('b\n')
56
t.commit('b', rev_id='r2')
58
self.assertTrue(t._transport.has('basis-inventory-cache'))
60
basis_inv_txt = t.read_basis_inventory()
61
basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
62
self.assertEquals('r2', basis_inv.revision_id)
63
store_inv = b.repository.get_inventory('r2')
65
self.assertEqual([], store_inv._make_delta(basis_inv))
67
def test_wrong_format(self):
68
"""WorkingTree.basis safely ignores junk basis inventories"""
69
# This test is not applicable to DirState based trees: the basis is
70
# not separate and ignorable.
71
if isinstance(self.workingtree_format,
72
bzrlib.workingtree_4.DirStateWorkingTreeFormat):
73
raise TestNotApplicable("not applicable to %r"
74
% (self.workingtree_format,))
75
t = self.make_branch_and_tree('.')
77
open('a', 'wb').write('a\n')
79
t.commit('a', rev_id='r1')
80
t._transport.put_bytes('basis-inventory-cache', 'booga')
82
t._transport.put_bytes('basis-inventory-cache', '<xml/>')
84
t._transport.put_bytes('basis-inventory-cache', '<inventory />')
86
t._transport.put_bytes('basis-inventory-cache',
87
'<inventory format="pi"/>')