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)
35
43
def test_is_within(self):
37
45
SRC_FOO_C = pathjoin('src', 'foo.c')
76
84
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'))
78
96
def test_iter_entries(self):
121
139
('src/sub/a', 'a-id'),
122
140
], [(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',))])
124
187
def test_version(self):
125
188
"""Inventory remembers the text's version."""
126
189
inv = Inventory()
434
497
self.assertEqual(self.branch.revision_history(), ['A'])
435
498
self.wt.commit('another add of file', rev_id='C')
436
499
self.inv_C = self.branch.repository.get_inventory('C')
437
self.wt.add_pending_merge('B')
500
self.wt.add_parent_tree_id('B')
438
501
self.wt.commit('merge in B', rev_id='D')
439
502
self.inv_D = self.branch.repository.get_inventory('D')
440
503
self.file_active = self.wt.inventory['fileid']
544
607
os.unlink('b1/a')
546
609
self.assertEqual(len(wt.inventory), 1)
612
class TestIsRoot(TestCase):
613
"""Ensure our root-checking code is accurate."""
615
def test_is_root(self):
616
inv = Inventory('TREE_ROOT')
617
self.assertTrue(inv.is_root('TREE_ROOT'))
618
self.assertFalse(inv.is_root('booga'))
619
inv.root.file_id = 'booga'
620
self.assertFalse(inv.is_root('TREE_ROOT'))
621
self.assertTrue(inv.is_root('booga'))
622
# works properly even if no root is set
624
self.assertFalse(inv.is_root('TREE_ROOT'))
625
self.assertFalse(inv.is_root('booga'))