Colin Watson has proposed merging lp:~cjwatson/launchpad/xenial-apt-tests into
lp:launchpad.
Commit message:
Fix various test failures caused by xenial's new apt version.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/xenial-apt-tests/+merge/314700
--
Your team Launchpad code reviewers is requested to review the proposed merge of
lp:~cjwatson/launchpad/xenial-apt-tests into lp:launchpad.
=== modified file 'lib/lp/archivepublisher/tests/test_ftparchive.py'
--- lib/lp/archivepublisher/tests/test_ftparchive.py 2016-09-24 04:24:30 +
+++ lib/lp/archivepublisher/tests/test_ftparchive.py 2017-01-13 13:31:05 +
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
+# Copyright 2009-2017 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""Tests for ftparchive.py"""
@@ -13,7 +13,15 @@
from textwrap import dedent
import time
-from testtools.matchers import LessThan
+from debian.deb822 import (
+Packages,
+Sources,
+)
+from testtools.matchers import (
+Equals,
+LessThan,
+MatchesListwise,
+)
from zope.component import getUtility
from lp.archivepublisher.config import getPubConfig
@@ -100,14 +108,13 @@
super(TestFTPArchive, self).tearDown()
shutil.rmtree(self._config.distroroot)
-def _verifyFile(self, filename, directory,
-result_suffix="", result_open_func=open):
+def _verifyFile(self, filename, directory):
"""Compare byte-to-byte the given file and the respective sample.
It's a poor way of testing files generated by apt-ftparchive.
"""
-result_path = os.path.join(directory, filename) + result_suffix
-with result_open_func(result_path) as result_file:
+result_path = os.path.join(directory, filename)
+with open(result_path) as result_file:
result_text = result_file.read()
sample_path = os.path.join(self._sampledir, filename)
with open(sample_path) as sample_file:
@@ -120,6 +127,18 @@
sample_text.splitlines(), result_text.splitlines())
self.assertEqual(sample_text, result_text, '\n'.join(diff_lines))
+def _verifyDeb822(self, filename, directory, deb822_factory,
+ result_suffix="", result_open_func=open):
+"""Compare the given file and the respective sample as deb822 files."""
+result_path = os.path.join(directory, filename) + result_suffix
+with result_open_func(result_path) as result_file:
+result = list(deb822_factory(result_file))
+sample_path = os.path.join(self._sampledir, filename)
+with open(sample_path) as sample_file:
+sample = list(deb822_factory(sample_file))
+self.assertThat(
+result, MatchesListwise([Equals(stanza) for stanza in sample]))
+
def _verifyEmpty(self, path, open_func=open):
"""Assert that the given file is empty."""
with open_func(path) as result_file:
@@ -441,18 +460,20 @@
# check'. Although they should remain active in PQM to avoid possible
# regressions.
fa.runApt(apt_conf)
-self._verifyFile(
+self._verifyDeb822(
"Packages",
os.path.join(self._distsdir, "hoary-test", "main", "binary-i386"),
+Packages.iter_paragraphs,
result_suffix=".gz", result_open_func=gzip.open)
self._verifyEmpty(
os.path.join(
self._distsdir, "hoary-test", "main", "debian-installer",
"binary-i386", "Packages.gz"),
open_func=gzip.open)
-self._verifyFile(
+self._verifyDeb822(
"Sources",
os.path.join(self._distsdir, "hoary-test", "main", "source"),
+Sources.iter_paragraphs,
result_suffix=".gz", result_open_func=gzip.open)
# XXX cprov 2007-03-21: see above, byte-to-byte configuration
@@ -666,15 +687,15 @@
binary_overrides = FakeSelectResult([(
"bin%d" % i, "main", "misc", "i386",
PackagePublishingPriority.EXTRA, BinaryPackageFormat.DEB, None)
-for i in range(10)])
+for i in range(50)])
fa.publishOverrides("hoary-test", source_overrides, binary_overrides)
source_files = FakeSelectResult([("tiny", "tiny_0.1.dsc", "main")])
binary_files = FakeSelectResult([(
"bin%d" % i, "bin%d_1_i386.deb" % i, "main", "binary-i386")
-for i in range(10)])
+for i in range(50)])
fa.publishFileLists("hoary-test", source_files, binary_files)
self._addRepositoryFile("main", "tiny", "tiny_0.1.dsc")
-for i in range(10):
+for i in range(50):
self._addRepositoryFile(
"main", "bin%d" % i,