/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_basis_inventory.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
20
20
from bzrlib.branch import Branch
 
21
from bzrlib import inventory
21
22
from bzrlib.revision import Revision
22
 
import bzrlib.xml5
 
23
import bzrlib.xml6
23
24
 
24
25
 
25
26
class TestBasisInventory(TestCaseWithWorkingTree):
35
36
        t.add('a')
36
37
        t.commit('a', rev_id='r1')
37
38
 
38
 
        t._control_files.get_utf8('basis-inventory')
 
39
        t._control_files.get_utf8('basis-inventory-cache')
39
40
 
40
41
        basis_inv = t.basis_tree().inventory
41
42
        self.assertEquals('r1', basis_inv.revision_id)
47
48
        t.add('b')
48
49
        t.commit('b', rev_id='r2')
49
50
 
50
 
        t._control_files.get_utf8('basis-inventory')
 
51
        t._control_files.get_utf8('basis-inventory-cache')
51
52
 
52
53
        basis_inv_txt = t.read_basis_inventory()
53
 
        basis_inv = bzrlib.xml5.serializer_v5.read_inventory_from_string(basis_inv_txt)
54
 
        basis_inv.root.revision = 'r2'
 
54
        basis_inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(basis_inv_txt)
55
55
        self.assertEquals('r2', basis_inv.revision_id)
56
56
        store_inv = b.repository.get_inventory('r2')
57
57
 
58
58
        self.assertEquals(store_inv._byid, basis_inv._byid)
59
59
 
 
60
    def test_wrong_format(self):
 
61
        """WorkingTree.basis safely ignores junk basis inventories"""
 
62
        t = self.make_branch_and_tree('.')
 
63
        b = t.branch
 
64
        open('a', 'wb').write('a\n')
 
65
        t.add('a')
 
66
        t.commit('a', rev_id='r1')
 
67
        t._control_files.put_utf8('basis-inventory-cache', 'booga')
 
68
        t.basis_tree()
 
69
        t._control_files.put_utf8('basis-inventory-cache', '<xml/>')
 
70
        t.basis_tree()
 
71
        t._control_files.put_utf8('basis-inventory-cache', '<inventory />')
 
72
        t.basis_tree()
 
73
        t._control_files.put_utf8('basis-inventory-cache', 
 
74
                                  '<inventory format="pi"/>')
 
75
        t.basis_tree()
 
76
 
60
77
    def test_basis_inv_gets_revision(self):
61
78
        """When the inventory of the basis tree has no revision id it gets set.
62
79
 
65
82
        tree = self.make_branch_and_tree('.')
66
83
        tree.lock_write()
67
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]
68
89
        tree.branch.repository.control_weaves.get_weave('inventory',
69
90
            tree.branch.repository.get_transaction()
70
 
            ).add_lines('r1', [], [
71
 
                '<inventory format="5">\n',
72
 
                '</inventory>\n'])
 
91
            ).add_lines('r1', [], inv_lines)
73
92
        rev = Revision(timestamp=0,
74
93
                       timezone=None,
75
94
                       committer="Foo Bar <foo@example.com>",
86
105
        # without parsing, but to do this properly needs a serialiser on the
87
106
        # tree object that abstracts whether it is xml/rio/etc.
88
107
        self.assertContainsRe(
89
 
            tree._control_files.get_utf8('basis-inventory').read(),
 
108
            tree._control_files.get_utf8('basis-inventory-cache').read(),
90
109
            'revision_id="r1"')
91
110