~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-20 03:30:14 UTC
  • mfrom: (1793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mbp@sourcefrog.net-20060620033014-e19ce470e2ce6561
[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()
79
94
            ('src/hello.c', 'hello-id'),
80
95
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
81
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
            
82
123
    def test_version(self):
83
124
        """Inventory remembers the text's version."""
84
125
        inv = Inventory()
196
237
                          "old_label", self.tree_1,
197
238
                          "/dev/null", None, None,
198
239
                          output)
199
 
        self.assertEqual(output.getvalue(), "--- old_label\t\n"
200
 
                                            "+++ /dev/null\t\n"
 
240
        self.assertEqual(output.getvalue(), "--- old_label\n"
 
241
                                            "+++ /dev/null\n"
201
242
                                            "@@ -1,1 +0,0 @@\n"
202
243
                                            "-foo\n"
203
244
                                            "\n")
208
249
                          "new_label", self.tree_1,
209
250
                          "/dev/null", None, None,
210
251
                          output, reverse=True)
211
 
        self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
212
 
                                            "+++ new_label\t\n"
 
252
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
253
                                            "+++ new_label\n"
213
254
                                            "@@ -0,0 +1,1 @@\n"
214
255
                                            "+foo\n"
215
256
                                            "\n")
220
261
                          "/dev/null", self.tree_1, 
221
262
                          "new_label", self.file_2, self.tree_2,
222
263
                          output)
223
 
        self.assertEqual(output.getvalue(), "--- /dev/null\t\n"
224
 
                                            "+++ new_label\t\n"
 
264
        self.assertEqual(output.getvalue(), "--- /dev/null\n"
 
265
                                            "+++ new_label\n"
225
266
                                            "@@ -1,1 +1,1 @@\n"
226
267
                                            "-foo\n"
227
268
                                            "+bar\n"
291
332
        self.inv_1 = self.branch.repository.get_inventory('1')
292
333
        self.file_1 = self.inv_1['fileid']
293
334
        self.file_active = self.wt.inventory['fileid']
 
335
        self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
294
336
 
295
337
    def test_snapshot_new_revision(self):
296
338
        # This tests that a simple commit with no parents makes a new
297
339
        # revision value in the inventory entry
298
 
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, 
299
 
                                  self.branch.repository.weave_store,
300
 
                                  self.branch.get_transaction())
 
340
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
301
341
        # expected outcome - file_1 has a revision id of '2', and we can get
302
342
        # its text of 'file contents' out of the weave.
303
343
        self.assertEqual(self.file_1.revision, '1')
312
352
        #This tests that a simple commit does not make a new entry for
313
353
        # an unchanged inventory entry
314
354
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
315
 
                                  self.wt, 
316
 
                                  self.branch.repository.weave_store,
317
 
                                  self.branch.get_transaction())
 
355
                                  self.wt, self.builder)
318
356
        self.assertEqual(self.file_1.revision, '1')
319
357
        self.assertEqual(self.file_active.revision, '1')
320
358
        vf = self.branch.repository.weave_store.get_weave(
341
379
        versionfile.clone_text('other', '1', ['1'])
342
380
        self.file_active.snapshot('2', 'subdir/file', 
343
381
                                  {'1':self.file_1, 'other':other_ie},
344
 
                                  self.wt, 
345
 
                                  self.branch.repository.weave_store,
346
 
                                  self.branch.get_transaction())
 
382
                                  self.wt, self.builder)
347
383
        self.assertEqual(self.file_active.revision, '2')
348
384
 
349
385
    def test_snapshot_changed(self):
352
388
        self.file_active.name='newname'
353
389
        rename('subdir/file', 'subdir/newname')
354
390
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
355
 
                                  self.wt,
356
 
                                  self.branch.repository.weave_store,
357
 
                                  self.branch.get_transaction())
 
391
                                  self.wt, self.builder)
358
392
        # expected outcome - file_1 has a revision id of '2'
359
393
        self.assertEqual(self.file_active.revision, '2')
360
394