[Yum-devel] [PATCH 2/3] Make FakePackage use a simulated RPMDBAdditionalDataPackage for yumdb_info.

Casey Jao cjao at ugcs.caltech.edu
Mon Jun 6 14:08:46 UTC 2011


---
 test/testbase.py |   47 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/test/testbase.py b/test/testbase.py
index 12025ce..d0f22be 100644
--- a/test/testbase.py
+++ b/test/testbase.py
@@ -84,6 +84,39 @@ class FakeRepo(object):
         else:
             return 0
 
+class FakeYumDBInfo(object):
+    """Simulate some functionality of RPMAdditionalDataPackage"""
+    _auto_hardlink_attrs = set(['checksum_type', 'reason',
+                                'installed_by', 'changed_by',
+                                'from_repo', 'from_repo_revision',
+                                'from_repo_timestamp', 'releasever',
+                                'command_line'])
+     
+    def __init__(self, conf=None, pkgdir=None, yumdb_cache=None):
+        self.db = {}
+        for attr in self._auto_hardlink_attrs:
+            self.db[attr] = ''
+            
+    def __getattr__(self, attr):
+        return self.db[attr]
+
+    def __setattr__(self, attr, value):
+        if not attr.startswith("db"):
+            self.db[attr] = value
+        else:
+            object.__setattr__(self, attr, value)
+            
+    def __iter__(self, show_hidden=False):
+        for item in self.db:
+            yield item
+
+    def get(self, attr, default=None):
+        try:
+            res = self.db[attr]
+        except AttributeError:
+            return default
+        return res
+        
 class FakePackage(packages.YumAvailablePackage):
 
     def __init__(self, name, version='1.0', release='1', epoch='0', arch='noarch', repo=None):
@@ -102,18 +135,24 @@ class FakePackage(packages.YumAvailablePackage):
         self.epoch = epoch
         self.arch = arch
         self.pkgtup = (self.name, self.arch, self.epoch, self.version, self.release)
-        self.yumdb_info = {}
+        self.yumdb_info = FakeYumDBInfo()
 
         self.prco['provides'].append((name, 'EQ', (epoch, version, release)))
 
         # Just a unique integer
         self.id = self.__hash__()
         self.pkgKey = self.__hash__()
-
+        
+        self.required_pkgs = []
+        self.requiring_pkgs = []
     def addProvides(self, name, flag=None, evr=(None, None, None)):
         self.prco['provides'].append((name, flag, evr))
     def addRequires(self, name, flag=None, evr=(None, None, None)):
         self.prco['requires'].append((name, flag, evr))
+    def addRequiresPkg(self, pkg):
+        self.required_pkgs.append(pkg)
+    def addRequiringPkg(self, pkg):
+        self.requiring_pkgs.append(pkg)   
     def addConflicts(self, name, flag=None, evr=(None, None, None)):
         self.prco['conflicts'].append((name, flag, evr))
     def addObsoletes(self, name, flag=None, evr=(None, None, None)):
@@ -121,9 +160,9 @@ class FakePackage(packages.YumAvailablePackage):
     def addFile(self, name, ftype='file'):
         self.files[ftype].append(name)
     def required_packages(self):
-        return []
+        return self.required_pkgs
     def requiring_packages(self):
-        return []
+        return self.requiring_pkgs
 
 class _Container(object):
     pass
-- 
1.7.5.2



More information about the Yum-devel mailing list