/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

MergeĀ upstream.

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
 
209
223
            ], [(path, ie.file_id) for path, ie in inv.iter_entries()])
210
224
 
211
225
    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)
 
226
        inv = self. prepare_inv_with_nested_dirs()
223
227
        self.assertEqual([
224
228
            ('', 'tree-root'),
225
229
            ('Makefile', 'makefile-id'),
283
287
            ('src/bye.c', 'bye-id'),
284
288
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
285
289
                specific_file_ids=('bye-id',), yield_parents=True)])
 
290
 
 
291
 
 
292
class TestInventoryFiltering(TestInventory):
 
293
 
 
294
    def test_inv_filter_empty(self):
 
295
        inv = self.prepare_inv_with_nested_dirs()
 
296
        new_inv = inv.filter([])
 
297
        self.assertEqual([
 
298
            ('', 'tree-root'),
 
299
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
300
    
 
301
    def test_inv_filter_files(self):
 
302
        inv = self.prepare_inv_with_nested_dirs()
 
303
        new_inv = inv.filter(['zz-id', 'hello-id', 'a-id'])
 
304
        self.assertEqual([
 
305
            ('', 'tree-root'),
 
306
            ('src', 'src-id'),
 
307
            ('src/hello.c', 'hello-id'),
 
308
            ('src/sub', 'sub-id'),
 
309
            ('src/sub/a', 'a-id'),
 
310
            ('zz', 'zz-id'),
 
311
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
312
    
 
313
    def test_inv_filter_dirs(self):
 
314
        inv = self.prepare_inv_with_nested_dirs()
 
315
        new_inv = inv.filter(['doc-id', 'sub-id'])
 
316
        self.assertEqual([
 
317
            ('', 'tree-root'),
 
318
            ('doc', 'doc-id'),
 
319
            ('src', 'src-id'),
 
320
            ('src/sub', 'sub-id'),
 
321
            ('src/sub/a', 'a-id'),
 
322
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])
 
323
 
 
324
    def test_inv_filter_files_and_dirs(self):
 
325
        inv = self.prepare_inv_with_nested_dirs()
 
326
        new_inv = inv.filter(['makefile-id', 'src-id'])
 
327
        self.assertEqual([
 
328
            ('', 'tree-root'),
 
329
            ('Makefile', 'makefile-id'),
 
330
            ('src', 'src-id'),
 
331
            ('src/bye.c', 'bye-id'),
 
332
            ('src/hello.c', 'hello-id'),
 
333
            ('src/sub', 'sub-id'),
 
334
            ('src/sub/a', 'a-id'),
 
335
            ('src/zz.c', 'zzc-id'),
 
336
            ], [(path, ie.file_id) for path, ie in new_inv.iter_entries()])