From cf026ec1840a0d858b48e35fa98b248323ab9d90 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 21 Oct 2011 11:07:53 +0200 Subject: first cut of multiarch support, tests still fail though --- tests/test_debfile_multiarch.py | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/test_debfile_multiarch.py (limited to 'tests/test_debfile_multiarch.py') diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py new file mode 100644 index 00000000..1b468a45 --- /dev/null +++ b/tests/test_debfile_multiarch.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2010 Michael Vogt +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. +"""Unit tests for verifying the correctness of DebPackage in apt.debfile.""" +import os +import logging +import unittest + +from test_all import get_library_dir +import sys +sys.path.insert(0, get_library_dir()) +import apt +import apt_pkg +import apt.debfile + +class TestDebfileMultiarch(unittest.TestCase): + """ test the multiarch debfile """ + + def test_multiarch_deb(self): + if apt_pkg.get_architectures() != ["amd64", "i386"]: + logging.warn("skipping test because running on a non-multiarch system") + return + deb = apt.debfile.DebPackage( + "./data/test_debs/multiarch-test1_i386.deb") + missing = deb.missing_deps + print missing + self.assertFalse("dpkg:i386" in missing) + + def test_multiarch_conflicts(self): + cache = apt.Cache() + # WARNING: this assumes that lib3ds-1-3 is a non-multiarch lib + # use "lib3ds-1-3" as a test to see if non-multiach lib conflicts work + cache["lib3ds-1-3"].mark_install() + deb = apt.debfile.DebPackage( + "./data/test_debs/multiarch-test1_i386.deb", cache=cache) + # this deb should now not be installable + self.assertFalse(deb.check()) + + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3 From c96acf6d26beb8c2c2e6eb9a868a4ea6b053a9d4 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 21 Oct 2011 11:47:03 +0200 Subject: make the tests pass --- apt/debfile.py | 36 +++++++++++++++++++++++++++++------- tests/test_debfile_multiarch.py | 11 ++++++++--- 2 files changed, 37 insertions(+), 10 deletions(-) (limited to 'tests/test_debfile_multiarch.py') diff --git a/apt/debfile.py b/apt/debfile.py index 1a9b471a..0e8bfcad 100644 --- a/apt/debfile.py +++ b/apt/debfile.py @@ -85,12 +85,33 @@ class DebPackage(object): return files # helper that will return a pkgname with a multiarch suffix if needed - def _maybe_append_multiarch_suffix(self, pkgname): - if (self._multiarch and - not self._cache.is_virtual_package(pkgname) and - self._cache[pkgname].candidate.architecture != "all"): - return "%s:%s" % (pkgname, self._multiarch) - return pkgname + def _maybe_append_multiarch_suffix(self, pkgname, + in_conflict_checking=False): + # trivial cases + if not self._multiarch: + return pkgname + elif self._cache.is_virtual_package(pkgname): + return pkgname + elif self._cache[pkgname].candidate == "all": + return pkgname + # now do the real multiarch checking + multiarch_pkgname = "%s:%s" % (pkgname, self._multiarch) + # the upper layers will handle this + if not multiarch_pkgname in self._cache: + return multiarch_pkgname + # now check the multiarch state + cand = self._cache[multiarch_pkgname].candidate._cand + #print pkgname, multiarch_pkgname, cand.multi_arch + # the default is to add the suffix, unless its a pkg that can satify + # foreign dependencies + if cand.multi_arch & cand.MULTI_ARCH_FOREIGN: + return pkgname + # for conflicts we need a special case here, any not multiarch enabled + # package has a implicit conflict + if (in_conflict_checking and + not (cand.multi_arch & cand.MULTI_ARCH_SAME)): + return pkgname + return multiarch_pkgname def _is_or_group_satisfied(self, or_group): """Return True if at least one dependency of the or-group is satisfied. @@ -220,7 +241,8 @@ class DebPackage(object): # FIXME: is this good enough? i.e. will apt always populate # the cache with conflicting pkgnames for our arch? - depname = self._maybe_append_multiarch_suffix(depname) + depname = self._maybe_append_multiarch_suffix( + depname, in_conflict_checking=True) # check conflicts with virtual pkgs if not depname in self._cache: diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index 1b468a45..db777692 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -21,14 +21,14 @@ import apt.debfile class TestDebfileMultiarch(unittest.TestCase): """ test the multiarch debfile """ - def test_multiarch_deb(self): + def test_multiarch_deb_check(self): if apt_pkg.get_architectures() != ["amd64", "i386"]: logging.warn("skipping test because running on a non-multiarch system") return deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb") missing = deb.missing_deps - print missing + #print missing self.assertFalse("dpkg:i386" in missing) def test_multiarch_conflicts(self): @@ -39,7 +39,12 @@ class TestDebfileMultiarch(unittest.TestCase): deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb", cache=cache) # this deb should now not be installable - self.assertFalse(deb.check()) + installable = deb.check() + #print deb._failure_string + self.assertFalse(installable) + self.assertEqual(deb._failure_string, + "Conflicts with the installed package 'lib3ds-1-3'") + if __name__ == "__main__": -- cgit v1.2.3 From cccf74c205b05cf81bade4269ea7df99c5dcbea7 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 21 Oct 2011 11:57:10 +0200 Subject: tests/test_debfile_multiarch.py: skip test if e.g. unvierse is not enabled --- tests/test_debfile_multiarch.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests/test_debfile_multiarch.py') diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py index db777692..7c02a32a 100644 --- a/tests/test_debfile_multiarch.py +++ b/tests/test_debfile_multiarch.py @@ -35,7 +35,11 @@ class TestDebfileMultiarch(unittest.TestCase): cache = apt.Cache() # WARNING: this assumes that lib3ds-1-3 is a non-multiarch lib # use "lib3ds-1-3" as a test to see if non-multiach lib conflicts work - cache["lib3ds-1-3"].mark_install() + canary = "lib3ds-1-3" + if not canary in cache: + logging.warn("skipping test because %s is missing" % canary) + return + cache[canary].mark_install() deb = apt.debfile.DebPackage( "./data/test_debs/multiarch-test1_i386.deb", cache=cache) # this deb should now not be installable -- cgit v1.2.3