From bb718951ed27450148f84d31ca94a4272741d135 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sat, 15 Jan 2011 19:47:13 +0200 Subject: [PATCH] Store blank example package extracted --- debian/clean | 1 + debian/copyright | 1 + test-data/blank-example/content | 1 + test-data/blank-example/debian/compat | 1 + test-data/blank-example/debian/control | 12 +++ test-data/blank-example/debian/copyright | 17 ++++ test-data/blank-example/debian/rules | 4 + test-data/blank-example/debian/source/format | 1 + .../blank-example/debian/source/local-options | 1 + ubuntutools/test/example_package.py | 94 +++---------------- ubuntutools/test/test_archive.py | 40 ++++---- 11 files changed, 72 insertions(+), 101 deletions(-) create mode 100644 test-data/blank-example/content create mode 100644 test-data/blank-example/debian/compat create mode 100644 test-data/blank-example/debian/control create mode 100644 test-data/blank-example/debian/copyright create mode 100755 test-data/blank-example/debian/rules create mode 100644 test-data/blank-example/debian/source/format create mode 100644 test-data/blank-example/debian/source/local-options diff --git a/debian/clean b/debian/clean index 45149aa..a0ad765 100644 --- a/debian/clean +++ b/debian/clean @@ -1 +1,2 @@ *.egg-info/* +test-data/example_* diff --git a/debian/copyright b/debian/copyright index bfeb82c..74a5ac4 100644 --- a/debian/copyright +++ b/debian/copyright @@ -184,6 +184,7 @@ Files: doc/pull-debian-debdiff.1, pull-debian-debdiff, sponsor-patch, suspicious-source, + test-data/*, ubuntutools/archive.py, ubuntutools/builder.py, ubuntutools/config.py, diff --git a/test-data/blank-example/content b/test-data/blank-example/content new file mode 100644 index 0000000..0459513 --- /dev/null +++ b/test-data/blank-example/content @@ -0,0 +1 @@ +upstream diff --git a/test-data/blank-example/debian/compat b/test-data/blank-example/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/test-data/blank-example/debian/compat @@ -0,0 +1 @@ +7 diff --git a/test-data/blank-example/debian/control b/test-data/blank-example/debian/control new file mode 100644 index 0000000..192c897 --- /dev/null +++ b/test-data/blank-example/debian/control @@ -0,0 +1,12 @@ +Source: example +Section: misc +Priority: extra +Maintainer: Ubuntu Developers +Build-Depends: debhelper (>= 7.0.50~) +Standards-Version: 3.9.1 + +Package: example +Architecture: all +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Example package for testing purposes + An example package used by the test suite. Useless. diff --git a/test-data/blank-example/debian/copyright b/test-data/blank-example/debian/copyright new file mode 100644 index 0000000..c19a068 --- /dev/null +++ b/test-data/blank-example/debian/copyright @@ -0,0 +1,17 @@ +Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=152 +Source: https://launchpad.net/ubuntu-dev-tools + +Files: * +Copyright: 2010-2011, Stefano Rivera +License: ISC + 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. diff --git a/test-data/blank-example/debian/rules b/test-data/blank-example/debian/rules new file mode 100755 index 0000000..4067ba0 --- /dev/null +++ b/test-data/blank-example/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ diff --git a/test-data/blank-example/debian/source/format b/test-data/blank-example/debian/source/format new file mode 100644 index 0000000..163aaf8 --- /dev/null +++ b/test-data/blank-example/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) diff --git a/test-data/blank-example/debian/source/local-options b/test-data/blank-example/debian/source/local-options new file mode 100644 index 0000000..2ee6f0f --- /dev/null +++ b/test-data/blank-example/debian/source/local-options @@ -0,0 +1 @@ +abort-on-upstream-changes diff --git a/ubuntutools/test/example_package.py b/ubuntutools/test/example_package.py index fffdb71..53c236c 100644 --- a/ubuntutools/test/example_package.py +++ b/ubuntutools/test/example_package.py @@ -17,81 +17,31 @@ import os.path import shutil import subprocess -import tempfile import debian.debian_support -_base_pkg = { - 'content': 'Boring file from upstream', - 'debian/control': -"""Source: example -Section: misc -Priority: extra -Maintainer: Example -Build-Depends: debhelper (>= 7.0.50~) -Standards-Version: 3.9.1 - -Package: example -Architecture: all -Depends: ${shlibs:Depends}, ${misc:Depends} -Description: Example package for testing purposes - An example package used by the test suite. Useless. -""", - 'debian/copyright': -"""Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=152 -Source: https://launchpad.net/ubuntu-dev-tools - -Files: * -Copyright: 2010-2011, Stefano Rivera -License: ISC - 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. -""", - 'debian/compat': '7', - 'debian/rules': -"""#!/usr/bin/make -f -%: -\tdh $@ -""", - 'debian/source/format': '3.0 (quilt)', - 'debian/source/local-options': 'abort-on-upstream-changes', -} - class ExamplePackage(object): - def __init__(self, source='example', version='1.0-1', workdir=None, - files=None): + def __init__(self, source='example', version='1.0-1'): self.source = source self.version = debian.debian_support.Version(version) - - self.pkg = dict(_base_pkg) - if files is not None: - self.pkg.update(files) - - self.workdir = workdir or tempfile.mkdtemp(prefix='examplepkg') - self.srcdir = os.path.join(self.workdir, '%s-%s' % (source, - self.version.upstream_version)) + self.srcdir = os.path.join('test-data', '%s-%s' % (source, + self.version.upstream_version)) + if os.path.exists(self.srcdir): + shutil.rmtree(self.srcdir) + shutil.copytree('test-data/blank-example', self.srcdir) def create_orig(self): "Create .orig.tar.gz" - self._write_files(filter_=lambda fn: not fn.startswith('debian/')) orig = '%s_%s.orig.tar.gz' % (self.source, self.version.upstream_version) subprocess.check_call(('tar', '-czf', orig, - os.path.basename(self.srcdir)), - cwd=self.workdir) + os.path.basename(self.srcdir), + '--exclude', 'debian'), + cwd='test-data') def changelog_entry(self, version=None, create=False): "Add a changelog entry" - cmd = ['dch', '--noconf', '--package', self.source] + cmd = ['dch', '--noconf', '--preserve', '--package', self.source] if create: cmd.append('--create') cmd += ['--newversion', version or self.version.full_version] @@ -103,31 +53,11 @@ class ExamplePackage(object): def create(self): "Build source package" - self._write_files() self.changelog_entry(create=True) subprocess.check_call(('dpkg-buildpackage', '-rfakeroot', '-S', '-uc', '-us'), cwd=self.srcdir) def cleanup(self): - "Remove workdir" - shutil.rmtree(self.workdir) - - def pathname(self, fn): - "Return path to file in workdir" - return os.path.join(self.workdir, fn) - - def _write_files(self, filter_=None): - "Write files from self.pkg into src pkg dir, if filter_(fn)" - if filter_ is None: - filter_ = lambda x: True - - for fn, content in self.pkg.iteritems(): - if not filter_(fn): - continue - pathname = os.path.join(self.srcdir, fn) - dirname = os.path.dirname(pathname) - if not os.path.exists(dirname): - os.makedirs(dirname) - with open(pathname, 'wb') as f: - f.write(content) + "Remove srcdir" + shutil.rmtree(self.srcdir) diff --git a/ubuntutools/test/test_archive.py b/ubuntutools/test/test_archive.py index e5a07d9..af12d51 100644 --- a/ubuntutools/test/test_archive.py +++ b/ubuntutools/test/test_archive.py @@ -30,37 +30,38 @@ import ubuntutools.archive from ubuntutools.config import UDTConfig from ubuntutools.logger import Logger from ubuntutools.test import unittest + from ubuntutools.test.example_package import ExamplePackage -ex_pkg = ExamplePackage() def setUpModule(): - ex_pkg.create_orig() - ex_pkg.create() + if not os.path.exists('test-data/example-0.1-1.dsc'): + ex_pkg = ExamplePackage() + ex_pkg.create_orig() + ex_pkg.create() + ex_pkg.cleanup() -def tearDownModule(): - ex_pkg.cleanup() class DscVerificationTestCase(mox.MoxTestBase, unittest.TestCase): def setUp(self): super(DscVerificationTestCase, self).setUp() - with open(ex_pkg.pathname('example_1.0-1.dsc'), 'rb') as f: + with open('test-data/example_1.0-1.dsc', 'rb') as f: self.dsc = ubuntutools.archive.Dsc(f.read()) def tearDown(self): super(DscVerificationTestCase, self).tearDown() def test_good(self): - self.assertTrue(self.dsc.verify_file(ex_pkg.pathname( - 'example_1.0.orig.tar.gz'))) - self.assertTrue(self.dsc.verify_file(ex_pkg.pathname( - 'example_1.0-1.debian.tar.gz'))) + self.assertTrue(self.dsc.verify_file( + 'test-data/example_1.0.orig.tar.gz')) + self.assertTrue(self.dsc.verify_file( + 'test-data/example_1.0-1.debian.tar.gz')) def test_missing(self): - self.assertFalse(self.dsc.verify_file(ex_pkg.pathname( - 'does.not.exist'))) + self.assertFalse(self.dsc.verify_file( + 'test-data/does.not.exist')) def test_bad(self): - fn = ex_pkg.pathname('example_1.0.orig.tar.gz') + fn = 'test-data/example_1.0.orig.tar.gz' with open(fn, 'rb') as f: data = f.read() data = data[:-1] + chr(ord(data[-1]) ^ 8) @@ -105,7 +106,8 @@ class LocalSourcePackageTestCase(mox.MoxTestBase, unittest.TestCase): if destname is None: destname = os.path.basename(url) return self.urlopen('file://' - + os.path.abspath(ex_pkg.pathname(destname))) + + os.path.join(os.path.abspath('test-data'), + destname)) def urlopen_file(self, filename): "Wrapper for urlopen_proxy for named files" @@ -129,15 +131,15 @@ class LocalSourcePackageTestCase(mox.MoxTestBase, unittest.TestCase): self.mox.ReplayAll() pkg = self.SourcePackage('example', '1.0-1', 'main', - dscfile=ex_pkg.pathname('example_1.0-1.dsc'), + dscfile='test-data/example_1.0-1.dsc', workdir=self.workdir) pkg.pull() pkg.unpack() def test_verification(self): - for fn in ('example_1.0-1.dsc', 'example_1.0.orig.tar.gz', - 'example_1.0-1.debian.tar.gz'): - shutil.copy2(ex_pkg.pathname(fn), self.workdir) + shutil.copy2('test-data/example_1.0-1.dsc', self.workdir) + shutil.copy2('test-data/example_1.0.orig.tar.gz', self.workdir) + shutil.copy2('test-data/example_1.0-1.debian.tar.gz', self.workdir) with open(os.path.join(self.workdir, 'example_1.0-1.debian.tar.gz'), 'r+b') as f: f.write('CORRUPTION') @@ -148,7 +150,7 @@ class LocalSourcePackageTestCase(mox.MoxTestBase, unittest.TestCase): self.mox.ReplayAll() pkg = self.SourcePackage('example', '1.0-1', 'main', - dscfile=ex_pkg.pathname('example_1.0-1.dsc'), + dscfile='test-data/example_1.0-1.dsc', workdir=self.workdir) pkg.pull()