1
# test_dep3.py -- Testsuite for builddeb dep3.py
2
# Copyright (C) 2011 Canonical Ltd.
4
# This file is part of bzr-builddeb.
6
# bzr-builddeb is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# bzr-builddeb is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with bzr-builddeb; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
from cStringIO import StringIO
25
from bzrlib.revision import (
28
from bzrlib.tests import (
30
TestCaseWithTransport,
33
from bzrlib.plugins.builddeb.dep3 import (
35
determine_applied_upstream,
36
gather_bugs_and_authors,
39
write_dep3_patch_header,
43
class Dep3HeaderTests(TestCase):
45
def dep3_header(self, description=None, origin=None, forwarded=None,
46
bugs=None, authors=None, revision_id=None, last_update=None,
47
applied_upstream=None):
49
write_dep3_patch_header(f, description=description, origin=origin,
50
forwarded=forwarded, bugs=bugs, authors=authors,
51
revision_id=revision_id, last_update=last_update,
52
applied_upstream=applied_upstream)
54
return rfc822.Message(f)
56
def test_description(self):
57
ret = self.dep3_header(description="This patch fixes the foobar")
58
self.assertEquals("This patch fixes the foobar", ret["Description"])
60
def test_last_updated(self):
61
ret = self.dep3_header(last_update=1304840034)
62
self.assertEquals("2011-05-08", ret["Last-Update"])
64
def test_revision_id(self):
65
ret = self.dep3_header(revision_id="myrevid")
66
self.assertEquals("myrevid", ret["X-Bzr-Revision-Id"])
68
def test_authors(self):
70
"Jelmer Vernooij <jelmer@canonical.com>",
71
"James Westby <james.westby@canonical.com>"]
72
ret = self.dep3_header(authors=authors)
74
("Jelmer Vernooij", "jelmer@canonical.com"),
75
("James Westby", "james.westby@canonical.com")],
76
ret.getaddrlist("Author"))
78
def test_origin(self):
79
ret = self.dep3_header(origin="Cherrypick from upstream")
80
self.assertEquals("Cherrypick from upstream",
83
def test_forwarded(self):
84
ret = self.dep3_header(forwarded="not needed")
85
self.assertEquals("not needed",
88
def test_applied_upstream(self):
89
ret = self.dep3_header(applied_upstream="commit 45")
90
self.assertEquals("commit 45", ret["Applied-Upstream"])
94
("http://bugs.debian.org/424242", "fixed"),
95
("https://bugs.launchpad.net/bugs/20110508", "fixed"),
96
("http://bugzilla.samba.org/bug.cgi?id=52", "fixed")]
97
ret = self.dep3_header(bugs=bugs)
99
"https://bugs.launchpad.net/bugs/20110508",
100
"http://bugzilla.samba.org/bug.cgi?id=52"],
101
ret.getheaders("Bug"))
102
self.assertEquals(["http://bugs.debian.org/424242"],
103
ret.getheaders("Bug-Debian"))
105
def test_write_bug_fix_only(self):
106
# non-fixed bug lines are ignored
108
write_dep3_bug_line(f, "http://bar/", "pending")
109
self.assertEquals("", f.getvalue())
111
def test_write_normal_bug(self):
113
write_dep3_bug_line(f, "http://bugzilla.samba.org/bug.cgi?id=42",
115
self.assertEquals("Bug: http://bugzilla.samba.org/bug.cgi?id=42\n",
118
def test_write_debian_bug(self):
120
write_dep3_bug_line(f, "http://bugs.debian.org/234354", "fixed")
121
self.assertEquals("Bug-Debian: http://bugs.debian.org/234354\n",
125
class GatherBugsAndAuthors(TestCaseWithTransport):
128
branch = self.make_branch(".")
129
self.assertEquals((set(), set(), None),
130
gather_bugs_and_authors(branch.repository, []))
132
def test_multiple_authors(self):
133
tree = self.make_branch_and_tree(".")
134
revid1 = tree.commit(authors=["Jelmer Vernooij <jelmer@canonical.com>"],
135
timestamp=1304844311, message="msg")
136
revid2 = tree.commit(authors=["Max Bowsher <maxb@f2s.com>"],
137
timestamp=1304844278, message="msg")
138
self.assertEquals((set(), set([
139
"Jelmer Vernooij <jelmer@canonical.com>",
140
"Max Bowsher <maxb@f2s.com>"]), 1304844311),
141
gather_bugs_and_authors(tree.branch.repository, [revid1, revid2]))
144
tree = self.make_branch_and_tree(".")
145
revid1 = tree.commit(authors=["Jelmer Vernooij <jelmer@canonical.com>"],
146
timestamp=1304844311, message="msg", revprops={"bugs":
147
"http://bugs.samba.org/bug.cgi?id=2011 fixed\n"})
149
set([("http://bugs.samba.org/bug.cgi?id=2011", "fixed")]),
150
set(["Jelmer Vernooij <jelmer@canonical.com>"]), 1304844311),
151
gather_bugs_and_authors(tree.branch.repository, [revid1]))
154
class DetermineAppliedUpstreamTests(TestCaseWithTransport):
156
def test_not_applied(self):
157
upstream = self.make_branch_and_tree("upstream")
158
feature = self.make_branch_and_tree("feature")
159
feature.commit(message="every bloody emperor")
160
self.addCleanup(feature.lock_read().unlock)
161
self.assertEquals("no",
162
determine_applied_upstream(upstream.branch, feature.branch))
164
def test_merged(self):
165
upstream = self.make_branch_and_tree("upstream")
166
upstream.commit(message="initial upstream commit")
167
feature = upstream.bzrdir.sprout("feature").open_workingtree()
168
feature.commit(message="nutter alert")
169
upstream.merge_from_branch(feature.branch)
170
upstream.commit(message="merge feature")
171
self.addCleanup(upstream.lock_read().unlock)
172
self.addCleanup(feature.lock_read().unlock)
173
self.assertEquals("merged in revision 2",
174
determine_applied_upstream(upstream.branch, feature.branch))
177
class DescribeOriginTests(TestCaseWithTransport):
179
def test_no_public_branch(self):
180
tree = self.make_branch_and_tree(".")
181
revid1 = tree.commit(message="msg1")
182
self.assertEquals("commit, revision id: %s" % revid1,
183
describe_origin(tree.branch, revid1))
185
def test_public_branch(self):
186
tree = self.make_branch_and_tree(".")
187
tree.branch.set_public_branch("http://example.com/public")
188
revid1 = tree.commit(message="msg1")
189
self.assertEquals("commit, http://example.com/public, revision: 1",
190
describe_origin(tree.branch, revid1))
193
class FullDep3PatchTests(TestCaseWithTransport):
195
def test_simple(self):
197
tree = self.make_branch_and_tree(".")
198
self.build_tree_contents([("foo", "data")])
200
revid = tree.commit("msg", rev_id="arevid", timestamp=1304849661,
202
write_dep3_patch(f, tree.branch, NULL_REVISION, revid,
203
description="Nutter alert",
204
forwarded="not needed",
205
authors=set(["Jelmer <jelmer@samba.org>"]))
206
self.assertEquals("Description: Nutter alert\n"
207
"Forwarded: not needed\n"
208
"Author: Jelmer <jelmer@samba.org>\n"
209
"X-Bzr-Revision-Id: arevid\n"
211
"=== added file 'foo'\n"
212
"--- old/foo\t1970-01-01 00:00:00 +0000\n"
213
"+++ new/foo\t2011-05-08 10:14:21 +0000\n"
216
"\\ No newline at end of file\n"