1
# Copyright (C) 2005, 2006 Canonical Ltd
1
# Copyright (C) 2005, 2006 by Canonical Ltd
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
33
33
class TestInventory(TestCase):
35
def test_add_path(self):
37
inv = Inventory(root_id=None)
38
self.assertIs(None, inv.root)
39
ie = inv.add_path("", "directory", "my-root")
40
self.assertEqual("my-root", ie.file_id)
41
self.assertIs(ie, inv.root)
43
35
def test_is_within(self):
45
37
SRC_FOO_C = pathjoin('src', 'foo.c')
84
76
self.assert_('src-id' in inv)
86
def test_non_directory_children(self):
87
"""Test path2id when a parent directory has no children"""
88
inv = inventory.Inventory('tree_root')
89
inv.add(inventory.InventoryFile('file-id','file',
90
parent_id='tree_root'))
91
inv.add(inventory.InventoryLink('link-id','link',
92
parent_id='tree_root'))
93
self.assertIs(None, inv.path2id('file/subfile'))
94
self.assertIs(None, inv.path2id('link/subfile'))
96
78
def test_iter_entries(self):
139
121
('src/sub/a', 'a-id'),
140
122
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir()])
144
('Makefile', 'makefile-id'),
148
('src/bye.c', 'bye-id'),
149
('src/hello.c', 'hello-id'),
150
('src/sub', 'sub-id'),
151
('src/zz.c', 'zzc-id'),
152
('src/sub/a', 'a-id'),
153
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
154
specific_file_ids=('a-id', 'zzc-id', 'doc-id', ROOT_ID,
155
'hello-id', 'bye-id', 'zz-id', 'src-id', 'makefile-id',
159
('Makefile', 'makefile-id'),
162
('src/bye.c', 'bye-id'),
163
('src/hello.c', 'hello-id'),
164
('src/zz.c', 'zzc-id'),
165
('src/sub/a', 'a-id'),
166
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
167
specific_file_ids=('a-id', 'zzc-id', 'doc-id',
168
'hello-id', 'bye-id', 'zz-id', 'makefile-id'))])
171
('Makefile', 'makefile-id'),
172
('src/bye.c', 'bye-id'),
173
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
174
specific_file_ids=('bye-id', 'makefile-id'))])
177
('Makefile', 'makefile-id'),
178
('src/bye.c', 'bye-id'),
179
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
180
specific_file_ids=('bye-id', 'makefile-id'))])
183
('src/bye.c', 'bye-id'),
184
], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
185
specific_file_ids=('bye-id',))])
187
124
def test_version(self):
188
125
"""Inventory remembers the text's version."""
189
126
inv = Inventory()
411
348
self.tree_1 = self.branch.repository.revision_tree('1')
412
349
self.inv_1 = self.branch.repository.get_inventory('1')
413
350
self.file_1 = self.inv_1['fileid']
415
self.addCleanup(self.wt.unlock)
416
351
self.file_active = self.wt.inventory['fileid']
417
352
self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
467
402
def test_snapshot_changed(self):
468
403
# This tests that a commit with one different parent results in a new
469
404
# revision id in the entry.
470
self.wt.rename_one('subdir/file', 'subdir/newname')
471
self.file_active = self.wt.inventory['fileid']
405
self.file_active.name='newname'
406
rename('subdir/file', 'subdir/newname')
472
407
self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1},
473
408
self.wt, self.builder)
474
409
# expected outcome - file_1 has a revision id of '2'
609
544
os.unlink('b1/a')
611
546
self.assertEqual(len(wt.inventory), 1)
614
class TestIsRoot(TestCase):
615
"""Ensure our root-checking code is accurate."""
617
def test_is_root(self):
618
inv = Inventory('TREE_ROOT')
619
self.assertTrue(inv.is_root('TREE_ROOT'))
620
self.assertFalse(inv.is_root('booga'))
621
inv.root.file_id = 'booga'
622
self.assertFalse(inv.is_root('TREE_ROOT'))
623
self.assertTrue(inv.is_root('booga'))
624
# works properly even if no root is set
626
self.assertFalse(inv.is_root('TREE_ROOT'))
627
self.assertFalse(inv.is_root('booga'))