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
|
# test_comit_message.py -- Test hook for pre-filling commit message.
# Copyright (C) 2009 Canonical Ltd.
#
# This file is part of bzr-builddeb.
#
# bzr-builddeb is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bzr-builddeb is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bzr-builddeb; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from .. import debian_changelog_commit_message, debian_changelog_commit
from . import TestCaseWithTransport
from ....tests.features import Feature
class _LaunchpadConnectionFeature(Feature):
def _probe(self):
import ssl
try:
from httplib2 import Http, ServerNotFoundError
except ImportError:
return False
try:
Http().request("https://code.launchpad.net/")
except ServerNotFoundError:
return False
except ssl.CertificateError:
return False
return True
LaunchpadConnectionFeature = _LaunchpadConnectionFeature()
class CommitMessageTests(TestCaseWithTransport):
class _Commit:
class _Builder:
_revprops = {}
def __init__(self, work_tree, exclude=[], specific_files=[]):
self.work_tree = work_tree
self.exclude = exclude
self.specific_files = specific_files
self.builder = self._Builder()
def set_changelog_content(self, content):
with open("debian/changelog", 'wb') as f:
f.write(content)
def test_leaves_existing_message(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/'])
wt.add(['a', 'debian'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(debian_changelog_commit_message(commit, "foo"), "foo")
def test_ignores_commit_without_debian_changelog(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/'])
wt.add(['a', 'debian'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(debian_changelog_commit_message(commit, None), None)
def test_ignores_commit_excluding_debian_changelog(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * new line")
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt, exclude=["debian/changelog"])
self.assertEqual(debian_changelog_commit_message(commit, None), None)
def test_ignores_commit_specific_files(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * new line\n")
wt.add(['a'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt, specific_files=["a"])
self.assertEqual(debian_changelog_commit_message(commit, None), None)
def test_provides_stripped_message(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * new line\n")
wt.add(['a'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(
debian_changelog_commit_message(commit, None),
"new line\n")
def test_provides_unstripped_message(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * two\n * changes\n")
wt.add(['a'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(
debian_changelog_commit_message(commit, None),
"* two\n* changes\n")
def test_set_message_with_bugs(self):
self.requireFeature(LaunchpadConnectionFeature)
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * fix LP: #1234\n * close LP: #4321\n")
wt.add(['a'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(
debian_changelog_commit(commit, None),
"* fix LP: #1234\n* close LP: #4321\n")
self.assertEqual(
commit.builder._revprops,
{'bugs': 'https://launchpad.net/bugs/1234 fixed\n'
'https://launchpad.net/bugs/4321 fixed'})
def test_set_message_returns_unicode(self):
wt = self.make_branch_and_tree(".")
self.build_tree(['a', 'debian/', 'debian/changelog'])
wt.add(['debian/', 'debian/changelog'])
wt.commit("one")
self.set_changelog_content(b" * \xe2\x80\xa6real fix this time\n")
wt.add(['a'])
wt.lock_read()
self.addCleanup(wt.unlock)
commit = self._Commit(wt)
self.assertEqual(
debian_changelog_commit(commit, None),
"\u2026real fix this time\n")
|