~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_knit.py

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-2010 Canonical Ltd
2
2
#
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
17
17
"""Tests for Knit data structure"""
18
18
 
19
19
from cStringIO import StringIO
 
20
import difflib
20
21
import gzip
21
22
import sys
22
23
 
23
24
from bzrlib import (
24
25
    errors,
 
26
    generate_ids,
25
27
    knit,
26
28
    multiparent,
27
29
    osutils,
28
30
    pack,
29
31
    tests,
30
 
    transport,
31
32
    )
32
33
from bzrlib.errors import (
 
34
    RevisionAlreadyPresent,
33
35
    KnitHeaderError,
 
36
    RevisionNotPresent,
34
37
    NoSuchFile,
35
38
    )
36
39
from bzrlib.index import *
37
40
from bzrlib.knit import (
38
41
    AnnotatedKnitContent,
39
42
    KnitContent,
 
43
    KnitSequenceMatcher,
40
44
    KnitVersionedFiles,
41
45
    PlainKnitContent,
42
46
    _VFContentMapGenerator,
46
50
    _KnitKeyAccess,
47
51
    make_file_factory,
48
52
    )
49
 
from bzrlib.patiencediff import PatienceSequenceMatcher
50
53
from bzrlib.repofmt import pack_repo
51
54
from bzrlib.tests import (
 
55
    Feature,
 
56
    KnownFailure,
52
57
    TestCase,
53
58
    TestCaseWithMemoryTransport,
54
59
    TestCaseWithTransport,
55
60
    TestNotApplicable,
56
61
    )
 
62
from bzrlib.transport import get_transport
 
63
from bzrlib.transport.memory import MemoryTransport
 
64
from bzrlib.tuned_gzip import GzipFile
57
65
from bzrlib.versionedfile import (
58
66
    AbsentContentFactory,
59
67
    ConstantMapper,
98
106
        line_delta = source_content.line_delta(target_content)
99
107
        delta_blocks = list(KnitContent.get_line_delta_blocks(line_delta,
100
108
            source_lines, target_lines))
101
 
        matcher = PatienceSequenceMatcher(None, source_lines, target_lines)
102
 
        matcher_blocks = list(matcher.get_matching_blocks())
 
109
        matcher = KnitSequenceMatcher(None, source_lines, target_lines)
 
110
        matcher_blocks = list(list(matcher.get_matching_blocks()))
103
111
        self.assertEqual(matcher_blocks, delta_blocks)
104
112
 
105
113
    def test_get_line_delta_blocks(self):
338
346
        writer.end()
339
347
        return memos
340
348
 
341
 
    def test_pack_collection_pack_retries(self):
342
 
        """An explicit pack of a pack collection succeeds even when a
343
 
        concurrent pack happens.
344
 
        """
345
 
        builder = self.make_branch_builder('.')
346
 
        builder.start_series()
347
 
        builder.build_snapshot('rev-1', None, [
348
 
            ('add', ('', 'root-id', 'directory', None)),
349
 
            ('add', ('file', 'file-id', 'file', 'content\nrev 1\n')),
350
 
            ])
351
 
        builder.build_snapshot('rev-2', ['rev-1'], [
352
 
            ('modify', ('file-id', 'content\nrev 2\n')),
353
 
            ])
354
 
        builder.build_snapshot('rev-3', ['rev-2'], [
355
 
            ('modify', ('file-id', 'content\nrev 3\n')),
356
 
            ])
357
 
        self.addCleanup(builder.finish_series)
358
 
        b = builder.get_branch()
359
 
        self.addCleanup(b.lock_write().unlock)
360
 
        repo = b.repository
361
 
        collection = repo._pack_collection
362
 
        # Concurrently repack the repo.
363
 
        reopened_repo = repo.bzrdir.open_repository()
364
 
        reopened_repo.pack()
365
 
        # Pack the new pack.
366
 
        collection.pack()
367
 
 
368
349
    def make_vf_for_retrying(self):
369
350
        """Create 3 packs and a reload function.
370
351
 
1598
1579
        # could leave an empty .kndx file, which bzr would later claim was a
1599
1580
        # corrupted file since the header was not present. In reality, the file
1600
1581
        # just wasn't created, so it should be ignored.
1601
 
        t = transport.get_transport('.')
 
1582
        t = get_transport('.')
1602
1583
        t.put_bytes('test.kndx', '')
1603
1584
 
1604
1585
        knit = self.make_test_knit()
1605
1586
 
1606
1587
    def test_knit_index_checks_header(self):
1607
 
        t = transport.get_transport('.')
 
1588
        t = get_transport('.')
1608
1589
        t.put_bytes('test.kndx', '# not really a knit header\n\n')
1609
1590
        k = self.make_test_knit()
1610
1591
        self.assertRaises(KnitHeaderError, k.keys)