[Yum-devel] [PATCH] Making package removal easier to test
James Bowes
jbowes at redhat.com
Sat Nov 17 00:14:32 UTC 2007
While fiddling with some test cases for package removal, I ran into some
problems with transactioninfo. It looks at the class of a package to
determine if its from the rpmdb, from a repo, or a local rpm. This makes
testing with fake packages hard.
The attached patch switches from looking at the class type to adding a
package_state variable to packages, which can be easily set for testing.
I don't think it will break any code using yum out in the wild.
Thoughts?
-James
-------------- next part --------------
From d808b817d0dad8b7eb572c5cd2fd03b9410e6168 Mon Sep 17 00:00:00 2001
From: James Bowes <jbowes at redhat.com>
Date: Fri, 16 Nov 2007 19:06:42 -0500
Subject: [PATCH] Re-introduce the package state constants, and use them in transactioninfo.
transactioninfo used to check class type of package objects to determine if
the package was local, from a repo, or installed. This makes testing hard,
as we don't always want to inherit from the particular classes that
transactioninfo looked for. Instead use the PO_{INSTALLED|LOCAL|REMOTE}PKG
constants, and add them to the classes that transactioninfo looked at. These
constants can be easily set in any testing objects.
---
test/depsolvetests.py | 22 ++++++++++++++++++++++
test/testbase.py | 8 +++++++-
yum/packages.py | 2 ++
yum/sqlitesack.py | 1 +
yum/transactioninfo.py | 7 ++++---
5 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/test/depsolvetests.py b/test/depsolvetests.py
index 22efc44..2b7ed45 100644
--- a/test/depsolvetests.py
+++ b/test/depsolvetests.py
@@ -501,6 +501,28 @@ class DepsolveTests(DepsolveTests):
self.assertEquals('ok', *self.resolveCode())
self.assertResult((po, updatepo))
+ def testEraseSinglePackage(self):
+ po = FakeInstalledPackage('zsh', '1', '1', '0', 'i386')
+ self.rpmdb.addPackage(po)
+ self.tsInfo.addErase(po)
+
+ self.assertEquals('ok', *self.resolveCode())
+ self.assertResult(())
+
+ def testEraseSinglePackageRequiredByOneInstalled(self):
+ po = FakeInstalledPackage('zippy', '1', '1', '0', 'i386')
+ po.addRequires('zsh', None, (None, None, None))
+ self.rpmdb.addPackage(po)
+
+ po = FakeInstalledPackage('zsh', '1', '1', '0', 'i386')
+ self.rpmdb.addPackage(po)
+ self.tsInfo.addErase(po)
+
+ self.assertEquals('ok', *self.resolveCode())
+ self.assertResult(())
+
+
+
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(DepsolveTests))
diff --git a/test/testbase.py b/test/testbase.py
index 3c90636..00ed5c4 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -14,7 +14,7 @@ from yum import YumBase
from yum import transactioninfo
from yum import packages
from yum import packageSack
-from yum.constants import TS_INSTALL_STATES, TS_REMOVE_STATES
+from yum.constants import TS_INSTALL_STATES, TS_REMOVE_STATES, PO_INSTALLEDPKG
from cli import YumBaseCli
import inspect
from rpmUtils import arch
@@ -72,6 +72,12 @@ class FakePackage(packages.YumAvailablePackage):
def addFile(self, name, ftype='file'):
self.files[ftype].append(name)
+class FakeInstalledPackage(FakePackage):
+
+ def __init__(self, name, version, release, epoch, arch, repo=None):
+ FakePackage.__init__(self, name, version, release, epoch, arch, repo)
+ self.package_state = PO_INSTALLEDPKG
+
class _Container(object):
pass
diff --git a/yum/packages.py b/yum/packages.py
index 900d9a1..c392638 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -763,6 +763,7 @@ class YumInstalledPackage(YumHeaderPackage):
fakerepo = FakeRepository('installed')
fakerepo.cost = 0
YumHeaderPackage.__init__(self, fakerepo, hdr)
+ self.package_state = PO_INSTALLEDPKG
class YumLocalPackage(YumHeaderPackage):
"""Class to handle an arbitrary package from a file path
@@ -792,6 +793,7 @@ class YumLocalPackage(YumHeaderPackage):
fakerepo.cost = 0
YumHeaderPackage.__init__(self, fakerepo, hdr)
self.id = self.pkgid
+ self.package_state = PO_LOCALPKG
def localPkg(self):
return self.localpath
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index df03c08..a6cae0c 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -51,6 +51,7 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
self.rel = self.release
self._changelog = None
+ self.package_state = PO_AVAILABLEPKG
files = property(fget=lambda self: self._loadFiles())
diff --git a/yum/transactioninfo.py b/yum/transactioninfo.py
index 29954c8..7ad6690 100644
--- a/yum/transactioninfo.py
+++ b/yum/transactioninfo.py
@@ -171,10 +171,11 @@ class TransactionData:
self._namedict.setdefault(txmember.name, []).append(txmember)
self.changed = True
- # Is this the right criteria?
- if not isinstance(txmember.po, (YumInstalledPackage, YumAvailablePackageSqlite)):
+ # XXX: Include hasattr check for backwards compat.
+ if not hasattr(txmember.po, 'package_state') or \
+ txmember.po.package_state in [PO_LOCALPKG]:
self.localSack.addPackage(txmember.po)
- elif isinstance(txmember.po, YumAvailablePackageSqlite):
+ elif txmember.po.package_state is PO_REMOTEPKG:
self.pkgSackPackages += 1
if self.conditionals.has_key(txmember.name):
--
1.5.3.5.1794.g083e
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.baseurl.org/pipermail/yum-devel/attachments/20071116/21f06e93/attachment.pgp
More information about the Yum-devel
mailing list