test: fix example package class

this class can be much simpler and more robust and doesn't require
checking in the example package files to git
This commit is contained in:
Dan Streetman 2021-07-13 15:57:10 -04:00
parent 1b12d8b4e3
commit 0eaf71737d
14 changed files with 57 additions and 83 deletions

4
.gitignore vendored
View File

@ -5,9 +5,7 @@ __pycache__/
*.pyc
/build/
/.pybuild/
/test-data/example_1.0-1.debian.tar.xz
/test-data/example_1.0-1.dsc
/test-data/example_1.0.orig.tar.gz
/test-data/
/debian/python-ubuntutools/
/debian/python3-ubuntutools/
/debian/ubuntu-dev-tools/

1
debian/clean vendored
View File

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

1
debian/control vendored
View File

@ -10,6 +10,7 @@ Build-Depends:
dctrl-tools,
debhelper-compat (= 12),
devscripts (>= 2.11.0~),
dh-make,
dh-python,
distro-info (>= 0.2~),
flake8,

3
debian/copyright vendored
View File

@ -152,7 +152,6 @@ Files: doc/pull-debian-debdiff.1
reverse-depends
seeded-in-ubuntu
sponsor-patch
test-data/*
ubuntu-upload-permission
ubuntutools/archive.py
ubuntutools/builder.py
@ -167,7 +166,7 @@ Copyright: 2009-2011, Benjamin Drung <bdrung@ubuntu.com>
2010, Evan Broder <evan@ebroder.net>
2008, Siegfried-Angel Gevatter Pujals <rainct@ubuntu.com>
2010-2011, Stefano Rivera <stefanor@ubuntu.com>
2017-2019, Dan Streetman <ddstreet@canonical.com>
2017-2021, Dan Streetman <ddstreet@canonical.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

View File

@ -5,6 +5,7 @@ Restrictions: allow-stderr
Test-Command: nosetests3 -v ubuntutools
Depends:
dh-make,
python3-nose,
python3-setuptools,
@,

View File

@ -1 +0,0 @@
upstream

View File

@ -1 +0,0 @@
7

View File

@ -1,12 +0,0 @@
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: ${misc:Depends}, ${shlibs:Depends}
Description: Example package for testing purposes
An example package used by the test suite. Useless.

View File

@ -1,17 +0,0 @@
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

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

View File

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

View File

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

View File

@ -1 +0,0 @@
compression=xz

View File

@ -14,55 +14,69 @@
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
import os.path
import shutil
import os
import subprocess
import tempfile
from pathlib import Path
from ubuntutools.version import Version
class ExamplePackage(object):
def __init__(self, source='example', version='1.0-1'):
def __init__(self, source='example', version='1.0-1', destdir='test-data'):
self.source = source
self.version = Version(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)
self.destdir = Path(destdir)
def create_orig(self):
"Create .orig.tar.gz"
orig = '%s_%s.orig.tar.gz' % (self.source,
self.version.upstream_version)
subprocess.check_call(
(
'tar',
'-czf', orig,
'--exclude', 'debian',
os.path.basename(self.srcdir),
),
cwd='test-data'
)
self.env = dict(os.environ)
self.env['DEBFULLNAME'] = 'Example'
self.env['DEBEMAIL'] = 'example@example.net'
def changelog_entry(self, version=None, create=False):
"Add a changelog entry"
cmd = ['dch', '--noconf', '--preserve', '--package', self.source]
if create:
cmd.append('--create')
cmd += ['--newversion', version or self.version.full_version]
cmd.append('')
env = dict(os.environ)
env['DEBFULLNAME'] = 'Example'
env['DEBEMAIL'] = 'example@example.net'
subprocess.check_call(cmd, env=env, cwd=self.srcdir)
@property
def orig(self):
return self.destdir / f'{self.source}_{self.version.upstream_version}.orig.tar.xz'
@property
def debian(self):
return self.destdir / f'{self.source}_{self.version}.debian.tar.xz'
@property
def dsc(self):
return self.destdir / f'{self.source}_{self.version}.dsc'
@property
def dirname(self):
return f'{self.source}-{self.version.upstream_version}'
@property
def content_filename(self):
return 'content'
@property
def content_text(self):
return 'my content'
def create(self):
"Build source package"
self.changelog_entry(create=True)
(basename, dirname) = os.path.split(self.srcdir)
subprocess.check_call(('dpkg-source', '-b', dirname), cwd=basename)
with tempfile.TemporaryDirectory() as d:
self._create(Path(d))
def cleanup(self):
"Remove srcdir"
shutil.rmtree(self.srcdir)
def _create(self, d):
pkgdir = d / self.dirname
pkgdir.mkdir()
(pkgdir / self.content_filename).write_text(self.content_text)
# run dh_make to create orig tarball
subprocess.run('dh_make -sy --createorig'.split(),
check=True, env=self.env, cwd=str(pkgdir),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# run dpkg-source -b to create debian tar and dsc
subprocess.run(f'dpkg-source -b {self.dirname}'.split(),
check=True, env=self.env, cwd=str(d),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
# move tarballs and dsc to destdir
self.destdir.mkdir(parents=True, exist_ok=True)
(d / self.orig.name).rename(self.orig)
(d / self.debian.name).rename(self.debian)
(d / self.dsc.name).rename(self.dsc)