[jhbuild] tests: Update tests a bit to work with new internals



commit 7e973e4d75edad417a4bf4f0f0bd60d16108de48
Author: Colin Walters <walters verbum org>
Date:   Sat Jul 23 11:27:57 2011 -0400

    tests: Update tests a bit to work with new internals

 jhbuild/moduleset.py |   15 +++++++++------
 tests/mock.py        |   15 +++++++++++++--
 tests/tests.py       |   15 +++++++++------
 3 files changed, 31 insertions(+), 14 deletions(-)
---
diff --git a/jhbuild/moduleset.py b/jhbuild/moduleset.py
index 36025d4..3c214b8 100644
--- a/jhbuild/moduleset.py
+++ b/jhbuild/moduleset.py
@@ -49,16 +49,19 @@ def get_default_repo():
     return _default_repo
 
 class ModuleSet:
-    def __init__(self, config = None):
+    def __init__(self, config = None, db=None):
         self.config = config
         self.modules = {}
 
-        legacy_pkgdb_path = os.path.join(self.config.prefix, 'share', 'jhbuild', 'packagedb.xml')
-        new_pkgdb_path = os.path.join(self.config.top_builddir, 'packagedb.xml')
-        if os.path.exists(self.config.top_builddir) and os.path.isfile(legacy_pkgdb_path):
-            os.rename(legacy_pkgdb_path, new_pkgdb_path)
+        if db is None:
+            legacy_pkgdb_path = os.path.join(self.config.prefix, 'share', 'jhbuild', 'packagedb.xml')
+            new_pkgdb_path = os.path.join(self.config.top_builddir, 'packagedb.xml')
+            if os.path.exists(self.config.top_builddir) and os.path.isfile(legacy_pkgdb_path):
+                os.rename(legacy_pkgdb_path, new_pkgdb_path)
 
-        self.packagedb = packagedb.PackageDB(new_pkgdb_path, config)
+            self.packagedb = packagedb.PackageDB(new_pkgdb_path, config)
+        else:
+            self.packagedb = db
 
     def add(self, module):
         '''add a Module object to this set of modules'''
diff --git a/tests/mock.py b/tests/mock.py
index 3913afa..d6121ac 100644
--- a/tests/mock.py
+++ b/tests/mock.py
@@ -55,6 +55,7 @@ class Config(jhbuild.config.Config):
     min_age = None
 
     prefix = '/tmp/'
+    top_builddir = '/tmp/_jhbuild'
 
     def __init__(self):
         pass
@@ -72,7 +73,7 @@ class PackageDB:
             return self.force_uptodate
         return self.db.get(package, ('_none_'))[0] == version
 
-    def add(self, package, version):
+    def add(self, package, version, manifest):
         self.db[package] = (version, time.time()+self.time_delta)
 
     def remove(self, package):
@@ -85,9 +86,10 @@ class PackageDB:
 class BuildScript(jhbuild.frontends.buildscript.BuildScript):
     execute_is_failure = False
 
-    def __init__(self, config, module_list):
+    def __init__(self, config, module_list, moduleset):
         self.config = config
         self.modulelist = module_list
+        self.moduleset = moduleset
         self.packagedb = PackageDB()
         self.actions = []
     
@@ -113,9 +115,18 @@ class Branch(jhbuild.versioncontrol.Branch):
         return '/tmp/'
     srcdir = property(srcdir)
 
+    def checkoutdir(self):
+        return '/tmp/'
+    checkoutdir = property(checkoutdir)
+
     def checkout(self, buildscript):
         pass
 
+    def may_checkout(self, buildscript):
+        if buildscript.config.nonetwork:
+            return False
+        return True
+
     def tree_id(self):
         return 'foo'
 
diff --git a/tests/tests.py b/tests/tests.py
index 106ec9e..83e574d 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -202,6 +202,7 @@ class BuildTestCase(unittest.TestCase):
         self.branch = mock.Branch()
         self.branch.config = self.config
         self.buildscript = None
+        self.moduleset = None
 
     def build(self, packagedb_params = {}, **kwargs):
         self.config.build_targets = ['install', 'test']
@@ -210,12 +211,12 @@ class BuildTestCase(unittest.TestCase):
         self.config.update_build_targets()
 
         if not self.buildscript or packagedb_params:
-            self.buildscript = mock.BuildScript(self.config, self.modules)
-            self.buildscript.packagedb = mock.PackageDB(**packagedb_params)
+            packagedb = mock.PackageDB(**packagedb_params)
+            self.moduleset = jhbuild.moduleset.ModuleSet(self.config, db=packagedb)
+            self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
         else:
-            packagedb = self.buildscript.packagedb
-            self.buildscript = mock.BuildScript(self.config, self.modules)
-            self.buildscript.packagedb = packagedb
+            packagedb = self.buildscript.moduleset.packagedb
+            self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
 
         self.buildscript.build()
         return self.buildscript.actions
@@ -229,7 +230,9 @@ class AutotoolsModTypeTestCase(BuildTestCase):
 
     def setUp(self):
         BuildTestCase.setUp(self)
-        self.modules = [AutogenModule('foo', self.branch)]
+        module = AutogenModule('foo')
+        module.branch = self.branch
+        self.modules = [module]
         self.modules[0].config = self.config
         # replace clean method as it checks for Makefile existence
         self.modules[0].skip_clean = lambda x,y: False



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]