From 0eaf71737d197240d368d1296d7bcd780085d68d Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Tue, 13 Jul 2021 15:57:10 -0400 Subject: [PATCH] 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 --- .gitignore | 4 +- debian/clean | 1 - debian/control | 1 + debian/copyright | 3 +- debian/tests/control | 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 - test-data/blank-example/debian/source/options | 1 - ubuntutools/test/example_package.py | 92 +++++++++++-------- 14 files changed, 57 insertions(+), 83 deletions(-) delete mode 100644 test-data/blank-example/content delete mode 100644 test-data/blank-example/debian/compat delete mode 100644 test-data/blank-example/debian/control delete mode 100644 test-data/blank-example/debian/copyright delete mode 100755 test-data/blank-example/debian/rules delete mode 100644 test-data/blank-example/debian/source/format delete mode 100644 test-data/blank-example/debian/source/local-options delete mode 100644 test-data/blank-example/debian/source/options diff --git a/.gitignore b/.gitignore index 20a512f..869d17d 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/debian/clean b/debian/clean index 9ea7836..3feb78a 100644 --- a/debian/clean +++ b/debian/clean @@ -1,2 +1 @@ *.egg-info/ -test-data/example_* diff --git a/debian/control b/debian/control index 1781dd3..dc3c830 100644 --- a/debian/control +++ b/debian/control @@ -10,6 +10,7 @@ Build-Depends: dctrl-tools, debhelper-compat (= 12), devscripts (>= 2.11.0~), + dh-make, dh-python, distro-info (>= 0.2~), flake8, diff --git a/debian/copyright b/debian/copyright index 2221ec8..9db0196 100644 --- a/debian/copyright +++ b/debian/copyright @@ -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 2010, Evan Broder 2008, Siegfried-Angel Gevatter Pujals 2010-2011, Stefano Rivera - 2017-2019, Dan Streetman + 2017-2021, Dan Streetman 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 diff --git a/debian/tests/control b/debian/tests/control index 0be1f25..51ba57e 100644 --- a/debian/tests/control +++ b/debian/tests/control @@ -5,6 +5,7 @@ Restrictions: allow-stderr Test-Command: nosetests3 -v ubuntutools Depends: + dh-make, python3-nose, python3-setuptools, @, diff --git a/test-data/blank-example/content b/test-data/blank-example/content deleted file mode 100644 index 0459513..0000000 --- a/test-data/blank-example/content +++ /dev/null @@ -1 +0,0 @@ -upstream diff --git a/test-data/blank-example/debian/compat b/test-data/blank-example/debian/compat deleted file mode 100644 index 7f8f011..0000000 --- a/test-data/blank-example/debian/compat +++ /dev/null @@ -1 +0,0 @@ -7 diff --git a/test-data/blank-example/debian/control b/test-data/blank-example/debian/control deleted file mode 100644 index a101fad..0000000 --- a/test-data/blank-example/debian/control +++ /dev/null @@ -1,12 +0,0 @@ -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: ${misc:Depends}, ${shlibs: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 deleted file mode 100644 index c19a068..0000000 --- a/test-data/blank-example/debian/copyright +++ /dev/null @@ -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 -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 deleted file mode 100755 index 2d33f6a..0000000 --- a/test-data/blank-example/debian/rules +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/make -f - -%: - dh $@ diff --git a/test-data/blank-example/debian/source/format b/test-data/blank-example/debian/source/format deleted file mode 100644 index 163aaf8..0000000 --- a/test-data/blank-example/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/test-data/blank-example/debian/source/local-options b/test-data/blank-example/debian/source/local-options deleted file mode 100644 index 2ee6f0f..0000000 --- a/test-data/blank-example/debian/source/local-options +++ /dev/null @@ -1 +0,0 @@ -abort-on-upstream-changes diff --git a/test-data/blank-example/debian/source/options b/test-data/blank-example/debian/source/options deleted file mode 100644 index 161b7e0..0000000 --- a/test-data/blank-example/debian/source/options +++ /dev/null @@ -1 +0,0 @@ -compression=xz diff --git a/ubuntutools/test/example_package.py b/ubuntutools/test/example_package.py index 3b53bde..d4be8cd 100644 --- a/ubuntutools/test/example_package.py +++ b/ubuntutools/test/example_package.py @@ -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)