/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/test_inv.py

  • Committer: Martin Pool
  • Date: 2007-08-21 05:29:59 UTC
  • mto: This revision was merged to the branch mainline in revision 2779.
  • Revision ID: mbp@sourcefrog.net-20070821052959-5odvyjziwyuaeo3d
Move per-inventory tests from test_inv to tests.inventory_implementations

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
 
17
18
from bzrlib import errors, inventory, osutils
18
19
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
19
20
    InventoryDirectory, InventoryEntry, TreeReference)
20
 
from bzrlib.osutils import (pathjoin
21
 
    )
22
21
from bzrlib.tests import TestCase
23
22
 
24
23
 
25
 
class TestInventory(TestCase):
26
 
 
27
 
    def test_ids(self):
28
 
        """Test detection of files within selected directories."""
29
 
        inv = Inventory()
30
 
        
31
 
        for args in [('src', 'directory', 'src-id'), 
32
 
                     ('doc', 'directory', 'doc-id'), 
33
 
                     ('src/hello.c', 'file'),
34
 
                     ('src/bye.c', 'file', 'bye-id'),
35
 
                     ('Makefile', 'file')]:
36
 
            inv.add_path(*args)
37
 
            
38
 
        self.assertEqual(inv.path2id('src'), 'src-id')
39
 
        self.assertEqual(inv.path2id('src/bye.c'), 'bye-id')
40
 
        
41
 
        self.assert_('src-id' in inv)
42
 
 
43
 
    def test_non_directory_children(self):
44
 
        """Test path2id when a parent directory has no children"""
45
 
        inv = inventory.Inventory('tree_root')
46
 
        inv.add(inventory.InventoryFile('file-id','file', 
47
 
                                        parent_id='tree_root'))
48
 
        inv.add(inventory.InventoryLink('link-id','link', 
49
 
                                        parent_id='tree_root'))
50
 
        self.assertIs(None, inv.path2id('file/subfile'))
51
 
        self.assertIs(None, inv.path2id('link/subfile'))
52
 
 
53
 
    def test_iter_entries(self):
54
 
        inv = Inventory()
55
 
        
56
 
        for args in [('src', 'directory', 'src-id'), 
57
 
                     ('doc', 'directory', 'doc-id'), 
58
 
                     ('src/hello.c', 'file', 'hello-id'),
59
 
                     ('src/bye.c', 'file', 'bye-id'),
60
 
                     ('Makefile', 'file', 'makefile-id')]:
61
 
            inv.add_path(*args)
62
 
 
63
 
        self.assertEqual([
64
 
            ('', ROOT_ID),
65
 
            ('Makefile', 'makefile-id'),
66
 
            ('doc', 'doc-id'),
67
 
            ('src', 'src-id'),
68
 
            ('src/bye.c', 'bye-id'),
69
 
            ('src/hello.c', 'hello-id'),
70
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
71
 
            
72
 
    def test_iter_entries_by_dir(self):
73
 
        inv = Inventory()
74
 
        
75
 
        for args in [('src', 'directory', 'src-id'), 
76
 
                     ('doc', 'directory', 'doc-id'), 
77
 
                     ('src/hello.c', 'file', 'hello-id'),
78
 
                     ('src/bye.c', 'file', 'bye-id'),
79
 
                     ('zz', 'file', 'zz-id'),
80
 
                     ('src/sub/', 'directory', 'sub-id'),
81
 
                     ('src/zz.c', 'file', 'zzc-id'),
82
 
                     ('src/sub/a', 'file', 'a-id'),
83
 
                     ('Makefile', 'file', 'makefile-id')]:
84
 
            inv.add_path(*args)
85
 
 
86
 
        self.assertEqual([
87
 
            ('', ROOT_ID),
88
 
            ('Makefile', 'makefile-id'),
89
 
            ('doc', 'doc-id'),
90
 
            ('src', 'src-id'),
91
 
            ('zz', 'zz-id'),
92
 
            ('src/bye.c', 'bye-id'),
93
 
            ('src/hello.c', 'hello-id'),
94
 
            ('src/sub', 'sub-id'),
95
 
            ('src/zz.c', 'zzc-id'),
96
 
            ('src/sub/a', 'a-id'),
97
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
98
 
            
99
 
        self.assertEqual([
100
 
            ('', ROOT_ID),
101
 
            ('Makefile', 'makefile-id'),
102
 
            ('doc', 'doc-id'),
103
 
            ('src', 'src-id'),
104
 
            ('zz', 'zz-id'),
105
 
            ('src/bye.c', 'bye-id'),
106
 
            ('src/hello.c', 'hello-id'),
107
 
            ('src/sub', 'sub-id'),
108
 
            ('src/zz.c', 'zzc-id'),
109
 
            ('src/sub/a', 'a-id'),
110
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
111
 
                specific_file_ids=('a-id', 'zzc-id', 'doc-id', ROOT_ID,
112
 
                'hello-id', 'bye-id', 'zz-id', 'src-id', 'makefile-id', 
113
 
                'sub-id'))])
114
 
 
115
 
        self.assertEqual([
116
 
            ('Makefile', 'makefile-id'),
117
 
            ('doc', 'doc-id'),
118
 
            ('zz', 'zz-id'),
119
 
            ('src/bye.c', 'bye-id'),
120
 
            ('src/hello.c', 'hello-id'),
121
 
            ('src/zz.c', 'zzc-id'),
122
 
            ('src/sub/a', 'a-id'),
123
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
124
 
                specific_file_ids=('a-id', 'zzc-id', 'doc-id',
125
 
                'hello-id', 'bye-id', 'zz-id', 'makefile-id'))])
126
 
 
127
 
        self.assertEqual([
128
 
            ('Makefile', 'makefile-id'),
129
 
            ('src/bye.c', 'bye-id'),
130
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
131
 
                specific_file_ids=('bye-id', 'makefile-id'))])
132
 
 
133
 
        self.assertEqual([
134
 
            ('Makefile', 'makefile-id'),
135
 
            ('src/bye.c', 'bye-id'),
136
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
137
 
                specific_file_ids=('bye-id', 'makefile-id'))])
