~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inv.py

  • Committer: Martin Pool
  • Date: 2006-06-10 23:16:19 UTC
  • mfrom: (1759 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1761.
  • Revision ID: mbp@sourcefrog.net-20060610231619-05b997deeb005d02
[merge] bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from cStringIO import StringIO
18
18
import os
 
19
import time
19
20
 
20
21
from bzrlib.branch import Branch
21
22
import bzrlib.errors as errors
23
24
from bzrlib.inventory import (Inventory, ROOT_ID, InventoryFile,
24
25
    InventoryDirectory, InventoryEntry)
25
26
import bzrlib.inventory as inventory
26
 
from bzrlib.osutils import has_symlinks, rename, pathjoin
 
27
from bzrlib.osutils import (has_symlinks, rename, pathjoin, is_inside_any, 
 
28
    is_inside_or_parent_of_any)
27
29
from bzrlib.tests import TestCase, TestCaseWithTransport
28
30
from bzrlib.transform import TreeTransform
29
31
from bzrlib.uncommit import uncommit
32
34
class TestInventory(TestCase):
33
35
 
34
36
    def test_is_within(self):
35
 
        from bzrlib.osutils import is_inside_any
36
37
 
37
38
        SRC_FOO_C = pathjoin('src', 'foo.c')
38
39
        for dirs, fn in [(['src', 'doc'], SRC_FOO_C),
44
45
        for dirs, fn in [(['src'], 'srccontrol'),
45
46
                         (['src'], 'srccontrol/foo')]:
46
47
            self.assertFalse(is_inside_any(dirs, fn))
 
48
 
 
49
    def test_is_within_or_parent(self):
 
50
        for dirs, fn in [(['src', 'doc'], 'src/foo.c'),
 
51
                         (['src'], 'src/foo.c'),
 
52
                         (['src/bar.c'], 'src'),
 
53
                         (['src/bar.c', 'bla/foo.c'], 'src'),
 
54
                         (['src'], 'src'),
 
55
                         ]:
 
56
            self.assert_(is_inside_or_parent_of_any(dirs, fn))
47
57
            
 
58
        for dirs, fn in [(['src'], 'srccontrol'),
 
59
                         (['srccontrol/foo.c'], 'src'),
 
60
                         (['src'], 'srccontrol/foo')]:
 
61
            self.assertFalse(is_inside_or_parent_of_any(dirs, fn))
 
62
 
48
63
    def test_ids(self):
49
64
        """Test detection of files within selected directories."""
50
65
        inv = Inventory()
61
76
        
62
77
        self.assert_('src-id' in inv)
63
78
 
 
79
    def test_iter_entries(self):
 
80
        inv = Inventory()
 
81
        
 
82
        for args in [('src', 'directory', 'src-id'), 
 
83
                     ('doc', 'directory', 'doc-id'), 
 
84
                     ('src/hello.c', 'file', 'hello-id'),
 
85
                     ('src/bye.c', 'file', 'bye-id'),
 
86
                     ('Makefile', 'file', 'makefile-id')]:
 
87
            inv.add_path(*args)
 
88
 
 
89
        self.assertEqual([
 
90
            ('Makefile', 'makefile-id'),
 
91
            ('doc', 'doc-id'),
 
92
            ('src', 'src-id'),
 
93
            ('src/bye.c', 'bye-id'),
 
94
            ('src/hello.c', 'hello-id'),
 
95
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
 
96
            
 
97
    def test_iter_entries_by_dir(self):
 
98
        inv = Inventory()
 
99
        
 
100
        for args in [('src', 'directory', 'src-id'), 
 
101
                     ('doc', 'directory', 'doc-id'), 
 
102
                     ('src/hello.c', 'file', 'hello-id'),
 
103
                     ('src/bye.c', 'file', 'bye-id'),
 
104
                     ('zz', 'file', 'zz-id'),
 
105
                     ('src/sub/', 'directory', 'sub-id'),
 
106
                     ('src/zz.c', 'file', 'zzc-id'),
 
107
                     ('src/sub/a', 'file', 'a-id'),
 
108
                     ('Makefile', 'file', 'makefile-id')]:
 
109
            inv.add_path(*args)
 
110
 
 
111
        self.assertEqual([
 
112
            ('Makefile', 'makefile-id'),
 
113
            ('doc', 'doc-id'),
 
114
            ('src', 'src-id'),
 
115
            ('zz', 'zz-id'),
 
116
            ('src/bye.c', 'bye-id'),
 
117
            ('src/hello.c', 'hello-id'),
 
118
            ('src/sub', 'sub-id'),
 
119
            ('src/zz.c', 'zzc-id'),
 
120
            ('src/sub/a', 'a-id'),
 
121
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
 
122
            
64
123
    def test_version(self):
65
124
        """Inventory remembers the text's version."""
66
125
        inv = Inventory()
178
237
                          "old_label", self.tree_1,
179
238
                          "/dev/null", None, None,
180
239
                          output)
181
 
        self.assertEqual(output.getvalue(), "--- old_label\t\n"
182
 
                                            "+++ /dev/null\t\n"
 
240
        self.assertEqual(output.getvalue(), "--- old_label\n"
 
241
                                            "+++ /dev/null\n"
183
242
                                            "@@ -1,1 +0,0 @@\n"
184
243
                                            "-foo\n"
185
244
                                            "\n")
190
249
                          "new_label", self.tree_1,
191
250
                          "/dev/null", None, None,
192
251
                          output, reverse=True)
193
 
        self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
194
 
                                            "+++ new_label\t\n"
 
252
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
253
                                            "+++ new_label\n"
195
254
                                            "@@ -0,0 +1,1 @@\n"
196
255
                                            "+foo\n"
197
256
                                            "\n")
202
261
                          "/dev/null", self.tree_1, 
203
262
                          "new_label", self.file_2, self.tree_2,
204
263
                          output)
205
 
        self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
206
 
                                            "+++ new_label\t\n"
 
264
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
265
                                            "+++ new_label\n"
207
266
                                            "@@ -1,1 +1,1 @@\n"
208
267
                                            "-foo\n"
209
268
                                            "+bar\n"
273
332
        self.inv_1 = self.branch.repository.get_inventory('1')
274
333
        self.file_1 = self.inv_1['fileid']
275
334
        self.file_active = self.wt.inventory['fileid']
 
335
        self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
276
336
 
277
337
    def test_snapshot_new_revision(self):
278
338
        # This tests that a simple commit with no parents makes a new
279
339
        # revision value in the inventory entry
280
 
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, 
281
 
                                  self.branch.repository.weave_store,
282
 
                                  self.branch.get_transaction())
 
340
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
283
341
        # expected outcome - file_1 has a revision id of '2', and we can get
284
342
        # its text of 'file contents' out of the weave.
285
343
        self.assertEqual(self.file_1.revision, '1')
294
352
        #This tests that a simple commit does not make a new entry for
295
353
        # an unchanged inventory entry
296
354
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
297
 
                                  self.wt, 
298
 
                                  self.branch.repository.weave_store,
299
 
                                  self.branch.get_transaction())
 
355
                                  self.wt, self.builder)
300
356
        self.assertEqual(self.file_1.revision, '1')
301
357
        self.assertEqual(self.file_active.revision, '1')
302
358
        vf = self.branch.repository.weave_store.get_weave(
323
379
        versionfile.clone_text('other', '1', ['1'])
324
380
        self.file_active.snapshot('2', 'subdir/file', 
325
381
                                  {'1':self.file_1, 'other':other_ie},
326
 
                                  self.wt, 
327
 
                                  self.branch.repository.weave_store,
328
 
                                  self.branch.get_transaction())
 
382
                                  self.wt, self.builder)
329
383
        self.assertEqual(self.file_active.revision, '2')
330
384
 
331
385
    def test_snapshot_changed(self):
334
388
        self.file_active.name='newname'
335
389
        rename('subdir/file', 'subdir/newname')
336
390
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
337
 
                                  self.wt,
338
 
                                  self.branch.repository.weave_store,
339
 
                                  self.branch.get_transaction())
 
391
                                  self.wt, self.builder)
340
392
        # expected outcome - file_1 has a revision id of '2'
341
393
        self.assertEqual(self.file_active.revision, '2')
342
394