/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.358.2 by Jelmer Vernooij
Refresh copyright headers, add my email.
1
# Copyright (C) 2012-2018 Jelmer Vernooij <jelmer@jelmer.uk>
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
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
0.358.1 by Jelmer Vernooij
Fix FSF address.
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
16
17
"""Tests for pristine tar extraction code."""
18
19
from base64 import standard_b64encode
20
0.200.1642 by Jelmer Vernooij
Use relative imports in tests.
21
from ..pristine_tar import (
0.277.4 by Jelmer Vernooij
Add function for storing git pristine tar delta files.
22
    get_pristine_tar_tree,
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
23
    revision_pristine_tar_data,
24
    read_git_pristine_tar_data,
0.277.4 by Jelmer Vernooij
Add function for storing git pristine tar delta files.
25
    store_git_pristine_tar_data,
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
26
    )
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
27
6986.2.1 by Jelmer Vernooij
Move breezy.plugins.git to breezy.git.
28
from ...revision import Revision
29
from ...tests import TestCase
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
30
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
31
from dulwich.objects import (
32
    Blob,
33
    Tree,
34
    )
35
from dulwich.repo import (
36
    MemoryRepo as GitMemoryRepo,
37
    )
38
import stat
39
40
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
41
class RevisionPristineTarDataTests(TestCase):
42
43
    def test_pristine_tar_delta_unknown(self):
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
44
        rev = Revision(b"myrevid")
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
45
        self.assertRaises(KeyError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
46
                          revision_pristine_tar_data, rev)
0.277.2 by Jelmer Vernooij
Add tests for basic pristine tar extraction function.
47
48
    def test_pristine_tar_delta_gz(self):
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
49
        rev = Revision(b"myrevid")
50
        rev.properties[u"deb-pristine-delta"] = standard_b64encode(b"bla")
6964.2.3 by Jelmer Vernooij
Review comments.
51
        self.assertEqual((b"bla", "gz"), revision_pristine_tar_data(rev))
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
52
53
54
class ReadPristineTarData(TestCase):
55
56
    def test_read_pristine_tar_data_no_branch(self):
57
        r = GitMemoryRepo()
58
        self.assertRaises(KeyError, read_git_pristine_tar_data,
7143.15.2 by Jelmer Vernooij
Run autopep8.
59
                          r, b"foo")
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
60
61
    def test_read_pristine_tar_data_no_file(self):
62
        r = GitMemoryRepo()
63
        t = Tree()
6973.13.2 by Jelmer Vernooij
Fix some more tests.
64
        b = Blob.from_string(b"README")
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
65
        r.object_store.add_object(b)
6973.13.2 by Jelmer Vernooij
Fix some more tests.
66
        t.add(b"README", stat.S_IFREG | 0o644, b.id)
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
67
        r.object_store.add_object(t)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
68
        r.do_commit(b"Add README", tree=t.id,
69
                    ref=b'refs/heads/pristine-tar')
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
70
        self.assertRaises(KeyError, read_git_pristine_tar_data,
7143.15.2 by Jelmer Vernooij
Run autopep8.
71
                          r, b"foo")
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
72
73
    def test_read_pristine_tar_data(self):
74
        r = GitMemoryRepo()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
75
        delta = Blob.from_string(b"some yummy data")
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
76
        r.object_store.add_object(delta)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
77
        idfile = Blob.from_string(b"someid")
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
78
        r.object_store.add_object(idfile)
79
        t = Tree()
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
80
        t.add(b"foo.delta", stat.S_IFREG | 0o644, delta.id)
81
        t.add(b"foo.id", stat.S_IFREG | 0o644, idfile.id)
0.277.3 by Jelmer Vernooij
Add function for reading pristine tar data from a git repo.
82
        r.object_store.add_object(t)
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
83
        r.do_commit(b"pristine tar delta for foo", tree=t.id,
84
                    ref=b'refs/heads/pristine-tar')
6964.2.3 by Jelmer Vernooij
Review comments.
85
        self.assertEqual(
6964.2.1 by Jelmer Vernooij
Initial work to support brz-git on python3.
86
            (b"some yummy data", b"someid"),
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
87
            read_git_pristine_tar_data(r, b'foo'))
0.277.4 by Jelmer Vernooij
Add function for storing git pristine tar delta files.
88
89
90
class StoreGitPristineTarData(TestCase):
91
92
    def test_store_new(self):
93
        r = GitMemoryRepo()
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
94
        cid = store_git_pristine_tar_data(r, b"foo", b"mydelta", b"myid")
0.277.4 by Jelmer Vernooij
Add function for storing git pristine tar delta files.
95
        tree = get_pristine_tar_tree(r)
6964.2.3 by Jelmer Vernooij
Review comments.
96
        self.assertEqual(
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
97
            (stat.S_IFREG | 0o644, b"7b02de8ac4162e64f402c43487d8a40a505482e1"),
98
            tree[b"README"])
6964.2.3 by Jelmer Vernooij
Review comments.
99
        self.assertEqual(r[cid].tree, tree.id)
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
100
        self.assertEqual(r[tree[b"foo.delta"][1]].data, b"mydelta")
101
        self.assertEqual(r[tree[b"foo.id"][1]].data, b"myid")
0.277.5 by Jelmer Vernooij
Test delta functions against each other.
102
7018.3.8 by Jelmer Vernooij
Disable some flaky tests on python3, allow running without fastimport.
103
        self.assertEqual((b"mydelta", b"myid"),
7143.15.2 by Jelmer Vernooij
Run autopep8.
104
                         read_git_pristine_tar_data(r, b"foo"))