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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
# test_update_maintainer.py - Test suite for ubuntutools.update_maintainer
#
# Copyright (C) 2010, Benjamin Drung <bdrung@ubuntu.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""Test suite for ubuntutools.update_maintainer"""
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import os
import sys
import mock
from ubuntutools.logger import Logger
from ubuntutools.test import unittest
from ubuntutools.update_maintainer import update_maintainer
_LUCID_CHANGELOG = """\
axis2c (1.6.0-0ubuntu8) lucid; urgency=low
* rebuild rest of main for armel armv7/thumb2 optimization;
UbuntuSpec:mobile-lucid-arm-gcc-v7-thumb2
-- Alexander Sack <asac@ubuntu.com> Fri, 05 Mar 2010 03:10:28 +0100
"""
_AXIS2C_CONTROL = """\
Source: axis2c
Section: libs
Priority: optional
DM-Upload-Allowed: yes
XSBC-Original-Maintainer: Soren Hansen <soren@ubuntu.com>
Maintainer: Kyo Lee <kyo.lee@eucalyptus.com>
Standards-Version: 3.9.1
Homepage: http://ws.apache.org/axis2/c/
Package: libaxis2c0
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
"""
_AXIS2C_UPDATED = """\
Source: axis2c
Section: libs
Priority: optional
DM-Upload-Allowed: yes
XSBC-Original-Maintainer: Kyo Lee <kyo.lee@eucalyptus.com>
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Standards-Version: 3.9.1
Homepage: http://ws.apache.org/axis2/c/
Package: libaxis2c0
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
"""
_UNSTABLE_CHANGELOG = """\
adblock-plus (1.3.3-1) unstable; urgency=low
* New upstream release.
-- Benjamin Drung <bdrung@ubuntu.com> Sat, 25 Dec 2010 20:17:41 +0100
"""
_ABP_CONTROL = """\
Source: adblock-plus
Section: web
Priority: optional
Maintainer: Dmitry E. Oboukhov <unera@debian.org>
Uploaders: Debian Mozilla Extension Maintainers <pkg-mozext-maintainers@lists.alioth.debian.org>,
Benjamin Drung <bdrung@ubuntu.com>
Build-Depends: debhelper (>= 7.0.50~), mozilla-devscripts (>= 0.19~)
Standards-Version: 3.9.1
DM-Upload-Allowed: yes
Homepage: http://adblockplus.org/
VCS-Browser: http://git.debian.org/?p=pkg-mozext/adblock-plus.git;a=summary
VCS-Git: git://git.debian.org/pkg-mozext/adblock-plus.git
Package: xul-ext-adblock-plus
"""
_ABP_UPDATED = """\
Source: adblock-plus
Section: web
Priority: optional
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
XSBC-Original-Maintainer: Dmitry E. Oboukhov <unera@debian.org>
Uploaders: Debian Mozilla Extension Maintainers <pkg-mozext-maintainers@lists.alioth.debian.org>,
Benjamin Drung <bdrung@ubuntu.com>
Build-Depends: debhelper (>= 7.0.50~), mozilla-devscripts (>= 0.19~)
Standards-Version: 3.9.1
DM-Upload-Allowed: yes
Homepage: http://adblockplus.org/
VCS-Browser: http://git.debian.org/?p=pkg-mozext/adblock-plus.git;a=summary
VCS-Git: git://git.debian.org/pkg-mozext/adblock-plus.git
Package: xul-ext-adblock-plus
"""
_ABP_OLD_MAINTAINER = """\
Source: adblock-plus
Section: web
Priority: optional
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
XSBC-Original-Maintainer: Dmitry E. Oboukhov <unera@debian.org>
Uploaders: Debian Mozilla Extension Maintainers <pkg-mozext-maintainers@lists.alioth.debian.org>,
Benjamin Drung <bdrung@ubuntu.com>
Build-Depends: debhelper (>= 7.0.50~), mozilla-devscripts (>= 0.19~)
Standards-Version: 3.9.1
DM-Upload-Allowed: yes
Homepage: http://adblockplus.org/
VCS-Browser: http://git.debian.org/?p=pkg-mozext/adblock-plus.git;a=summary
VCS-Git: git://git.debian.org/pkg-mozext/adblock-plus.git
Package: xul-ext-adblock-plus
"""
_SIMPLE_RULES = """\
#!/usr/bin/make -f
%:
\tdh $@
"""
_COMPLEX_RULES = """\
#!/usr/bin/make -f
... from python2.6 ...
distribution := $(shell lsb_release -is)
control-file:
\tsed -e "s/@PVER@/$(PVER)/g" \\
\t\t-e "s/@VER@/$(VER)/g" \\
\t\t-e "s/@PYSTDDEP@/$(PYSTDDEP)/g" \\
\t\t-e "s/@PRIO@/$(PY_PRIO)/g" \\
\t\t-e "s/@MINPRIO@/$(PY_MINPRIO)/g" \\
\t\tdebian/control.in > debian/control.tmp
ifeq ($(distribution),Ubuntu)
ifneq (,$(findstring ubuntu, $(PKGVERSION)))
\tm='Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>'; \\
\t\tsed -i "/^Maintainer:/s/\\(.*\\)/Maintainer: $$m\nXSBC-Original-\1/" \\
\t\tdebian/control.tmp
endif
endif
\t[ -e debian/control ] \\
\t\t&& cmp -s debian/control debian/control.tmp \\
\t\t&& rm -f debian/control.tmp && exit 0; \\
\t\tmv debian/control.tmp debian/control
... from python2.6 ...
"""
_SEAHORSE_PLUGINS_CONTROL = """\
# This file is autogenerated. DO NOT EDIT!
#
# Modifications should be made to debian/control.in instead.
# This file is regenerated automatically in the clean target.
Source: seahorse-plugins
Section: gnome
Priority: optional
Maintainer: Emilio Pozuelo Monfort <pochu@debian.org>
Build-Depends: debhelper (>= 5),
cdbs (>= 0.4.41)
Standards-Version: 3.8.3
Homepage: http://live.gnome.org/Seahorse
Package: seahorse-plugins
"""
_SEAHORSE_PLUGINS_UPDATED = """\
# This file is autogenerated. DO NOT EDIT!
#
# Modifications should be made to debian/control.in instead.
# This file is regenerated automatically in the clean target.
Source: seahorse-plugins
Section: gnome
Priority: optional
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
XSBC-Original-Maintainer: Emilio Pozuelo Monfort <pochu@debian.org>
Build-Depends: debhelper (>= 5),
cdbs (>= 0.4.41)
Standards-Version: 3.8.3
Homepage: http://live.gnome.org/Seahorse
Package: seahorse-plugins
"""
# pylint: disable=R0904
class UpdateMaintainerTestCase(unittest.TestCase):
"""TestCase object for ubuntutools.update_maintainer"""
_directory = "/"
_files = {
"changelog": None,
"control": None,
"control.in": None,
"rules": None,
}
def _fake_isfile(self, filename):
"""Check only for existing fake files."""
directory, base = os.path.split(filename)
return (directory == self._directory and base in self._files and
self._files[base] is not None)
def _fake_open(self, filename, mode='r'):
"""Provide StringIO objects instead of real files."""
directory, base = os.path.split(filename)
if (directory != self._directory or base not in self._files or
(mode == "r" and self._files[base] is None)):
raise IOError("No such file or directory: '%s'" % filename)
if mode == "w":
self._files[base] = StringIO()
self._files[base].close = lambda: None
return self._files[base]
# pylint: disable=C0103
def setUp(self):
if sys.version_info[0] < 3:
self.assertRegex = self.assertRegexpMatches
m = mock.mock_open()
m.side_effect = self._fake_open
if sys.version_info[0] >= 3:
target = 'builtins.open'
else:
target = '__builtin__.open'
patcher = mock.patch(target, m)
self.addCleanup(patcher.stop)
patcher.start()
m = mock.MagicMock(side_effect=self._fake_isfile)
patcher = mock.patch('os.path.isfile', m)
self.addCleanup(patcher.stop)
patcher.start()
self._files["rules"] = StringIO(_SIMPLE_RULES)
Logger.stdout = StringIO()
Logger.stderr = StringIO()
def tearDown(self):
self.assertEqual(Logger.stdout.getvalue(), '')
self.assertEqual(Logger.stderr.getvalue(), '')
self._files["changelog"] = None
self._files["control"] = None
self._files["control.in"] = None
self._files["rules"] = None
Logger.stdout = sys.stdout
Logger.stderr = sys.stderr
# pylint: enable=C0103
def test_debian_package(self):
"""Test: Don't update Maintainer field if target is Debian."""
self._files["changelog"] = StringIO(_UNSTABLE_CHANGELOG)
self._files["control"] = StringIO(_ABP_CONTROL)
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), _ABP_CONTROL)
def test_original_ubuntu_maintainer(self):
"""Test: Original maintainer is Ubuntu developer.
The Maintainer field needs to be update even if
XSBC-Original-Maintainer has an @ubuntu.com address."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_AXIS2C_CONTROL)
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), _AXIS2C_UPDATED)
warnings = Logger.stderr.getvalue().strip()
Logger.stderr = StringIO()
self.assertEqual(len(warnings.splitlines()), 1)
self.assertRegex(warnings, "Warning: Overwriting original maintainer: "
"Soren Hansen <soren@ubuntu.com>")
def test_update_maintainer(self):
"""Test: Update Maintainer field."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_ABP_CONTROL)
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), _ABP_UPDATED)
def test_update_old_maintainer(self):
"""Test: Update old MOTU address."""
self._files["changelog"] = StringIO(_UNSTABLE_CHANGELOG)
self._files["control.in"] = StringIO(_ABP_OLD_MAINTAINER)
update_maintainer(self._directory, True)
self.assertEqual(self._files["control.in"].getvalue(), _ABP_UPDATED)
def test_comments_in_control(self):
"""Test: Update Maintainer field in a control file containing
comments."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_SEAHORSE_PLUGINS_CONTROL)
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(),
_SEAHORSE_PLUGINS_UPDATED)
def test_skip_smart_rules(self):
"""Test: Skip update when XSBC-Original in debian/rules."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_ABP_CONTROL)
self._files["rules"] = StringIO(_COMPLEX_RULES)
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), _ABP_CONTROL)
def test_missing_rules(self):
"""Test: Skip XSBC-Original test when debian/rules is missing."""
self._files["changelog"] = StringIO(_LUCID_CHANGELOG)
self._files["control"] = StringIO(_ABP_CONTROL)
self._files["rules"] = None
update_maintainer(self._directory)
self.assertEqual(self._files["control"].getvalue(), _ABP_UPDATED)
|