26
27
class TestBasisInventory(TestCaseWithWorkingTree):
28
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.WorkingTreeFormat4):
34
raise TestNotApplicable("not applicable to %r"
35
% (self.workingtree_format,))
29
36
# TODO: jam 20051218 this probably should add more than just
30
37
# a couple files to the inventory
49
56
t.commit('b', rev_id='r2')
51
t._control_files.get_utf8('basis-inventory-cache')
58
self.assertTrue(t._transport.has('basis-inventory-cache'))
53
60
basis_inv_txt = t.read_basis_inventory()
54
basis_inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(basis_inv_txt)
61
basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
55
62
self.assertEquals('r2', basis_inv.revision_id)
56
63
store_inv = b.repository.get_inventory('r2')
60
67
def test_wrong_format(self):
61
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.WorkingTreeFormat4):
73
raise TestNotApplicable("not applicable to %r"
74
% (self.workingtree_format,))
62
75
t = self.make_branch_and_tree('.')
64
77
open('a', 'wb').write('a\n')
66
79
t.commit('a', rev_id='r1')
67
t._control_files.put_utf8('basis-inventory-cache', 'booga')
69
t._control_files.put_utf8('basis-inventory-cache', '<xml/>')
71
t._control_files.put_utf8('basis-inventory-cache', '<inventory />')
73
t._control_files.put_utf8('basis-inventory-cache',
74
'<inventory format="pi"/>')
77
def test_basis_inv_gets_revision(self):
78
"""When the inventory of the basis tree has no revision id it gets set.
80
It gets set during set_parent_trees() or set_parent_ids().
82
tree = self.make_branch_and_tree('.')
84
# TODO change this to use CommitBuilder
85
inv = inventory.Inventory(revision_id='r1')
86
inv.root.revision = 'r1'
87
inv_lines = tree.branch.repository.serialise_inventory(inv).split('\n')
88
inv_lines = [(l + '\n') for l in inv_lines if l is not None]
89
tree.branch.repository.control_weaves.get_weave('inventory',
90
tree.branch.repository.get_transaction()
91
).add_lines('r1', [], inv_lines)
92
rev = Revision(timestamp=0,
94
committer="Foo Bar <foo@example.com>",
99
tree.branch.repository.add_revision('r1', rev)
101
tree.branch.append_revision('r1')
102
tree.set_parent_trees(
103
[('r1', tree.branch.repository.revision_tree('r1'))])
104
# TODO: we should deserialise the file here, rather than peeking
105
# without parsing, but to do this properly needs a serialiser on the
106
# tree object that abstracts whether it is xml/rio/etc.
107
self.assertContainsRe(
108
tree._control_files.get_utf8('basis-inventory-cache').read(),
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"/>')