138
 
 
139
 
        self.assertEqual([
140
 
            ('src/bye.c', 'bye-id'),
141
 
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
142
 
                specific_file_ids=('bye-id',))])
143
 
 
144
 
    def test_add_recursive(self):
145
 
        parent = InventoryDirectory('src-id', 'src', ROOT_ID)
146
 
        child = InventoryFile('hello-id', 'hello.c', 'src-id')
147
 
        parent.children[child.file_id] = child
148
 
        inv = Inventory()
149
 
        inv.add(parent)
150
 
        self.assertEqual('src/hello.c', inv.id2path('hello-id'))
151
 
 
152
 
 
153
24
class TestInventoryEntry(TestCase):
154
25
 
155
26
    def test_file_kind_character(self):
295
166
    def assertChangeDescription(self, expected_change, old_ie, new_ie):
296
167
        change = InventoryEntry.describe_change(old_ie, new_ie)
297
168
        self.assertEqual(expected_change, change)
298
 
 
299
 
 
300
 
class TestIsRoot(TestCase):
301
 
    """Ensure our root-checking code is accurate."""
302
 
 
303
 
    def test_is_root(self):
304
 
        inv = Inventory('TREE_ROOT')
305
 
        self.assertTrue(inv.is_root('TREE_ROOT'))
306
 
        self.assertFalse(inv.is_root('booga'))
307
 
        inv.root.file_id = 'booga'
308
 
        self.assertFalse(inv.is_root('TREE_ROOT'))
309
 
        self.assertTrue(inv.is_root('booga'))
310
 
        # works properly even if no root is set
311
 
        inv.root = None
312
 
        self.assertFalse(inv.is_root('TREE_ROOT'))
313
 
        self.assertFalse(inv.is_root('booga'))
314
 
 
315
 
 
316
 
class TestTreeReference(TestCase):
317
 
    
318
 
    def test_create(self):
319
 
        inv = Inventory('tree-root-123')
320
 
        inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
321
 
                              revision='rev', reference_revision='rev2'))
322
 
 
323
 
 
324
 
class TestEncoding(TestCase):
325
 
 
326
 
    def test_error_encoding(self):
327
 
        inv = Inventory('tree-root')
328
 
        inv.add(InventoryFile('a-id', u'\u1234', 'tree-root'))
329
 
        try:
330
 
            inv.add(InventoryFile('b-id', u'\u1234', 'tree-root'))
331
 
        except errors.BzrError, e:
332
 
            self.assertContainsRe(str(e), u'\u1234'.encode('utf-8'))
333
 
        else:
334
 
            self.fail('BzrError not raised')