~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

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 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
26
26
class TestBasisInventory(TestCaseWithWorkingTree):
27
27
 
28
28
    def test_create(self):
 
29
        # This test is not applicable to DirState based trees: the basis is
 
30
        # not separate is mandatory.
 
31
        if isinstance(self.workingtree_format,
 
32
            bzrlib.workingtree_4.WorkingTreeFormat4):
 
33
            return
29
34
        # TODO: jam 20051218 this probably should add more than just
30
35
        #                    a couple files to the inventory
31
36
 
51
56
        t._control_files.get_utf8('basis-inventory-cache')
52
57
 
53
58
        basis_inv_txt = t.read_basis_inventory()
54
 
        basis_inv = bzrlib.xml6.serializer_v6.read_inventory_from_string(basis_inv_txt)
 
59
        basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
55
60
        self.assertEquals('r2', basis_inv.revision_id)
56
61
        store_inv = b.repository.get_inventory('r2')
57
62
 
59
64
 
60
65
    def test_wrong_format(self):
61
66
        """WorkingTree.basis safely ignores junk basis inventories"""
 
67
        # This test is not applicable to DirState based trees: the basis is
 
68
        # not separate and ignorable.
 
69
        if isinstance(self.workingtree_format,
 
70
            bzrlib.workingtree_4.WorkingTreeFormat4):
 
71
            return
62
72
        t = self.make_branch_and_tree('.')
63
73
        b = t.branch
64
74
        open('a', 'wb').write('a\n')
73
83
        t._control_files.put_utf8('basis-inventory-cache', 
74
84
                                  '<inventory format="pi"/>')
75
85
        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