/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/inventory_implementations/basics.py

  • Committer: Robert Collins
  • Date: 2009-05-23 20:57:12 UTC
  • mfrom: (4371 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4441.
  • Revision ID: robertc@robertcollins.net-20090523205712-lcwbfqk6vwavinuv
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for different inventory implementations"""
18
18
 
42
42
    def make_inventory(self, root_id):
43
43
        return self.inventory_class(root_id=root_id)
44
44
 
 
45
    def prepare_inv_with_nested_dirs(self):
 
46
        inv = self.make_inventory('tree-root')
 
47
        for args in [('src', 'directory', 'src-id'),
 
48
                     ('doc', 'directory', 'doc-id'),
 
49
                     ('src/hello.c', 'file', 'hello-id'),
 
50
                     ('src/bye.c', 'file', 'bye-id'),
 
51
                     ('zz', 'file', 'zz-id'),
 
52
                     ('src/sub/', 'directory', 'sub-id'),
 
53
                     ('src/zz.c', 'file', 'zzc-id'),
 
54
                     ('src/sub/a', 'file', 'a-id'),
 
55
                     ('Makefile', 'file', 'makefile-id')]:
 
56
            inv.add_path(*args)
 
57
        return inv
 
58
 
45
59
 
46
60
class TestInventoryUpdates(TestInventory):
47
61
 
208
222
            ('src/hello.c', 'hello-id'),
209
223
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
210
224
 
 
225
    def test_iter_just_entries(self):
 
226
        inv = self.make_inventory('tree-root')
 
227
        for args in [('src', 'directory', 'src-id'),
 
228
                     ('doc', 'directory', 'doc-id'),
 
229
                     ('src/hello.c', 'file', 'hello-id'),
 
230
                     ('src/bye.c', 'file', 'bye-id'),
 
231
                     ('Makefile', 'file', 'makefile-id')]:
 
232
            inv.add_path(*args)
 
233
        self.assertEqual([
 
234
            'bye-id',
 
235
            'doc-id',
 
236
            'hello-id',
 
237
            'makefile-id',
 
238
            'src-id',
 
239
            'tree-root',
 
240
            ], sorted([ie.file_id for ie in inv.iter_just_entries()]))
 
241
 
211
242
    def test_iter_entries_by_dir(self):
212
 
        inv = self.make_inventory('tree-root')
213
 
        for args in [('src', 'directory', 'src-id'),
214
 
                     ('doc', 'directory', 'doc-id'),
215
 
                     ('src/hello.c', 'file', 'hello-id'),
216
 
                     ('src/bye.c', 'file', 'bye-id'),
217
 
                     ('zz', 'file', 'zz-id'),
218
 
                     ('src/sub/', 'directory', 'sub-id'),
219
 
                     ('src/zz.c', 'file', 'zzc-id'),
220
 
                     ('src/sub/a', 'file', 'a-id'),
221
 
                     ('Makefile', 'file', 'makefile-id')]:
222
 
            inv.add_path(*args)
 
243
        inv = self. prepare_inv_with_nested_dirs()
223
244
        self.assertEqual([
224
245
            ('', 'tree-root'),
225
246
            ('Makefile', 'makefile-id'),
283
304
            ('src/bye.c', 'bye-id'),
284
305
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
285
306
                specific_file_ids=('bye-id',), yield_parents=True)])
 
307
 
 
308
 
 
309
class TestInventoryFiltering(TestInventory):
 
310
 
 
311
    def test_inv_filter_empty(self):
 
312
        inv = self.prepare_inv_with_nested_dirs()
 
313
        new_inv = inv.filter([])
 
314
        self.assertEqual([
 
315
            ('', 'tree-root'),
 
316
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
317
    
 
318
    def test_inv_filter_files(self):
 
319
        inv = self.prepare_inv_with_nested_dirs()
 
320
        new_inv = inv.filter(['zz-id', 'hello-id', 'a-id'])
 
321
        self.assertEqual([
 
322
            ('', 'tree-root'),
 
323
            ('src', 'src-id'),
 
324
            ('src/hello.c', 'hello-id'),
 
325
            ('src/sub', 'sub-id'),
 
326
            ('src/sub/a', 'a-id'),
 
327
            ('zz', 'zz-id'),
 
328
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
329
    
 
330
    def test_inv_filter_dirs(self):
 
331
        inv = self.prepare_inv_with_nested_dirs()
 
332
        new_inv = inv.filter(['doc-id', 'sub-id'])
 
333
        self.assertEqual([
 
334
            ('', 'tree-root'),
 
335
            ('doc', 'doc-id'),
 
336
            ('src', 'src-id'),
 
337
            ('src/sub', 'sub-id'),
 
338
            ('src/sub/a', 'a-id'),
 
339
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
340
 
 
341
    def test_inv_filter_files_and_dirs(self):
 
342
        inv = self.prepare_inv_with_nested_dirs()
 
343
        new_inv = inv.filter(['makefile-id', 'src-id'])
 
344
        self.assertEqual([
 
345
            ('', 'tree-root'),
 
346
            ('Makefile', 'makefile-id'),
 
347
            ('src', 'src-id'),
 
348
            ('src/bye.c', 'bye-id'),
 
349
            ('src/hello.c', 'hello-id'),
 
350
            ('src/sub', 'sub-id'),
 
351
            ('src/sub/a', 'a-id'),
 
352
            ('src/zz.c', 'zzc-id'),
 
353
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])