~mbp/bzr/doc-old

« back to all changes in this revision

Viewing changes to bzrlib/tests/inventory_implementations/basics.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-12 10:40:01 UTC
  • mfrom: (4127.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090312104001-k2722d61gjdpb91v
check for duplicate file-ids in Inventory.apply_delta (Ian Clatworthy)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        )
38
38
 
39
39
 
40
 
class TestInventoryBasics(TestCase):
41
 
    # Most of these were moved the rather old bzrlib.tests.test_inv module
 
40
class TestInventory(TestCase):
42
41
 
43
42
    def make_inventory(self, root_id):
44
43
        return self.inventory_class(root_id=root_id)
45
44
 
 
45
 
 
46
class TestInventoryUpdates(TestInventory):
 
47
 
46
48
    def test_creation_from_root_id(self):
47
49
        # iff a root id is passed to the constructor, a root directory is made
48
50
        inv = self.make_inventory(root_id='tree-root')
88
90
        self.assertEquals('someroot', inv2.root.file_id)
89
91
        self.assertEquals('therev', inv2.root.revision)
90
92
 
91
 
    def test_is_root(self):
92
 
        """Ensure our root-checking code is accurate."""
93
 
        inv = self.make_inventory('TREE_ROOT')
94
 
        self.assertTrue(inv.is_root('TREE_ROOT'))
95
 
        self.assertFalse(inv.is_root('booga'))
96
 
        inv.root.file_id = 'booga'
97
 
        self.assertFalse(inv.is_root('TREE_ROOT'))
98
 
        self.assertTrue(inv.is_root('booga'))
99
 
        # works properly even if no root is set
100
 
        inv.root = None
101
 
        self.assertFalse(inv.is_root('TREE_ROOT'))
102
 
        self.assertFalse(inv.is_root('booga'))
103
 
 
104
93
    def test_create_tree_reference(self):
105
94
        inv = self.make_inventory('tree-root-123')
106
95
        inv.add(TreeReference('nested-id', 'nested', parent_id='tree-root-123',
116
105
        else:
117
106
            self.fail('BzrError not raised')
118
107
 
 
108
    def test_add_recursive(self):
 
109
        parent = InventoryDirectory('src-id', 'src', 'tree-root')
 
110
        child = InventoryFile('hello-id', 'hello.c', 'src-id')
 
111
        parent.children[child.file_id] = child
 
112
        inv = self.make_inventory('tree-root')
 
113
        inv.add(parent)
 
114
        self.assertEqual('src/hello.c', inv.id2path('hello-id'))
 
115
 
 
116
 
 
117
class TestInventoryApplyDelta(TestInventory):
 
118
 
 
119
    def test_apply_delta_add(self):
 
120
        inv = self.make_inventory('tree-root')
 
121
        inv.apply_delta([
 
122
            (None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
 
123
            ])
 
124
        self.assertEqual('a', inv.id2path('a-id'))
 
125
 
 
126
    def test_apply_delta_delete(self):
 
127
        inv = self.make_inventory('tree-root')
 
128
        inv.apply_delta([
 
129
            (None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
 
130
            ])
 
131
        self.assertEqual('a', inv.id2path('a-id'))
 
132
        a_ie = inv['a-id']
 
133
        inv.apply_delta([("a", None, "a-id", a_ie)])
 
134
        self.assertRaises(errors.NoSuchId, inv.id2path, 'a-id')
 
135
 
 
136
    def test_apply_delta_rename(self):
 
137
        inv = self.make_inventory('tree-root')
 
138
        inv.apply_delta([
 
139
            (None, "a", "a-id", InventoryFile('a-id', 'a', 'tree-root')),
 
140
            ])
 
141
        self.assertEqual('a', inv.id2path('a-id'))
 
142
        a_ie = inv['a-id']
 
143
        b_ie = InventoryFile(a_ie.file_id, "b", a_ie.parent_id)
 
144
        inv.apply_delta([("a", "b", "a-id", b_ie)])
 
145
        self.assertEqual("b", inv.id2path('a-id'))
 
146
 
 
147
    def test_apply_delta_illegal(self):
 
148
        # A file-id cannot appear in a delta more than once
 
149
        inv = self.make_inventory('tree-root')
 
150
        self.assertRaises(AssertionError, inv.apply_delta, [
 
151
            ("a", "a", "id-1", InventoryFile('id-1', 'a', 'tree-root')),
 
152
            ("a", "b", "id-1", InventoryFile('id-1', 'b', 'tree-root')),
 
153
            ])
 
154
 
 
155
 
 
156
class TestInventoryReads(TestInventory):
 
157
 
 
158
    def test_is_root(self):
 
159
        """Ensure our root-checking code is accurate."""
 
160
        inv = self.make_inventory('TREE_ROOT')
 
161
        self.assertTrue(inv.is_root('TREE_ROOT'))
 
162
        self.assertFalse(inv.is_root('booga'))
 
163
        inv.root.file_id = 'booga'
 
164
        self.assertFalse(inv.is_root('TREE_ROOT'))
 
165
        self.assertTrue(inv.is_root('booga'))
 
166
        # works properly even if no root is set
 
167
        inv.root = None
 
168
        self.assertFalse(inv.is_root('TREE_ROOT'))
 
169
        self.assertFalse(inv.is_root('booga'))
 
170
 
119
171
    def test_ids(self):
120
172
        """Test detection of files within selected directories."""
121
173
        inv = self.make_inventory(ROOT_ID)
231
283
            ('src/bye.c', 'bye-id'),
232
284
            ], [(path, ie.file_id) for path, ie in inv.iter_entries_by_dir(
233
285
                specific_file_ids=('bye-id',), yield_parents=True)])
234
 
 
235
 
    def test_add_recursive(self):
236
 
        parent = InventoryDirectory('src-id', 'src', 'tree-root')
237
 
        child = InventoryFile('hello-id', 'hello.c', 'src-id')
238
 
        parent.children[child.file_id] = child
239
 
        inv = self.make_inventory('tree-root')
240
 
        inv.add(parent)
241
 
        self.assertEqual('src/hello.c', inv.id2path('hello-id'))