~bzr/ubuntu/karmic/bzr-git/bzr-ppa

« back to all changes in this revision

Viewing changes to tests/test_object_store.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-22 23:40:04 UTC
  • mfrom: (17.25.364 trunk)
  • Revision ID: jelmer@samba.org-20100522234004-48r0bfkodp3xspgv
* New upstream release.
* Bump standards version to 3.8.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2010 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 bzr-git's object store."""
 
18
 
 
19
from dulwich.objects import (
 
20
    Blob,
 
21
    )
 
22
 
 
23
from bzrlib.graph import (
 
24
    DictParentsProvider,
 
25
    )
 
26
from bzrlib.tests import (
 
27
    TestCase,
 
28
    )
 
29
 
 
30
from bzrlib.plugins.git.object_store import (
 
31
    _check_expected_sha,
 
32
    _find_missing_bzr_revids,
 
33
    )
 
34
 
 
35
 
 
36
class ExpectedShaTests(TestCase):
 
37
 
 
38
    def setUp(self):
 
39
        super(ExpectedShaTests, self).setUp()
 
40
        self.obj = Blob()
 
41
        self.obj.data = "foo"
 
42
 
 
43
    def test_none(self):
 
44
        _check_expected_sha(None, self.obj)
 
45
 
 
46
    def test_hex(self):
 
47
        _check_expected_sha(self.obj.sha().hexdigest(), self.obj)
 
48
        self.assertRaises(AssertionError, _check_expected_sha, 
 
49
            "0" * 40, self.obj)
 
50
 
 
51
    def test_binary(self):
 
52
        _check_expected_sha(self.obj.sha().digest(), self.obj)
 
53
        self.assertRaises(AssertionError, _check_expected_sha, 
 
54
            "x" * 20, self.obj)
 
55
 
 
56
 
 
57
class FindMissingBzrRevidsTests(TestCase):
 
58
 
 
59
    def _find_missing(self, ancestry, want, have):
 
60
        return _find_missing_bzr_revids(
 
61
            DictParentsProvider(ancestry).get_parent_map,
 
62
            set(want), set(have))
 
63
 
 
64
    def test_simple(self):
 
65
        self.assertEquals(set(), self._find_missing({}, [], []))
 
66
 
 
67
    def test_up_to_date(self):
 
68
        self.assertEquals(set(),
 
69
                self._find_missing({"a": ["b"]}, ["a"], ["a"]))
 
70
 
 
71
    def test_one_missing(self):
 
72
        self.assertEquals(set(["a"]),
 
73
                self._find_missing({"a": ["b"]}, ["a"], ["b"]))
 
74
 
 
75
    def test_two_missing(self):
 
76
        self.assertEquals(set(["a", "b"]),
 
77
                self._find_missing({"a": ["b"], "b": ["c"]}, ["a"], ["c"]))
 
78
 
 
79
    def test_two_missing_history(self):
 
80
        self.assertEquals(set(["a", "b"]),
 
81
                self._find_missing({"a": ["b"], "b": ["c"], "c": ["d"]},
 
82
                    ["a"], ["c"]))