/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_pristine_tar.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2012-2018 Jelmer Vernooij <jelmer@jelmer.uk>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
"""Tests for pristine tar extraction code."""
18
 
 
19
 
from __future__ import absolute_import
20
 
 
21
 
from base64 import standard_b64encode
22
 
 
23
 
from ..pristine_tar import (
24
 
    get_pristine_tar_tree,
25
 
    revision_pristine_tar_data,
26
 
    read_git_pristine_tar_data,
27
 
    store_git_pristine_tar_data,
28
 
    )
29
 
 
30
 
from ....revision import Revision
31
 
from ....tests import TestCase
32
 
 
33
 
from dulwich.objects import (
34
 
    Blob,
35
 
    Tree,
36
 
    )
37
 
from dulwich.repo import (
38
 
    MemoryRepo as GitMemoryRepo,
39
 
    )
40
 
import stat
41
 
 
42
 
 
43
 
class RevisionPristineTarDataTests(TestCase):
44
 
 
45
 
    def test_pristine_tar_delta_unknown(self):
46
 
        rev = Revision("myrevid")
47
 
        self.assertRaises(KeyError,
48
 
            revision_pristine_tar_data, rev)
49
 
 
50
 
    def test_pristine_tar_delta_gz(self):
51
 
        rev = Revision("myrevid")
52
 
        rev.properties["deb-pristine-delta"] = standard_b64encode("bla")
53
 
        self.assertEquals(("bla", "gz"), revision_pristine_tar_data(rev))
54
 
 
55
 
 
56
 
class ReadPristineTarData(TestCase):
57
 
 
58
 
    def test_read_pristine_tar_data_no_branch(self):
59
 
        r = GitMemoryRepo()
60
 
        self.assertRaises(KeyError, read_git_pristine_tar_data,
61
 
            r, "foo")
62
 
 
63
 
    def test_read_pristine_tar_data_no_file(self):
64
 
        r = GitMemoryRepo()
65
 
        t = Tree()
66
 
        b = Blob.from_string("README")
67
 
        r.object_store.add_object(b)
68
 
        t.add("README", stat.S_IFREG | 0644, b.id)
69
 
        r.object_store.add_object(t)
70
 
        r.do_commit("Add README", tree=t.id,
71
 
                    ref='refs/heads/pristine-tar')
72
 
        self.assertRaises(KeyError, read_git_pristine_tar_data,
73
 
            r, "foo")
74
 
 
75
 
    def test_read_pristine_tar_data(self):
76
 
        r = GitMemoryRepo()
77
 
        delta = Blob.from_string("some yummy data")
78
 
        r.object_store.add_object(delta)
79
 
        idfile = Blob.from_string("someid")
80
 
        r.object_store.add_object(idfile)
81
 
        t = Tree()
82
 
        t.add("foo.delta", stat.S_IFREG | 0644, delta.id)
83
 
        t.add("foo.id", stat.S_IFREG | 0644, idfile.id)
84
 
        r.object_store.add_object(t)
85
 
        r.do_commit("pristine tar delta for foo", tree=t.id,
86
 
                    ref='refs/heads/pristine-tar')
87
 
        self.assertEquals(
88
 
            ("some yummy data", "someid"),
89
 
            read_git_pristine_tar_data(r, 'foo'))
90
 
 
91
 
 
92
 
class StoreGitPristineTarData(TestCase):
93
 
 
94
 
    def test_store_new(self):
95
 
        r = GitMemoryRepo()
96
 
        cid = store_git_pristine_tar_data(r, "foo", "mydelta", "myid")
97
 
        tree = get_pristine_tar_tree(r)
98
 
        self.assertEquals(
99
 
            (stat.S_IFREG | 0644, "7b02de8ac4162e64f402c43487d8a40a505482e1"),
100
 
            tree["README"])
101
 
        self.assertEquals(r[cid].tree, tree.id)
102
 
        self.assertEquals(r[tree["foo.delta"][1]].data, "mydelta")
103
 
        self.assertEquals(r[tree["foo.id"][1]].data, "myid")
104
 
 
105
 
        self.assertEquals(("mydelta", "myid"),
106
 
            read_git_pristine_tar_data(r, "foo"))