Store blank example package extracted

This commit is contained in:
Stefano Rivera 2011-01-15 19:47:13 +02:00
parent b11d08f6b0
commit bb718951ed
11 changed files with 72 additions and 101 deletions

1
debian/clean vendored
View File

@ -1 +1,2 @@
*.egg-info/*
test-data/example_*

1
debian/copyright vendored
View File

@ -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,

View File

@ -0,0 +1 @@
upstream

View File

@ -0,0 +1 @@
7

View File

@ -0,0 +1,12 @@
Source: example
Section: misc
Priority: extra
Maintainer: Ubuntu Developers <ubuntu-dev-team@lists.alioth.debian.org>
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.

View File

@ -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 <stefanor@ubuntu.com>
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.

View File

@ -0,0 +1,4 @@
#!/usr/bin/make -f
%:
dh $@

View File

@ -0,0 +1 @@
3.0 (quilt)

View File

@ -0,0 +1 @@
abort-on-upstream-changes

View File

@ -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 <example@example.net>
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 <stefanor@ubuntu.com>
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)

View File

@ -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()