aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/doctests/test_PristineTar.py
blob: 15c614cf42be8d946e04b1a29aa341592ae36a36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# vim: set fileencoding=utf-8 :
"""
Test pristine-tar related methods in

    - L{gbp.deb.pristinetar.DebianPristineTar}

and

    - L{gbp.deb.git.DebianGitRepository}

This testcase creates this reposity:

    - A repository at I{dirs['repo']} called I{repo}

"""

import os
from .. import context

test_data = os.path.join(context.projectdir, "tests/data/pristine_tar")
dirs = {}


def setup_module():
    dirs['repo'] = context.new_tmpdir(__name__).join('repo')


def teardown_module():
    del dirs['repo']
    context.teardown()


def test_create():
    """
    Create a repository

    Methods tested:
         - L{gbp.deb.git.DebianGitRepository.create}

    >>> import os, gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository.create(dirs['repo'])
    """


def test_empty_repo():
    """
    Empty repos have no branch pristine-tar branch

    Methods tested:
         - L{gbp.deb.git.DebianGitRepository.has_pristine_tar_branch}
         - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.has_pristine_tar_branch()
    False
    >>> repo.pristine_tar.has_commit('upstream', '1.0', 'gzip')
    False
    """


def test_commit_dir():
    """
    Empty repos have no branch pristine-tar branch

    Methods tested:
         - L{gbp.git.repository.GitRepository.commit_dir}
         - L{gbp.git.repository.GitRepository.create_branch}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> commit = repo.commit_dir(test_data, msg="initial commit", branch=None)
    >>> repo.create_branch('upstream')
    """


def test_create_tarball():
    """
    Create a tarball from a git tree and add a stub signature

    Methods tested:
         - L{gbp.deb.git.DebianGitRepository.archive}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.archive('tar', 'upstream/', '../upstream_1.0.orig.tar', 'upstream')
    >>> gbp.command_wrappers.Command('gzip', [ '-n', '%s/../upstream_1.0.orig.tar' % dirs['repo']])()
    >>> with open('%s/../upstream_1.0.orig.tar.gz.asc' % dirs['repo'], 'w') as f: f.write("sig")
    3
    """


def test_pristine_tar_commit():
    """
    Commit the delta to the pristine-tar branch

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.commit}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.pristine_tar.commit('../upstream_1.0.orig.tar.gz', 'upstream')
    """


def test_pristine_tar_commit_with_sig():
    """
    Commit the delta to the pristine-tar branch including a signature

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.commit}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.pristine_tar.commit('../upstream_1.0.orig.tar.gz', 'upstream',
    ...                          signaturefile='../upstream_1.0.orig.tar.gz.asc')
    """


def test_pristine_has_commit():
    """
    Find delta on the pristine tar branch

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.has_commit}
         - L{gbp.pkg.pristinetar.PristineTar.get_commit}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.pristine_tar.has_commit('upstream', '1.0', 'bzip2')
    False
    >>> repo.pristine_tar.has_commit('upstream', '1.0', 'gzip')
    True
    >>> repo.pristine_tar.has_commit('upstream', '1.0')
    True
    >>> branch = repo.rev_parse('pristine-tar')
    >>> commit = repo.pristine_tar.get_commit('upstream_1.0.orig.tar.gz')
    >>> branch == commit
    True
    """


def test_pristine_tar_checkout():
    """
    Checkout a tarball using pristine-tar

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.checkout}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> repo.pristine_tar.checkout('upstream', '1.0', 'gzip', '..')
    """


def test_pristine_tar_checkout_with_sig():
    """
    Checkout a tarball using pristine-tar

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.checkout}

    >>> import gbp.deb.git
    >>> from gbp.deb.policy import DebianPkgPolicy

    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> sf = os.path.join(repo.path,
    ...                   DebianPkgPolicy.build_signature_name('upstream', '1.0', 'gzip', '..'))
    >>> os.unlink(sf)
    >>> repo.pristine_tar.checkout('upstream', '1.0', 'gzip', '..',
    ...                             signature=True)
    >>> os.path.exists(sf) or not repo.pristine_tar.has_feature_sig()
    True
    """


def test_pristine_tar_verify():
    """
    Verify a tarball using pristine-tar

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.verify}

    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> if repo.pristine_tar.has_feature_verify():
    ...    repo.pristine_tar.verify('../upstream_1.0.orig.tar.gz')
    """


def test_pristine_tar_checkout_nonexistent():
    """
    Checkout a tarball that does not exist using pristine-tar

    Methods tested:
         - L{gbp.deb.pristinetar.DebianPristineTar.checkout}

    # Silence error output
    >>> import gbp.deb.git
    >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
    >>> _gbp_log_err_bak = gbp.log.err
    >>> gbp.log.err = lambda x: None
    >>> repo.pristine_tar.checkout('upstream', '1.1', 'gzip', '..')
    Traceback (most recent call last):
    ...
    gbp.command_wrappers.CommandExecFailed: Pristine-tar couldn't checkout "upstream_1.1.orig.tar.gz": fatal: Path 'upstream_1.1.orig.tar.gz.delta' does not exist in 'refs/heads/pristine-tar'
    pristine-tar: git show refs/heads/pristine-tar:upstream_1.1.orig.tar.gz.delta failed
    >>> gbp.log.err = _gbp_log_err_bak
    """

# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: