gather: Correctly sort list with multiple data types
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ář <lsedlar@redhat.com>
This commit is contained in:
parent
fc362c5347
commit
8d00f56117
@ -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,
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user