~greatmay12/+junk/test1

« back to all changes in this revision

Viewing changes to build/lib.linux-x86_64-2.6/bzrlib/tests/per_workingtree/test_basis_inventory.py

  • Committer: thitipong at ndrsolution
  • Date: 2011-11-14 06:31:02 UTC
  • Revision ID: thitipong@ndrsolution.com-20111114063102-9obte3yfi2azku7d
ndr redirect version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2004, 2005, 2008 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
import os
 
18
 
 
19
from bzrlib.tests import TestNotApplicable
 
20
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
21
from bzrlib.branch import Branch
 
22
from bzrlib import inventory
 
23
from bzrlib.revision import Revision
 
24
import bzrlib.xml6
 
25
 
 
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.DirStateWorkingTreeFormat):
 
34
            raise TestNotApplicable("not applicable to %r"
 
35
                % (self.workingtree_format,))
 
36
        # TODO: jam 20051218 this probably should add more than just
 
37
        #                    a couple files to the inventory
 
38
 
 
39
        # Make sure the basis file is created by a commit
 
40
        t = self.make_branch_and_tree('.')
 
41
        b = t.branch
 
42
        open('a', 'wb').write('a\n')
 
43
        t.add('a')
 
44
        t.commit('a', rev_id='r1')
 
45
 
 
46
        self.assertTrue(t._transport.has('basis-inventory-cache'))
 
47
 
 
48
        basis_inv = t.basis_tree().inventory
 
49
        self.assertEquals('r1', basis_inv.revision_id)
 
50
 
 
51
        store_inv = b.repository.get_inventory('r1')
 
52
        self.assertEqual([], store_inv._make_delta(basis_inv))
 
53
 
 
54
        open('b', 'wb').write('b\n')
 
55
        t.add('b')
 
56
        t.commit('b', rev_id='r2')
 
57
 
 
58
        self.assertTrue(t._transport.has('basis-inventory-cache'))
 
59
 
 
60
        basis_inv_txt = t.read_basis_inventory()
 
61
        basis_inv = bzrlib.xml7.serializer_v7.read_inventory_from_string(basis_inv_txt)
 
62
        self.assertEquals('r2', basis_inv.revision_id)
 
63
        store_inv = b.repository.get_inventory('r2')
 
64
 
 
65
        self.assertEqual([], store_inv._make_delta(basis_inv))
 
66
 
 
67
    def test_wrong_format(self):
 
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.DirStateWorkingTreeFormat):
 
73
            raise TestNotApplicable("not applicable to %r"
 
74
                % (self.workingtree_format,))
 
75
        t = self.make_branch_and_tree('.')
 
76
        b = t.branch
 
77
        open('a', 'wb').write('a\n')
 
78
        t.add('a')
 
79
        t.commit('a', rev_id='r1')
 
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()