~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_inventory_delta.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-13 00:20:29 UTC
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090813002029-akc5x2mtxa8rq068
Raise InventoryDeltaErrors, not generic BzrErrors, from inventory_delta.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    inventory,
27
27
    inventory_delta,
28
28
    )
 
29
from bzrlib.inventory_delta import InventoryDeltaError
29
30
from bzrlib.inventory import Inventory
30
31
from bzrlib.revision import NULL_REVISION
31
32
from bzrlib.tests import TestCase
95
96
    def test_parse_no_bytes(self):
96
97
        deserializer = inventory_delta.InventoryDeltaDeserializer()
97
98
        err = self.assertRaises(
98
 
            errors.BzrError, deserializer.parse_text_bytes, '')
 
99
            InventoryDeltaError, deserializer.parse_text_bytes, '')
99
100
        self.assertContainsRe(str(err), 'last line not empty')
100
101
 
101
102
    def test_parse_bad_format(self):
102
103
        deserializer = inventory_delta.InventoryDeltaDeserializer()
103
 
        err = self.assertRaises(errors.BzrError,
 
104
        err = self.assertRaises(InventoryDeltaError,
104
105
            deserializer.parse_text_bytes, 'format: foo\n')
105
106
        self.assertContainsRe(str(err), 'unknown format')
106
107
 
107
108
    def test_parse_no_parent(self):
108
109
        deserializer = inventory_delta.InventoryDeltaDeserializer()
109
 
        err = self.assertRaises(errors.BzrError,
 
110
        err = self.assertRaises(InventoryDeltaError,
110
111
            deserializer.parse_text_bytes,
111
112
            'format: bzr inventory delta v1 (bzr 1.14)\n')
112
113
        self.assertContainsRe(str(err), 'missing parent: marker')
113
114
 
114
115
    def test_parse_no_version(self):
115
116
        deserializer = inventory_delta.InventoryDeltaDeserializer()
116
 
        err = self.assertRaises(errors.BzrError,
 
117
        err = self.assertRaises(InventoryDeltaError,
117
118
            deserializer.parse_text_bytes,
118
119
            'format: bzr inventory delta v1 (bzr 1.14)\n'
119
120
            'parent: null:\n')
130
131
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
131
132
None\x00/\x00an-id\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
132
133
"""
133
 
        err = self.assertRaises(errors.BzrError,
 
134
        err = self.assertRaises(InventoryDeltaError,
134
135
            deserializer.parse_text_bytes, double_root_lines)
135
136
        self.assertContainsRe(str(err), 'duplicate file id')
136
137
 
154
155
tree_references: true
155
156
None\x00/\x00TREE_ROOT\x00\x00null:\x00dir\x00\x00
156
157
"""
157
 
        err = self.assertRaises(errors.BzrError,
 
158
        err = self.assertRaises(InventoryDeltaError,
158
159
            deserializer.parse_text_bytes, root_only_lines)
159
160
        self.assertContainsRe(str(err), 'special revisionid found')
160
161
 
167
168
tree_references: true
168
169
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir\x00\x00
169
170
"""
170
 
        err = self.assertRaises(errors.BzrError,
 
171
        err = self.assertRaises(InventoryDeltaError,
171
172
            deserializer.parse_text_bytes, root_only_lines)
172
173
        self.assertContainsRe(str(err), 'Versioned root found')
173
174
 
180
181
tree_references: true
181
182
None\x00/\x00an-id\x00\x00parent-id\x00dir\x00\x00
182
183
"""
183
 
        err = self.assertRaises(errors.BzrError,
 
184
        err = self.assertRaises(InventoryDeltaError,
184
185
            deserializer.parse_text_bytes, root_only_lines)
185
186
        self.assertContainsRe(str(err), 'Versioned root found')
186
187
 
198
199
    def test_parse_versioned_root_when_disabled(self):
199
200
        deserializer = inventory_delta.InventoryDeltaDeserializer(
200
201
            allow_versioned_root=False)
201
 
        err = self.assertRaises(inventory_delta._IncompatibleDelta,
 
202
        err = self.assertRaises(inventory_delta.IncompatibleInventoryDelta,
202
203
            deserializer.parse_text_bytes, root_only_lines)
203
204
        self.assertEquals("versioned_root not allowed", str(err))
204
205
 
205
206
    def test_parse_tree_when_disabled(self):
206
207
        deserializer = inventory_delta.InventoryDeltaDeserializer(
207
208
            allow_tree_references=False)
208
 
        err = self.assertRaises(inventory_delta._IncompatibleDelta,
 
209
        err = self.assertRaises(inventory_delta.IncompatibleInventoryDelta,
209
210
            deserializer.parse_text_bytes, reference_lines)
210
211
        self.assertEquals("Tree reference not allowed", str(err))
211
212
 
221
222
tree_references: false
222
223
None\x00/foo\x00id\x00TREE_ROOT\x00changed\x00tree\x00subtree-version
223
224
"""
224
 
        err = self.assertRaises(errors.BzrError,
 
225
        err = self.assertRaises(InventoryDeltaError,
225
226
            deserializer.parse_text_bytes, lines)
226
227
        self.assertContainsRe(str(err), 'Tree reference found')
227
228
 
237
238
tree_references: false
238
239
None\x00/\x00TREE_ROOT\x00\x00a@e\xc3\xa5ample.com--2004\x00dir
239
240
"""
240
 
        err = self.assertRaises(errors.BzrError,
 
241
        err = self.assertRaises(InventoryDeltaError,
241
242
            deserializer.parse_text_bytes, lines)
242
243
        self.assertContainsRe(str(err), 'Versioned root found')
243
244
 
246
247
        # Trim the trailing newline from a valid serialization
247
248
        lines = root_only_lines[:-1]
248
249
        deserializer = inventory_delta.InventoryDeltaDeserializer()
249
 
        err = self.assertRaises(errors.BzrError,
 
250
        err = self.assertRaises(InventoryDeltaError,
250
251
            deserializer.parse_text_bytes, lines)
251
252
        self.assertContainsRe(str(err), 'last line not empty')
252
253
 
255
256
        lines = empty_lines
256
257
        lines += "None\x00bad\x00TREE_ROOT\x00\x00version\x00dir\n"
257
258
        deserializer = inventory_delta.InventoryDeltaDeserializer()
258
 
        err = self.assertRaises(errors.BzrError,
 
259
        err = self.assertRaises(InventoryDeltaError,
259
260
            deserializer.parse_text_bytes, lines)
260
261
        self.assertContainsRe(str(err), 'newpath invalid')
261
262
 
264
265
        lines = root_only_lines
265
266
        lines += "bad\x00/new\x00file-id\x00\x00version\x00dir\n"
266
267
        deserializer = inventory_delta.InventoryDeltaDeserializer()
267
 
        err = self.assertRaises(errors.BzrError,
 
268
        err = self.assertRaises(InventoryDeltaError,
268
269
            deserializer.parse_text_bytes, lines)
269
270
        self.assertContainsRe(str(err), 'oldpath invalid')
270
271
    
351
352
        delta = new_inv._make_delta(old_inv)
352
353
        serializer = inventory_delta.InventoryDeltaSerializer(
353
354
            versioned_root=True, tree_references=True)
354
 
        err = self.assertRaises(errors.BzrError,
 
355
        err = self.assertRaises(InventoryDeltaError,
355
356
            serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta)
356
357
        self.assertEqual(str(err), 'no version for fileid id')
357
358
 
363
364
        delta = new_inv._make_delta(old_inv)
364
365
        serializer = inventory_delta.InventoryDeltaSerializer(
365
366
            versioned_root=True, tree_references=True)
366
 
        err = self.assertRaises(errors.BzrError,
 
367
        err = self.assertRaises(InventoryDeltaError,
367
368
            serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta)
368
369
        self.assertEqual(str(err), 'no version for fileid TREE_ROOT')
369
370
 
376
377
        delta = new_inv._make_delta(old_inv)
377
378
        serializer = inventory_delta.InventoryDeltaSerializer(
378
379
            versioned_root=False, tree_references=True)
379
 
        err = self.assertRaises(errors.BzrError,
 
380
        err = self.assertRaises(InventoryDeltaError,
380
381
            serializer.delta_to_lines, NULL_REVISION, 'entry-version', delta)
381
382
        self.assertStartsWith(str(err), 'Version present for / in TREE_ROOT')
382
383
 
443
444
        serializer = inventory_delta.InventoryDeltaSerializer(
444
445
            versioned_root=False, tree_references=True)
445
446
        self.assertRaises(
446
 
            errors.BzrError, serializer.delta_to_lines, 'old-version',
 
447
            InventoryDeltaError, serializer.delta_to_lines, 'old-version',
447
448
            'new-version', delta)
448
449
 
449
450
    def test_to_inventory_root_id_not_versioned(self):
452
453
        serializer = inventory_delta.InventoryDeltaSerializer(
453
454
            versioned_root=True, tree_references=True)
454
455
        self.assertRaises(
455
 
            errors.BzrError, serializer.delta_to_lines, 'old-version',
 
456
            InventoryDeltaError, serializer.delta_to_lines, 'old-version',
456
457
            'new-version', delta)
457
458
 
458
459
    def test_to_inventory_has_tree_not_meant_to(self):
467
468
            ]
468
469
        serializer = inventory_delta.InventoryDeltaSerializer(
469
470
            versioned_root=True, tree_references=True)
470
 
        self.assertRaises(errors.BzrError, serializer.delta_to_lines,
 
471
        self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
471
472
            'old-version', 'new-version', delta)
472
473
 
473
474
    def test_to_inventory_torture(self):
571
572
    def test_file_without_size(self):
572
573
        file_entry = inventory.make_entry('file', 'a file', None, 'file-id')
573
574
        file_entry.text_sha1 = 'foo'
574
 
        self.assertRaises(errors.BzrError,
 
575
        self.assertRaises(InventoryDeltaError,
575
576
            inventory_delta._file_content, file_entry)
576
577
 
577
578
    def test_file_without_sha1(self):
578
579
        file_entry = inventory.make_entry('file', 'a file', None, 'file-id')
579
580
        file_entry.text_size = 10
580
 
        self.assertRaises(errors.BzrError,
 
581
        self.assertRaises(InventoryDeltaError,
581
582
            inventory_delta._file_content, file_entry)
582
583
 
583
584
    def test_link_empty_target(self):
600
601
 
601
602
    def test_link_no_target(self):
602
603
        entry = inventory.make_entry('symlink', 'a link', None)
603
 
        self.assertRaises(errors.BzrError,
 
604
        self.assertRaises(InventoryDeltaError,
604
605
            inventory_delta._link_content, entry)
605
606
 
606
607
    def test_reference_null(self):
617
618
 
618
619
    def test_reference_no_reference(self):
619
620
        entry = inventory.make_entry('tree-reference', 'a tree', None)
620
 
        self.assertRaises(errors.BzrError,
 
621
        self.assertRaises(InventoryDeltaError,
621
622
            inventory_delta._reference_content, entry)