/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tests/test_shamap.py

Add docstring.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Jelmer Vernooij <jelmer@samba.org>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for GitShaMap."""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.tests import (
 
22
    TestCase,
 
23
    TestCaseInTempDir,
 
24
    UnavailableFeature,
 
25
    )
 
26
 
 
27
from bzrlib.plugins.git.shamap import (
 
28
    DictGitShaMap,
 
29
    SqliteGitShaMap,
 
30
    TdbGitShaMap,
 
31
    )
 
32
 
 
33
class TestGitShaMap:
 
34
 
 
35
    def test_commit(self):
 
36
        self.map.start_write_group()
 
37
        self.map._add_entry("5686645d49063c73d35436192dfc9a160c672301",
 
38
            "commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"))
 
39
        self.map.commit_write_group()
 
40
        self.assertEquals(
 
41
            ("commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba")),
 
42
            self.map.lookup_git_sha("5686645d49063c73d35436192dfc9a160c672301"))
 
43
 
 
44
    def test_lookup_notfound(self):
 
45
        self.assertRaises(KeyError,
 
46
            self.map.lookup_git_sha, "5686645d49063c73d35436192dfc9a160c672301")
 
47
 
 
48
    def test_blob(self):
 
49
        thesha = "5686645d49063c73d35436192dfc9a160c672301"
 
50
        self.map.start_write_group()
 
51
        self.map._add_entry(thesha, "blob", ("myfileid", "myrevid"))
 
52
        self.map.commit_write_group()
 
53
        self.assertEquals(
 
54
            ("blob", ("myfileid", "myrevid")),
 
55
            self.map.lookup_git_sha(thesha))
 
56
        invshamap = self.map.get_inventory_sha_map("myrevid")
 
57
        self.assertEquals(thesha, invshamap.lookup_blob("myfileid"))
 
58
 
 
59
    def test_tree(self):
 
60
        thesha = "5686645d49063c73d35436192dfc9a160c672301"
 
61
        self.map.start_write_group()
 
62
        self.map._add_entry(thesha,
 
63
            "tree", ("somepath", "myrevid"))
 
64
        self.map.commit_write_group()
 
65
        self.assertEquals(
 
66
            ("tree", ("somepath", "myrevid")),
 
67
            self.map.lookup_git_sha(thesha))
 
68
 
 
69
    def test_revids(self):
 
70
        self.map.start_write_group()
 
71
        self.map._add_entry("5686645d49063c73d35436192dfc9a160c672301",
 
72
            "commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"))
 
73
        self.map.commit_write_group()
 
74
        self.assertEquals(["myrevid"], list(self.map.revids()))
 
75
 
 
76
    def test_missing_revisions(self):
 
77
        self.map.start_write_group()
 
78
        self.map._add_entry("5686645d49063c73d35436192dfc9a160c672301",
 
79
            "commit", ("myrevid", "cc9462f7f8263ef5adfbeff2fb936bb36b504cba"))
 
80
        self.map.commit_write_group()
 
81
        self.assertEquals(set(["lala", "bla"]),
 
82
            set(self.map.missing_revisions(["myrevid", "lala", "bla"])))
 
83
 
 
84
 
 
85
class DictGitShaMapTests(TestCase,TestGitShaMap):
 
86
 
 
87
    def setUp(self):
 
88
        TestCase.setUp(self)
 
89
        self.map = DictGitShaMap()
 
90
 
 
91
 
 
92
class SqliteGitShaMapTests(TestCase,TestGitShaMap):
 
93
 
 
94
    def setUp(self):
 
95
        TestCase.setUp(self)
 
96
        self.map = SqliteGitShaMap()
 
97
 
 
98
 
 
99
class TdbGitShaMapTests(TestCaseInTempDir,TestGitShaMap):
 
100
 
 
101
    def setUp(self):
 
102
        TestCaseInTempDir.setUp(self)
 
103
        try:
 
104
            self.map = TdbGitShaMap(os.path.join(self.test_dir, 'foo.tdb'))
 
105
        except ImportError:
 
106
            raise UnavailableFeature("Missing tdb")