/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
1
from bzrlib import (
2
    inventory,
3
    revision as _mod_revision,
4
    )
5
from bzrlib.tests.repository_implementations import TestCaseWithRepository
6
7
class TestCheckRepository(TestCaseWithRepository):
8
9
    def make_broken_repository(self):
10
        repo = self.make_repository('.')
11
12
        # make rev1a
13
        inv = inventory.Inventory(revision_id='rev1a')
14
        inv.root.revision = 'rev1a'
15
        self.add_file(repo, inv, 'file1', 'rev1a', [])
16
        repo.add_inventory('rev1a', inv, [])
17
        revision = _mod_revision.Revision('rev1a',
18
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
19
            timezone=0, message='foo', parent_ids=[])
20
        repo.add_revision('rev1a',revision, inv)
21
22
        # make rev1b
23
        inv = inventory.Inventory(revision_id='rev1b')
24
        inv.root.revision = 'rev1b'
25
        self.add_file(repo, inv, 'file1', 'rev1b', [])
26
        repo.add_inventory('rev1b', inv, [])
27
28
        # make rev2
29
        inv = inventory.Inventory(revision_id='rev2')
30
        inv.root.revision = 'rev2'
31
        self.add_file(repo, inv, 'file1', 'rev2', ['rev1a', 'rev1b'])
2745.6.2 by Aaron Bentley
Handle files not present in revision
32
        self.add_file(repo, inv, 'file2', 'rev2', [])
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
33
        repo.add_inventory('rev2', inv, ['rev1a'])
34
        revision = _mod_revision.Revision('rev2',
35
            committer='jrandom@example.com', timestamp=0, inventory_sha1='',
36
            timezone=0, message='foo', parent_ids=['rev1a'])
37
        repo.add_revision('rev2',revision, inv)
38
        return repo
39
40
    def add_file(self, repo, inv, filename, revision, parents):
41
        file_id = filename + '-id'
42
        entry = inventory.InventoryFile(file_id, filename, 'TREE_ROOT')
43
        entry.revision = revision 
44
        inv.add(entry)
45
        vf = repo.weave_store.get_weave_or_empty(file_id,
46
                                                 repo.get_transaction())
47
        vf.add_lines(revision, parents, ['line\n'])
48
2745.6.2 by Aaron Bentley
Handle files not present in revision
49
    def check_versionedfile(self, file_id, revision_ids):
50
        repo = self.make_broken_repository()
51
        vf = repo.weave_store.get_weave(file_id, repo.get_transaction())
52
        return repo.check_versionedfile(revision_ids, file_id, vf, {})
53
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
54
    def test_normal_first_revision(self):
55
        repo = self.make_broken_repository()
56
        vf = repo.weave_store.get_weave('file1-id', repo.get_transaction())
57
        inventory_versions = {}
58
        result = repo.check_versionedfile(['rev1a'], 'file1-id', vf,
59
            inventory_versions)
60
        self.assertSubset(['rev1a'], inventory_versions.keys())
61
        self.assertEqual('rev1a', inventory_versions['rev1a']['file1-id'])
62
        self.assertEqual({}, result)
63
2745.6.2 by Aaron Bentley
Handle files not present in revision
64
    def test_not_present_in_revision(self):
65
        # It is not an error to check a revision that does not contain the file
66
        result = self.check_versionedfile('file2-id', ['rev1a'])
67
        self.assertEqual({}, result)
68
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
69
    def test_second_revision(self):
70
        repo = self.make_broken_repository()
71
        vf = repo.weave_store.get_weave('file1-id', repo.get_transaction())
72
        inventory_versions = {}
73
        result = repo.check_versionedfile(['rev2'], 'file1-id', vf,
74
            inventory_versions)
75
        self.assertEqual({('file1-id', 'rev2'): set(['rev1b'])}, result)