~ubuntu-branches/ubuntu/oneiric/dulwich/oneiric

« back to all changes in this revision

Viewing changes to dulwich/tests/test_pack.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-30 13:22:11 UTC
  • mfrom: (1.2.11 upstream) (8.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20100730132211-k6aop8v5z42mawef
Tags: 0.6.1-1
* New upstream release.
* Bump standards version to 3.9.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
18
# MA  02110-1301, USA.
19
19
 
20
 
 
21
20
"""Tests for Dulwich packs."""
22
21
 
23
22
 
25
24
import os
26
25
import shutil
27
26
import tempfile
28
 
import unittest
29
27
import zlib
30
28
 
31
29
from dulwich.errors import (
32
30
    ChecksumMismatch,
33
31
    )
 
32
from dulwich.file import (
 
33
    GitFile,
 
34
    )
34
35
from dulwich.objects import (
35
36
    hex_to_sha,
36
37
    sha_to_hex,
42
43
    apply_delta,
43
44
    create_delta,
44
45
    load_pack_index,
45
 
    hex_to_sha,
46
46
    read_zlib_chunks,
47
 
    sha_to_hex,
48
47
    write_pack_index_v1,
49
48
    write_pack_index_v2,
50
49
    write_pack,
51
50
    )
 
51
from dulwich.tests import (
 
52
    TestCase,
 
53
    )
52
54
 
53
55
pack1_sha = 'bc63ddad95e7321ee734ea11a7a62d314e0d7481'
54
56
 
57
59
commit_sha = 'f18faa16531ac570a3fdc8c7ca16682548dafd12'
58
60
 
59
61
 
60
 
class PackTests(unittest.TestCase):
 
62
class PackTests(TestCase):
61
63
    """Base class for testing packs"""
62
64
 
63
65
    def setUp(self):
 
66
        super(PackTests, self).setUp()
64
67
        self.tempdir = tempfile.mkdtemp()
65
68
 
66
69
    def tearDown(self):
67
70
        shutil.rmtree(self.tempdir)
 
71
        super(PackTests, self).tearDown()
68
72
 
69
73
    datadir = os.path.join(os.path.dirname(__file__), 'data/packs')
70
74
 
126
130
        self.assertEquals(set([tree_sha, commit_sha, a_sha]), set(p))
127
131
 
128
132
 
129
 
class TestPackDeltas(unittest.TestCase):
 
133
class TestPackDeltas(TestCase):
130
134
 
131
135
    test_string1 = 'The answer was flailing in the wind'
132
136
    test_string2 = 'The answer was falling down the pipe'
290
294
        except ChecksumMismatch, e:
291
295
            self.fail(e)
292
296
 
 
297
    def writeIndex(self, filename, entries, pack_checksum):
 
298
        # FIXME: Write to StringIO instead rather than hitting disk ?
 
299
        f = GitFile(filename, "wb")
 
300
        try:
 
301
            self._write_fn(f, entries, pack_checksum)
 
302
        finally:
 
303
            f.close()
 
304
 
293
305
    def test_empty(self):
294
306
        filename = os.path.join(self.tempdir, 'empty.idx')
295
 
        self._write_fn(filename, [], pack_checksum)
 
307
        self.writeIndex(filename, [], pack_checksum)
296
308
        idx = load_pack_index(filename)
297
309
        self.assertSucceeds(idx.check)
298
310
        self.assertEquals(idx.get_pack_checksum(), pack_checksum)
302
314
        entry_sha = hex_to_sha('6f670c0fb53f9463760b7295fbb814e965fb20c8')
303
315
        my_entries = [(entry_sha, 178, 42)]
304
316
        filename = os.path.join(self.tempdir, 'single.idx')
305
 
        self._write_fn(filename, my_entries, pack_checksum)
 
317
        self.writeIndex(filename, my_entries, pack_checksum)
306
318
        idx = load_pack_index(filename)
307
319
        self.assertEquals(idx.version, self._expected_version)
308
320
        self.assertSucceeds(idx.check)
321
333
                self.assertTrue(actual_crc is None)
322
334
 
323
335
 
324
 
class TestPackIndexWritingv1(unittest.TestCase, BaseTestPackIndexWriting):
 
336
class TestPackIndexWritingv1(TestCase, BaseTestPackIndexWriting):
325
337
 
326
338
    def setUp(self):
327
 
        unittest.TestCase.setUp(self)
 
339
        TestCase.setUp(self)
328
340
        BaseTestPackIndexWriting.setUp(self)
329
341
        self._has_crc32_checksum = False
330
342
        self._expected_version = 1
331
343
        self._write_fn = write_pack_index_v1
332
344
 
333
345
    def tearDown(self):
334
 
        unittest.TestCase.tearDown(self)
 
346
        TestCase.tearDown(self)
335
347
        BaseTestPackIndexWriting.tearDown(self)
336
348
 
337
349
 
338
 
class TestPackIndexWritingv2(unittest.TestCase, BaseTestPackIndexWriting):
 
350
class TestPackIndexWritingv2(TestCase, BaseTestPackIndexWriting):
339
351
 
340
352
    def setUp(self):
341
 
        unittest.TestCase.setUp(self)
 
353
        TestCase.setUp(self)
342
354
        BaseTestPackIndexWriting.setUp(self)
343
355
        self._has_crc32_checksum = True
344
356
        self._expected_version = 2
345
357
        self._write_fn = write_pack_index_v2
346
358
 
347
359
    def tearDown(self):
348
 
        unittest.TestCase.tearDown(self)
 
360
        TestCase.tearDown(self)
349
361
        BaseTestPackIndexWriting.tearDown(self)
350
362
 
351
363
 
352
 
class ReadZlibTests(unittest.TestCase):
 
364
class ReadZlibTests(TestCase):
353
365
 
354
366
    decomp = (
355
367
      'tree 4ada885c9196b6b6fa08744b5862bf92896fc002\n'
362
374
    extra = 'nextobject'
363
375
 
364
376
    def setUp(self):
 
377
        super(ReadZlibTests, self).setUp()
365
378
        self.read = StringIO(self.comp + self.extra).read
366
379
 
367
380
    def test_decompress_size(self):