From 8d00f561175ebd2c8658d538753fe9faa931f4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Tue, 2 Jul 2019 10:09:20 +0200 Subject: [PATCH] gather: Correctly sort list with multiple data types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Python 3 it is not possible to sort str and None or RpmWrapper. First convert everything to strings and then sort it. The sorting is really to simplify diffing the files, so exact order does not have to be preserved. Fixes: https://pagure.io/pungi/issue/1227 Signed-off-by: Lubomír Sedlář --- pungi/phases/gather/methods/method_deps.py | 8 +++++--- tests/test_gather_method_deps.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/pungi/phases/gather/methods/method_deps.py b/pungi/phases/gather/methods/method_deps.py index 44fb60b2..e82c9070 100644 --- a/pungi/phases/gather/methods/method_deps.py +++ b/pungi/phases/gather/methods/method_deps.py @@ -68,15 +68,17 @@ def raise_on_invalid_sigkeys(arch, variant, package_sets, result): def _format_packages(pkgs): """Sort packages and merge name with arch.""" - for pkg, pkg_arch in sorted(pkgs): + result = set() + for pkg, pkg_arch in pkgs: if type(pkg) in [SimpleRpmWrapper, RpmWrapper]: pkg_name = pkg.name else: pkg_name = pkg if pkg_arch: - yield '%s.%s' % (pkg_name, pkg_arch) + result.add("%s.%s" % (pkg_name, pkg_arch)) else: - yield pkg_name + result.add(pkg_name) + return sorted(result) def write_pungi_config(compose, arch, variant, packages, groups, filter_packages, diff --git a/tests/test_gather_method_deps.py b/tests/test_gather_method_deps.py index 1d577209..85a24a47 100644 --- a/tests/test_gather_method_deps.py +++ b/tests/test_gather_method_deps.py @@ -41,6 +41,27 @@ class TestWritePungiConfig(helpers.PungiTestCase): exclude_packages=['pkg3', 'pkg4.x86_64'], fulltree_excludes=fulltree, package_whitelist=set()) + @mock.patch("pungi.phases.gather.methods.method_deps.PungiWrapper") + def test_duplicated_package_name(self, PungiWrapper): + pkgs = [("pkg1", None), ("pkg1", "x86_64")] + grps = [] + filter = [("pkg2", None), ("pkg2", "x86_64")] + white = mock.Mock() + black = mock.Mock() + prepopulate = mock.Mock() + fulltree = mock.Mock() + deps.write_pungi_config(self.compose, "x86_64", self.compose.variants["Server"], + pkgs, grps, filter, white, black, + prepopulate=prepopulate, fulltree_excludes=fulltree) + self.assertWritten(PungiWrapper, packages=["pkg1", "pkg1.x86_64"], + ks_path=self.topdir + "/work/x86_64/pungi/Server.x86_64.conf", + lookaside_repos={}, multilib_whitelist=white, multilib_blacklist=black, + groups=[], prepopulate=prepopulate, + repos={"pungi-repo": self.topdir + "/work/x86_64/repo", + "comps-repo": self.topdir + "/work/x86_64/comps_repo_Server"}, + exclude_packages=["pkg2", "pkg2.x86_64"], + fulltree_excludes=fulltree, package_whitelist=set()) + @mock.patch('pungi.phases.gather.get_lookaside_repos') @mock.patch('pungi.phases.gather.methods.method_deps.PungiWrapper') def test_with_lookaside(self, PungiWrapper, glr):