~maxb/bzr-builddeb/mend-indent

« back to all changes in this revision

Viewing changes to tests/test_dep3.py

  • Committer: Jelmer Vernooij
  • Date: 2011-05-16 14:08:45 UTC
  • mfrom: (556.1.13 trunk)
  • Revision ID: jelmer@samba.org-20110516140845-98c5a9x3vpx3wc14
Merge new 'bzr dep3-patch' command.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    test_dep3.py -- Testsuite for builddeb dep3.py
 
2
#    Copyright (C) 2011 Canonical Ltd.
 
3
#
 
4
#    This file is part of bzr-builddeb.
 
5
#
 
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.
 
10
#
 
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.
 
15
#
 
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
 
19
#
 
20
 
 
21
from cStringIO import StringIO
 
22
 
 
23
import rfc822
 
24
 
 
25
from bzrlib.revision import (
 
26
    NULL_REVISION,
 
27
    )
 
28
from bzrlib.tests import (
 
29
    TestCase,
 
30
    TestCaseWithTransport,
 
31
    )
 
32
 
 
33
from bzrlib.plugins.builddeb.dep3 import (
 
34
    describe_origin,
 
35
    determine_applied_upstream,
 
36
    gather_bugs_and_authors,
 
37
    write_dep3_bug_line,
 
38
    write_dep3_patch,
 
39
    write_dep3_patch_header,
 
40
    )
 
41
 
 
42
 
 
43
class Dep3HeaderTests(TestCase):
 
44
 
 
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):
 
48
        f = StringIO()
 
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)
 
53
        f.seek(0)
 
54
        return rfc822.Message(f)
 
55
 
 
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"])
 
59
 
 
60
    def test_last_updated(self):
 
61
        ret = self.dep3_header(last_update=1304840034)
 
62
        self.assertEquals("2011-05-08", ret["Last-Update"])
 
63
 
 
64
    def test_revision_id(self):
 
65
        ret = self.dep3_header(revision_id="myrevid")
 
66
        self.assertEquals("myrevid", ret["X-Bzr-Revision-Id"])
 
67
 
 
68
    def test_authors(self):
 
69
        authors = [
 
70
            "Jelmer Vernooij <jelmer@canonical.com>",
 
71
            "James Westby <james.westby@canonical.com>"]
 
72
        ret = self.dep3_header(authors=authors)
 
73
        self.assertEquals([
 
74
            ("Jelmer Vernooij", "jelmer@canonical.com"),
 
75
            ("James Westby", "james.westby@canonical.com")],
 
76
            ret.getaddrlist("Author"))
 
77
 
 
78
    def test_origin(self):
 
79
        ret = self.dep3_header(origin="Cherrypick from upstream")
 
80
        self.assertEquals("Cherrypick from upstream",
 
81
            ret["Origin"])
 
82
 
 
83
    def test_forwarded(self):
 
84
        ret = self.dep3_header(forwarded="not needed")
 
85
        self.assertEquals("not needed",
 
86
            ret["Forwarded"])
 
87
 
 
88
    def test_applied_upstream(self):
 
89
        ret = self.dep3_header(applied_upstream="commit 45")
 
90
        self.assertEquals("commit 45", ret["Applied-Upstream"])
 
91
 
 
92
    def test_bugs(self):
 
93
        bugs = [
 
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)
 
98
        self.assertEquals([
 
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"))
 
104
 
 
105
    def test_write_bug_fix_only(self):
 
106
        # non-fixed bug lines are ignored
 
107
        f = StringIO()
 
108
        write_dep3_bug_line(f, "http://bar/", "pending")
 
109
        self.assertEquals("", f.getvalue())
 
110
 
 
111
    def test_write_normal_bug(self):
 
112
        f = StringIO()
 
113
        write_dep3_bug_line(f, "http://bugzilla.samba.org/bug.cgi?id=42",
 
114
            "fixed")
 
115
        self.assertEquals("Bug: http://bugzilla.samba.org/bug.cgi?id=42\n",
 
116
            f.getvalue())
 
117
 
 
118
    def test_write_debian_bug(self):
 
119
        f = StringIO()
 
120
        write_dep3_bug_line(f, "http://bugs.debian.org/234354", "fixed")
 
121
        self.assertEquals("Bug-Debian: http://bugs.debian.org/234354\n",
 
122
            f.getvalue())
 
123
 
 
124
 
 
125
class GatherBugsAndAuthors(TestCaseWithTransport):
 
126
 
 
127
    def test_none(self):
 
128
        branch = self.make_branch(".")
 
129
        self.assertEquals((set(), set(), None),
 
130
            gather_bugs_and_authors(branch.repository, []))
 
131
 
 
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]))
 
142
 
 
143
    def test_bugs(self):
 
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"})
 
148
        self.assertEquals((
 
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]))
 
152
 
 
153
 
 
154
class DetermineAppliedUpstreamTests(TestCaseWithTransport):
 
155
 
 
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))
 
163
 
 
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))
 
175
 
 
176
 
 
177
class DescribeOriginTests(TestCaseWithTransport):
 
178
 
 
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))
 
184
 
 
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))
 
191
 
 
192
 
 
193
class FullDep3PatchTests(TestCaseWithTransport):
 
194
 
 
195
    def test_simple(self):
 
196
        f = StringIO()
 
197
        tree = self.make_branch_and_tree(".")
 
198
        self.build_tree_contents([("foo", "data")])
 
199
        tree.add("foo")
 
200
        revid = tree.commit("msg", rev_id="arevid", timestamp=1304849661,
 
201
            timezone=0)
 
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"
 
210
            "\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"
 
214
            "@@ -0,0 +1,1 @@\n"
 
215
            "+data\n"
 
216
            "\\ No newline at end of file\n"
 
217
            "\n", f.getvalue())