1
# Copyright (C) 2004, 2005, 2008 Canonical Ltd
1
# Copyright (C) 2005-2009, 2011, 2012, 2016 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
17
from bzrlib.tests import TestNotApplicable
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
21
from bzrlib.branch import Branch
22
from bzrlib import inventory
23
from bzrlib.revision import Revision
18
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
30
25
# This test is not applicable to DirState based trees: the basis is
31
26
# not separate is mandatory.
32
27
if isinstance(self.workingtree_format,
33
bzrlib.workingtree_4.WorkingTreeFormat4):
28
bzrlib.workingtree_4.DirStateWorkingTreeFormat):
34
29
raise TestNotApplicable("not applicable to %r"
35
30
% (self.workingtree_format,))
36
31
# TODO: jam 20051218 this probably should add more than just
39
34
# Make sure the basis file is created by a commit
40
35
t = self.make_branch_and_tree('.')
42
open('a', 'wb').write('a\n')
37
with open('a', 'wb') as f: f.write('a\n')
44
39
t.commit('a', rev_id='r1')
46
41
self.assertTrue(t._transport.has('basis-inventory-cache'))
48
basis_inv = t.basis_tree().inventory
49
self.assertEquals('r1', basis_inv.revision_id)
43
basis_inv = t.basis_tree().root_inventory
44
self.assertEqual('r1', basis_inv.revision_id)
51
46
store_inv = b.repository.get_inventory('r1')
52
self.assertEquals(store_inv._byid, basis_inv._byid)
47
self.assertEqual([], store_inv._make_delta(basis_inv))
54
open('b', 'wb').write('b\n')
49
with open('b', 'wb') as f: f.write('b\n')
56
51
t.commit('b', rev_id='r2')
60
55
basis_inv_txt = t.read_basis_inventory()
61
56
basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
62
self.assertEquals('r2', basis_inv.revision_id)
57
self.assertEqual('r2', basis_inv.revision_id)
63
58
store_inv = b.repository.get_inventory('r2')
65
self.assertEquals(store_inv._byid, basis_inv._byid)
60
self.assertEqual([], store_inv._make_delta(basis_inv))
67
62
def test_wrong_format(self):
68
63
"""WorkingTree.basis safely ignores junk basis inventories"""
69
64
# This test is not applicable to DirState based trees: the basis is
70
65
# not separate and ignorable.
71
66
if isinstance(self.workingtree_format,
72
bzrlib.workingtree_4.WorkingTreeFormat4):
67
bzrlib.workingtree_4.DirStateWorkingTreeFormat):
73
68
raise TestNotApplicable("not applicable to %r"
74
69
% (self.workingtree_format,))
75
70
t = self.make_branch_and_tree('.')
77
open('a', 'wb').write('a\n')
72
with open('a', 'wb') as f: f.write('a\n')
79
74
t.commit('a', rev_id='r1')
80
75
t._transport.put_bytes('basis-inventory-cache', 'booga')