/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

First attempt to merge .dev and resolve the conflicts (but tests are 
failing)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2008 Canonical Ltd
2
2
#
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
16
16
 
17
17
import os
18
18
 
 
19
from bzrlib.tests import TestNotApplicable
19
20
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
20
21
from bzrlib.branch import Branch
21
22
from bzrlib import inventory
26
27
class TestBasisInventory(TestCaseWithWorkingTree):
27
28
 
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
31
38
 
36
43
        t.add('a')
37
44
        t.commit('a', rev_id='r1')
38
45
 
39
 
        t._control_files.get_utf8('basis-inventory-cache')
 
46
        self.assertTrue(t._transport.has('basis-inventory-cache'))
40
47
 
41
48
        basis_inv = t.basis_tree().inventory
42
49
        self.assertEquals('r1', basis_inv.revision_id)
48
55
        t.add('b')
49
56
        t.commit('b', rev_id='r2')
50
57
 
51
 
        t._control_files.get_utf8('basis-inventory-cache')
 
58
        self.assertTrue(t._transport.has('basis-inventory-cache'))
52
59
 
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')
57
64
 
59
66
 
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('.')
63
76
        b = t.branch
64
77
        open('a', 'wb').write('a\n')
65
78
        t.add('a')
66
79
        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
 
 
77
 
    def test_basis_inv_gets_revision(self):
78
 
        """When the inventory of the basis tree has no revision id it gets set.
79
 
 
80
 
        It gets set during set_parent_trees() or set_parent_ids().
81
 
        """
82
 
        tree = self.make_branch_and_tree('.')
83
 
        tree.lock_write()
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,
93
 
                       timezone=None,
94
 
                       committer="Foo Bar <foo@example.com>",
95
 
                       message="Message",
96
 
                       inventory_sha1="",
97
 
                       revision_id='r1')
98
 
        rev.parent_ids = []
99
 
        tree.branch.repository.add_revision('r1', rev)
100
 
        tree.unlock()
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(),
109
 
            'revision_id="r1"')
110
 
        
 
80
        t._transport.put_bytes('basis-inventory-cache', 'booga')
 
81
        t.basis_tree()
 
82
        t._transport.put_bytes('basis-inventory-cache', '<xml/>')
 
83
        t.basis_tree()
 
84
        t._transport.put_bytes('basis-inventory-cache', '<inventory />')
 
85
        t.basis_tree()
 
86
        t._transport.put_bytes('basis-inventory-cache',
 
87
            '<inventory format="pi"/>')
 
88
        t.basis_tree()