From 9ebaa17ad89db4d6f5b1670f328eb2478e39c25a Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Tue, 8 Feb 2011 10:28:06 -0800 Subject: [PATCH] ubuntutools/test/test_update_maintainer.py: update test cases to handle checking for debian/rules. --- debian/changelog | 4 ++- ubuntutools/test/test_update_maintainer.py | 41 ++++++++++++++++++++++ ubuntutools/update_maintainer.py | 2 +- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 50a48f5..c4f8f74 100644 --- a/debian/changelog +++ b/debian/changelog @@ -15,8 +15,10 @@ ubuntu-dev-tools (0.116) UNRELEASED; urgency=low [ Kees Cook ] * ubuntutools/update_maintainer.py: do nothing if the rules file already manages XSBC-Original (e.g. python). + * ubuntutools/test/test_update_maintainer.py: update test cases to + handle checking for debian/rules. - -- Kees Cook Mon, 07 Feb 2011 10:42:07 -0800 + -- Kees Cook Tue, 08 Feb 2011 10:27:27 -0800 ubuntu-dev-tools (0.115) unstable; urgency=low diff --git a/ubuntutools/test/test_update_maintainer.py b/ubuntutools/test/test_update_maintainer.py index b76d0ca..e8f2014 100644 --- a/ubuntutools/test/test_update_maintainer.py +++ b/ubuntutools/test/test_update_maintainer.py @@ -120,6 +120,36 @@ VCS-Git: git://git.debian.org/pkg-mozext/adblock-plus.git Package: xul-ext-adblock-plus """ +_SIMPLE_RULES = """#!/usr/bin/make -f +%: + dh $@ +""" + +_COMPLEX_RULES = """#!/usr/bin/make -f +... from python2.6 ... +distribution := $(shell lsb_release -is) + +control-file: + sed -e "s/@PVER@/$(PVER)/g" \ + -e "s/@VER@/$(VER)/g" \ + -e "s/@PYSTDDEP@/$(PYSTDDEP)/g" \ + -e "s/@PRIO@/$(PY_PRIO)/g" \ + -e "s/@MINPRIO@/$(PY_MINPRIO)/g" \ + debian/control.in > debian/control.tmp +ifeq ($(distribution),Ubuntu) + ifneq (,$(findstring ubuntu, $(PKGVERSION))) + m='Ubuntu Core Developers '; \ + sed -i "/^Maintainer:/s/\(.*\)/Maintainer: $$m\nXSBC-Original-\1/" \ + debian/control.tmp + endif +endif + [ -e debian/control ] \ + && cmp -s debian/control debian/control.tmp \ + && rm -f debian/control.tmp && exit 0; \ + mv debian/control.tmp debian/control +... from python2.6 ... +""" + #pylint: disable=R0904 class UpdateMaintainerTestCase(mox.MoxTestBase, unittest.TestCase): """TestCase object for ubuntutools.update_maintainer""" @@ -129,6 +159,7 @@ class UpdateMaintainerTestCase(mox.MoxTestBase, unittest.TestCase): "changelog": None, "control": None, "control.in": None, + "rules": None, } def _fake_isfile(self, filename): @@ -153,6 +184,7 @@ class UpdateMaintainerTestCase(mox.MoxTestBase, unittest.TestCase): super(UpdateMaintainerTestCase, self).setUp() self.mox.stubs.Set(__builtin__, 'open', self._fake_open) self.mox.stubs.Set(os.path, 'isfile', self._fake_isfile) + self._files["rules"] = StringIO.StringIO(_SIMPLE_RULES) Logger.stdout = StringIO.StringIO() Logger.stderr = StringIO.StringIO() @@ -162,6 +194,7 @@ class UpdateMaintainerTestCase(mox.MoxTestBase, unittest.TestCase): 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 @@ -202,3 +235,11 @@ class UpdateMaintainerTestCase(mox.MoxTestBase, unittest.TestCase): self._files["control.in"] = StringIO.StringIO(_ABP_OLD_MAINTAINER) update_maintainer(self._directory, True) self.assertEqual(self._files["control.in"].getvalue(), _ABP_UPDATED) + + def test_update_maintainer_skip_smart_rules(self): + """Test: Skip update when XSBC-Original in debian/rules.""" + self._files["changelog"] = StringIO.StringIO(_LUCID_CHANGELOG) + self._files["control"] = StringIO.StringIO(_ABP_CONTROL) + self._files["rules"] = StringIO.StringIO(_COMPLEX_RULES) + update_maintainer(self._directory) + self.assertEqual(self._files["control"].getvalue(), _ABP_CONTROL) diff --git a/ubuntutools/update_maintainer.py b/ubuntutools/update_maintainer.py index 66d408a..f3d984e 100644 --- a/ubuntutools/update_maintainer.py +++ b/ubuntutools/update_maintainer.py @@ -62,7 +62,7 @@ def update_maintainer(debian_directory, verbose=False): # If the rules file accounts for XSBC-Original-Maintainer, we should not # touch it in this package (e.g. the python package). - if 'XSBC-Original-' in file(os.path.join(debian_directory, "rules")).read(): + if 'XSBC-Original-' in open(os.path.join(debian_directory, "rules")).read(): if verbose: print "XSBC-Original is managed by 'rules' file. Doing nothing." return(0)