diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-04-03 15:29:19 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-04-26 22:07:15 +0200 |
commit | f880910c80c30bf64f951bb054814d2e00e76b77 (patch) | |
tree | a18da537a857d09ac8fb4c66c850e792d42c9c3c /tests | |
parent | ae63dba9f6d2fe2d1c0889b69eccacb3fc256a9c (diff) | |
download | git-buildpackage-f880910c80c30bf64f951bb054814d2e00e76b77.tar.gz git-buildpackage-f880910c80c30bf64f951bb054814d2e00e76b77.tar.bz2 git-buildpackage-f880910c80c30bf64f951bb054814d2e00e76b77.zip |
tests: Fix tests for Ubuntu
On Ubuntu dch produces different version numbering. Adapt tests for
this.
Adds a jew class to parse '/etc/lsb-release' to determine the
distribution and it's codename to dynamically adapt tests accordingly.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/11_test_dch_main.py | 30 | ||||
-rw-r--r-- | tests/test_Changelog.py | 28 | ||||
-rw-r--r-- | tests/testutils.py | 33 |
3 files changed, 71 insertions, 20 deletions
diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py index 7a0f6dff..ef718221 100644 --- a/tests/11_test_dch_main.py +++ b/tests/11_test_dch_main.py @@ -6,15 +6,25 @@ from . import context import unittest -from tests.testutils import DebianGitTestRepo +from tests.testutils import DebianGitTestRepo, OsReleaseFile from gbp.scripts import dch import os import re -# Snapshot of version 0.9-2~1 -snap_header_0_9 = r'^test-package\s\(0.9-2~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=low' +# For Ubuntu compatibility +os_release = OsReleaseFile('/etc/lsb-release') + +# OS release codename and snapshot of version 0.9-2~1 +if os_release['DISTRIB_ID'] == 'Ubuntu': + os_codename = os_release['DISTRIB_CODENAME'] + snap_header_0_9 = r'^test-package\s\(0.9-1ubuntu1~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=low' + new_version_0_9 = '0.9-1ubuntu1' +else: + os_codename = 'unstable' + snap_header_0_9 = r'^test-package\s\(0.9-2~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=low' + new_version_0_9 = '0.9-2' # Snapshot of version 1.0-1~1 snap_header_1 = r'^test-package\s\(1.0-1~1\.gbp([0-9a-f]{6})\)\sUNRELEASED;\surgency=low' # Snapshot of version 1.0-1~2 @@ -83,7 +93,7 @@ class TestScriptDch(DebianGitTestRepo): """Test dch.py like git-dch script does: new upstream version - release""" options = ["--release"] lines = self.run_dch(options) - self.assertEqual("test-package (1.0-1) unstable; urgency=low\n", lines[0]) + self.assertEqual("test-package (1.0-1) %s; urgency=low\n" % os_codename, lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -161,7 +171,7 @@ class TestScriptDch(DebianGitTestRepo): options = ["--auto"] options.append("--release") lines = self.run_dch(options) - self.assertEqual("test-package (1.0-1) unstable; urgency=low\n", lines[0]) + self.assertEqual("test-package (1.0-1) %s; urgency=low\n" % os_codename, lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -281,7 +291,7 @@ class TestScriptDch(DebianGitTestRepo): options = ["--release"] options.append("--urgency=emergency") lines = self.run_dch(options) - self.assertEqual("test-package (1.0-1) unstable; urgency=emergency\n", lines[0]) + self.assertEqual("test-package (1.0-1) %s; urgency=emergency\n" % os_codename, lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -303,7 +313,7 @@ class TestScriptDch(DebianGitTestRepo): self.repo.create_tag("debian/0.9-1", msg="Pre stable release version 0.9-1", commit="HEAD~2") self.repo.delete_tag("upstream/1.0") lines = self.run_dch() - self.assertEqual("test-package (0.9-2) UNRELEASED; urgency=low\n", lines[0]) + self.assertEqual("test-package (%s) UNRELEASED; urgency=low\n" % new_version_0_9, lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -312,7 +322,7 @@ class TestScriptDch(DebianGitTestRepo): self.repo.delete_tag("upstream/1.0") options = ["--release"] lines = self.run_dch(options) - self.assertEqual("test-package (0.9-2) unstable; urgency=low\n", lines[0]) + self.assertEqual("test-package (%s) %s; urgency=low\n" % (new_version_0_9, os_codename), lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -321,7 +331,7 @@ class TestScriptDch(DebianGitTestRepo): self.repo.delete_tag("upstream/1.0") options = ["--auto"] lines = self.run_dch(options) - self.assertEqual("test-package (0.9-2) UNRELEASED; urgency=low\n", lines[0]) + self.assertEqual("test-package (%s) UNRELEASED; urgency=low\n" % new_version_0_9, lines[0]) self.assertIn(""" * added debian/control\n""", lines) @@ -343,7 +353,7 @@ class TestScriptDch(DebianGitTestRepo): options = ["--auto"] options.append("--release") lines = self.run_dch(options) - self.assertEqual("test-package (0.9-2) unstable; urgency=low\n", lines[0]) + self.assertEqual("test-package (%s) %s; urgency=low\n" % (new_version_0_9, os_codename), lines[0]) self.assertIn(""" * added debian/control\n""", lines) diff --git a/tests/test_Changelog.py b/tests/test_Changelog.py index d0572c1e..55cbcada 100644 --- a/tests/test_Changelog.py +++ b/tests/test_Changelog.py @@ -238,6 +238,8 @@ def test_add_section(): >>> import tempfile >>> import shutil >>> import gbp.deb.changelog + >>> from tests.testutils import OsReleaseFile + >>> os_release = OsReleaseFile('/etc/lsb-release') >>> olddir = os.path.abspath(os.path.curdir) >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-') >>> testdebdir = os.path.join(testdir, 'debian') @@ -252,11 +254,13 @@ def test_add_section(): >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname) >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org") >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname) - >>> cl.version - '0.5.33' - >>> cl.debian_version - '0.5.33' - >>> cl['Distribution'] in ['UNRELEASED', 'unstable'] + >>> version = '0.5.32ubuntu1' if os_release['DISTRIB_ID'] == 'Ubuntu' else '0.5.33' + >>> cl.version == version + True + >>> cl.debian_version == version + True + >>> distributions = ['UNRELEASED', os_release['DISTRIB_CODENAME'] or 'unstable'] + >>> cl['Distribution'] in distributions True >>> 'Test add section' in cl['Changes'] True @@ -280,6 +284,8 @@ def test_add_entry(): >>> import tempfile >>> import shutil >>> import gbp.deb.changelog + >>> from tests.testutils import OsReleaseFile + >>> os_release = OsReleaseFile('/etc/lsb-release') >>> olddir = os.path.abspath(os.path.curdir) >>> testdir = tempfile.mkdtemp(prefix='gbp-test-changelog-') >>> testdebdir = os.path.join(testdir, 'debian') @@ -295,11 +301,13 @@ def test_add_entry(): >>> cl.add_section(msg=["Test add section"], distribution=None, author="Debian Maintainer", email="maint@debian.org") >>> cl.add_entry(msg=["Test add entry"], author="Debian Maintainer", email="maint@debian.org") >>> cl = gbp.deb.changelog.ChangeLog(filename=testclname) - >>> cl.version - '0.5.33' - >>> cl.debian_version - '0.5.33' - >>> cl['Distribution'] in ['UNRELEASED', 'unstable'] + >>> version = '0.5.32ubuntu1' if os_release['DISTRIB_ID'] == 'Ubuntu' else '0.5.33' + >>> cl.version == version + True + >>> cl.debian_version == version + True + >>> distributions = ['UNRELEASED', os_release['DISTRIB_CODENAME'] or 'unstable'] + >>> cl['Distribution'] in distributions True >>> 'Test add entry' in cl['Changes'] True diff --git a/tests/testutils.py b/tests/testutils.py index 38e0ac3b..0f953bce 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -41,3 +41,36 @@ class DebianGitTestRepo(unittest.TestCase): content == None or f.write(content) self.repo.add_files(name, force=True) self.repo.commit_files(path, msg or "added %s" % name) + +class OsReleaseFile(object): + """Repesents a simple file with key-value pairs""" + + def __init__(self, filename): + self._values = {} + + try: + with open(filename, 'r') as filed: + for line in filed.readlines(): + try: + key, value = line.split('=', 1) + except ValueError: + pass + else: + self._values[key] = value.strip() + except IOError as err: + gbp.log.info('Failed to read OS release file %s: %s' % + (filename, err)) + + def __getitem__(self, key): + if key in self._values: + return self._values[key] + return None + + def __contains__(self, key): + return key in self._values + + def __str__(self): + return str(self._values) + + def __repr__(self): + return repr(self._values) |